mirror of
https://github.com/bringout/oca-technical.git
synced 2026-04-18 12:32:01 +02:00
Initial commit: OCA Technical packages (595 packages)
This commit is contained in:
commit
2cc02aac6e
24950 changed files with 2318079 additions and 0 deletions
|
|
@ -0,0 +1,2 @@
|
|||
from . import upgrade_generate_record_wizard
|
||||
from . import upgrade_install_wizard
|
||||
|
|
@ -0,0 +1,127 @@
|
|||
# Copyright 2011-2015 Therp BV <https://therp.nl>
|
||||
# Copyright 2016 Opener B.V. <https://opener.am>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from threading import current_thread
|
||||
|
||||
from odoo import _, fields, models
|
||||
from odoo.exceptions import UserError
|
||||
from odoo.modules.registry import Registry
|
||||
|
||||
from ..odoo_patch.odoo_patch import OdooPatch
|
||||
|
||||
|
||||
class GenerateWizard(models.TransientModel):
|
||||
_name = "upgrade.generate.record.wizard"
|
||||
_description = "Upgrade Generate Record Wizard"
|
||||
|
||||
state = fields.Selection([("draft", "Draft"), ("done", "Done")], default="draft")
|
||||
|
||||
def generate(self):
|
||||
"""Reinitialize all installed modules.
|
||||
Equivalent of running the server with '-d <database> --init all'
|
||||
|
||||
The goal of this is to fill the records table.
|
||||
|
||||
TODO: update module list and versions, then update all modules?"""
|
||||
|
||||
# Truncate the records table
|
||||
self.env.cr.execute("TRUNCATE upgrade_attribute, upgrade_record;")
|
||||
|
||||
# Check of all the modules are correctly installed
|
||||
modules = self.env["ir.module.module"].search(
|
||||
[("state", "in", ["to install", "to upgrade"])]
|
||||
)
|
||||
if modules:
|
||||
raise UserError(
|
||||
_("Cannot seem to install or upgrade modules %s")
|
||||
% (", ".join([module.name for module in modules]))
|
||||
)
|
||||
# Now reinitialize all installed modules
|
||||
self.env["ir.module.module"].search([("state", "=", "installed")]).write(
|
||||
{"state": "to install"}
|
||||
)
|
||||
self.env.cr.commit() # pylint: disable=invalid-commit
|
||||
|
||||
# Patch the registry on the thread
|
||||
thread = current_thread()
|
||||
thread._upgrade_registry = {}
|
||||
|
||||
# Regenerate the registry with monkeypatches that log the records
|
||||
with OdooPatch():
|
||||
Registry.new(self.env.cr.dbname, update_module=True)
|
||||
|
||||
# Free the registry
|
||||
delattr(thread, "_upgrade_registry")
|
||||
|
||||
# Set domain property
|
||||
self.env.cr.execute(
|
||||
""" UPDATE upgrade_record our
|
||||
SET domain = iaw.domain
|
||||
FROM ir_model_data imd
|
||||
JOIN ir_act_window iaw ON imd.res_id = iaw.id
|
||||
WHERE our.type = 'xmlid'
|
||||
AND imd.model = 'ir.actions.act_window'
|
||||
AND our.model = imd.model
|
||||
AND our.name = imd.module || '.' || imd.name
|
||||
"""
|
||||
)
|
||||
self.env.cache.invalidate(
|
||||
[
|
||||
(self.env["upgrade.record"]._fields["domain"], None),
|
||||
]
|
||||
)
|
||||
|
||||
# Set constraint definition
|
||||
self.env.cr.execute(
|
||||
""" UPDATE upgrade_record our
|
||||
SET definition = btrim(replace(replace(replace(replace(
|
||||
imc.definition, chr(9), ' '), chr(10), ' '), ' ', ' '), ' ', ' '))
|
||||
FROM ir_model_data imd
|
||||
JOIN ir_model_constraint imc ON imd.res_id = imc.id
|
||||
WHERE our.type = 'xmlid'
|
||||
AND imd.model = 'ir.model.constraint'
|
||||
AND our.model = imd.model
|
||||
AND our.name = imd.module || '.' || imd.name"""
|
||||
)
|
||||
self.env.cache.invalidate(
|
||||
[
|
||||
(self.env["upgrade.record"]._fields["definition"], None),
|
||||
]
|
||||
)
|
||||
|
||||
# Set noupdate property from ir_model_data
|
||||
self.env.cr.execute(
|
||||
""" UPDATE upgrade_record our
|
||||
SET noupdate = imd.noupdate
|
||||
FROM ir_model_data imd
|
||||
WHERE our.type = 'xmlid'
|
||||
AND our.model = imd.model
|
||||
AND our.name = imd.module || '.' || imd.name
|
||||
"""
|
||||
)
|
||||
self.env.cache.invalidate(
|
||||
[
|
||||
(self.env["upgrade.record"]._fields["noupdate"], None),
|
||||
]
|
||||
)
|
||||
|
||||
# Log model records
|
||||
self.env.cr.execute(
|
||||
"""INSERT INTO upgrade_record
|
||||
(create_date, module, name, model, type)
|
||||
SELECT NOW() AT TIME ZONE 'UTC',
|
||||
imd2.module, imd2.module || '.' || imd.name AS name,
|
||||
im.model, 'model' AS type
|
||||
FROM (
|
||||
SELECT min(id) as id, name, res_id
|
||||
FROM ir_model_data
|
||||
WHERE name LIKE 'model_%' AND model = 'ir.model'
|
||||
GROUP BY name, res_id
|
||||
) imd
|
||||
JOIN ir_model_data imd2 ON imd2.id = imd.id
|
||||
JOIN ir_model im ON imd.res_id = im.id
|
||||
ORDER BY imd.name, imd.id""",
|
||||
)
|
||||
|
||||
return self.write({"state": "done"})
|
||||
|
|
@ -0,0 +1,118 @@
|
|||
# Copyright 2011-2015 Therp BV <https://therp.nl>
|
||||
# Copyright 2016 Opener B.V. <https://opener.am>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import api, fields, models
|
||||
from odoo.modules.registry import Registry
|
||||
from odoo.osv.expression import AND
|
||||
|
||||
from ..blacklist import (
|
||||
BLACKLIST_MODULES,
|
||||
BLACKLIST_MODULES_ENDS_WITH,
|
||||
BLACKLIST_MODULES_STARTS_WITH,
|
||||
)
|
||||
|
||||
|
||||
class UpgradeInstallWizard(models.TransientModel):
|
||||
_name = "upgrade.install.wizard"
|
||||
_description = "Upgrade Install Wizard"
|
||||
|
||||
state = fields.Selection(
|
||||
[("draft", "Draft"), ("done", "Done")], readonly=True, default="draft"
|
||||
)
|
||||
|
||||
module_ids = fields.Many2many(
|
||||
comodel_name="ir.module.module",
|
||||
domain=lambda x: x._module_ids_domain(),
|
||||
string="Modules",
|
||||
)
|
||||
|
||||
module_qty = fields.Integer(
|
||||
string="Modules Quantity", compute="_compute_module_qty"
|
||||
)
|
||||
|
||||
@api.model
|
||||
def _module_ids_domain(self, extra_domain=None):
|
||||
domain = [
|
||||
"&",
|
||||
("state", "not in", ["installed", "uninstallable", "unknown"]),
|
||||
("name", "not in", BLACKLIST_MODULES),
|
||||
]
|
||||
if extra_domain:
|
||||
domain = AND([domain, extra_domain])
|
||||
modules = self.env["ir.module.module"].search(domain)
|
||||
|
||||
for start_pattern in BLACKLIST_MODULES_STARTS_WITH:
|
||||
modules = modules.filtered(
|
||||
lambda x, start_pattern=start_pattern: not x.name.startswith(
|
||||
start_pattern
|
||||
)
|
||||
)
|
||||
for end_pattern in BLACKLIST_MODULES_ENDS_WITH:
|
||||
modules = modules.filtered(
|
||||
lambda x, end_pattern=end_pattern: not x.name.endswith(end_pattern)
|
||||
)
|
||||
return [("id", "in", modules.ids)]
|
||||
|
||||
@api.depends("module_ids")
|
||||
def _compute_module_qty(self):
|
||||
for wizard in self:
|
||||
wizard.module_qty = len(wizard.module_ids)
|
||||
|
||||
def select_odoo_modules(self, extra_domain=None):
|
||||
self.ensure_one()
|
||||
modules = self.env["ir.module.module"].search(
|
||||
self._module_ids_domain(extra_domain=extra_domain)
|
||||
)
|
||||
modules = modules.filtered(lambda x: x.is_odoo_module)
|
||||
self.module_ids = modules
|
||||
return self.return_same_form_view()
|
||||
|
||||
def select_oca_modules(self, extra_domain=None):
|
||||
self.ensure_one()
|
||||
modules = self.env["ir.module.module"].search(
|
||||
self._module_ids_domain(extra_domain=extra_domain)
|
||||
)
|
||||
modules = modules.filtered(lambda x: x.is_oca_module)
|
||||
self.module_ids = modules
|
||||
return self.return_same_form_view()
|
||||
|
||||
def select_other_modules(self, extra_domain=None):
|
||||
self.ensure_one()
|
||||
modules = self.env["ir.module.module"].search(
|
||||
self._module_ids_domain(extra_domain=extra_domain)
|
||||
)
|
||||
modules = modules.filtered(lambda x: not (x.is_oca_module or x.is_odoo_module))
|
||||
self.module_ids = modules
|
||||
return self.return_same_form_view()
|
||||
|
||||
def select_installable_modules(self, extra_domain=None):
|
||||
self.ensure_one()
|
||||
self.module_ids = self.env["ir.module.module"].search(
|
||||
self._module_ids_domain(extra_domain=extra_domain)
|
||||
)
|
||||
return self.return_same_form_view()
|
||||
|
||||
def unselect_modules(self):
|
||||
self.ensure_one()
|
||||
self.module_ids = False
|
||||
return self.return_same_form_view()
|
||||
|
||||
def install_modules(self):
|
||||
"""Set all selected modules and actually install them."""
|
||||
self.ensure_one()
|
||||
self.module_ids.write({"state": "to install"})
|
||||
self.env.cr.commit() # pylint: disable=invalid-commit
|
||||
Registry.new(self.env.cr.dbname, update_module=True)
|
||||
self.write({"state": "done"})
|
||||
return self.return_same_form_view()
|
||||
|
||||
def return_same_form_view(self):
|
||||
return {
|
||||
"type": "ir.actions.act_window",
|
||||
"res_model": "upgrade.install.wizard",
|
||||
"view_mode": "form",
|
||||
"res_id": self.id,
|
||||
"views": [(False, "form")],
|
||||
"target": "new",
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<odoo>
|
||||
|
||||
<record id="view_upgrade_generate_record_wizard_form" model="ir.ui.view">
|
||||
<field name="model">upgrade.generate.record.wizard</field>
|
||||
<field name="arch" type="xml">
|
||||
<form>
|
||||
<header>
|
||||
<field name="state" widget="statusbar" />
|
||||
</header>
|
||||
<group states="draft">
|
||||
<p
|
||||
colspan="2"
|
||||
>This will reinitialize all the modules installed on this database. Do not continue if you use this database in production.</p>
|
||||
</group>
|
||||
<group states="done">
|
||||
<p colspan="2">Modules initialized and record created</p>
|
||||
</group>
|
||||
<footer>
|
||||
<button
|
||||
string="Continue"
|
||||
name="generate"
|
||||
type="object"
|
||||
states="draft"
|
||||
class="btn-primary"
|
||||
/>
|
||||
<button special="cancel" string="Close" class="btn-default" />
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_upgrade_generate_record_wizard" model="ir.actions.act_window">
|
||||
<field name="name">Generate Records Wizard</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">upgrade.generate.record.wizard</field>
|
||||
<field name="view_mode">form,tree</field>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
|
||||
<menuitem
|
||||
name="Generate Records Wizard"
|
||||
id="menu_upgrade_generate_record"
|
||||
parent="menu_upgrade"
|
||||
action="action_upgrade_generate_record_wizard"
|
||||
sequence="15"
|
||||
/>
|
||||
|
||||
</odoo>
|
||||
|
|
@ -0,0 +1,92 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<odoo>
|
||||
|
||||
<record id="view_upgrade_install_wizard_form" model="ir.ui.view">
|
||||
<field name="model">upgrade.install.wizard</field>
|
||||
<field name="arch" type="xml">
|
||||
<form>
|
||||
<header>
|
||||
<field name="state" widget="statusbar" />
|
||||
</header>
|
||||
<group states="draft">
|
||||
<p
|
||||
class="alert alert-warning"
|
||||
role="alert"
|
||||
colspan="2"
|
||||
>This will install the selected modules on the database. Do not continue if you use this database in production.</p>
|
||||
</group>
|
||||
<group states="done">
|
||||
<p
|
||||
class="alert alert-info"
|
||||
role="alert"
|
||||
colspan="2"
|
||||
>The modules have been installed successfuly</p>
|
||||
</group>
|
||||
<header states="draft">
|
||||
<button
|
||||
name="select_installable_modules"
|
||||
type="object"
|
||||
string="All Modules"
|
||||
/>
|
||||
<button
|
||||
name="select_odoo_modules"
|
||||
type="object"
|
||||
string="All Odoo SA Modules"
|
||||
class="btn-primary"
|
||||
/>
|
||||
<button
|
||||
name="select_oca_modules"
|
||||
type="object"
|
||||
string="All OCA Modules"
|
||||
/>
|
||||
<button
|
||||
name="select_other_modules"
|
||||
type="object"
|
||||
string="All Other Modules"
|
||||
/>
|
||||
</header>
|
||||
<button
|
||||
name="unselect_modules"
|
||||
type="object"
|
||||
string="Clear the list"
|
||||
states="draft"
|
||||
/>
|
||||
<group states="draft">
|
||||
<field name="module_qty" />
|
||||
<field
|
||||
name="module_ids"
|
||||
widget="many2many_tags"
|
||||
options="{'no_create': True}"
|
||||
/>
|
||||
</group>
|
||||
<footer>
|
||||
<button
|
||||
name="install_modules"
|
||||
type="object"
|
||||
class="btn-primary"
|
||||
string="Install Modules"
|
||||
states="draft"
|
||||
/>
|
||||
<button special="cancel" string="Close" class="btn-default" />
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_upgrade_install_wizard" model="ir.actions.act_window">
|
||||
<field name="name">Install Modules Wizard</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">upgrade.install.wizard</field>
|
||||
<field name="view_mode">form,tree</field>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
|
||||
<menuitem
|
||||
name="Install Modules Wizard"
|
||||
id="menu_upgrade_install"
|
||||
parent="menu_upgrade"
|
||||
action="action_upgrade_install_wizard"
|
||||
sequence="14"
|
||||
/>
|
||||
|
||||
</odoo>
|
||||
Loading…
Add table
Add a link
Reference in a new issue