Refactor for multi-company
parent
7cae06b629
commit
5b0b1a39aa
|
@ -13,6 +13,7 @@
|
|||
"depends": ["base"],
|
||||
"data": [
|
||||
"security/ir.model.access.csv",
|
||||
"security/sequence_option_security.xml",
|
||||
"views/sequence_option_view.xml",
|
||||
],
|
||||
"license": "LGPL-3",
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Copyright 2021 Ecosoft Co., Ltd. (http://ecosoft.co.th)
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
|
||||
|
||||
from . import sequence_option
|
||||
from . import ir_sequence_option
|
||||
from . import ir_sequence
|
||||
|
|
|
@ -6,9 +6,10 @@ from odoo.exceptions import ValidationError
|
|||
from odoo.tools import safe_eval
|
||||
|
||||
|
||||
class BaseSequenceOption(models.Model):
|
||||
_name = "base.sequence.option"
|
||||
class IrSequenceOption(models.Model):
|
||||
_name = "ir.sequence.option"
|
||||
_description = "Sequence Option Base Model"
|
||||
_check_company_auto = True
|
||||
|
||||
name = fields.Char(readonly=True)
|
||||
use_sequence_option = fields.Boolean(
|
||||
|
@ -20,21 +21,32 @@ class BaseSequenceOption(models.Model):
|
|||
selection=[],
|
||||
string="Apply On Model",
|
||||
required=True,
|
||||
readonly=True,
|
||||
readonly=False,
|
||||
index=True,
|
||||
)
|
||||
option_ids = fields.One2many(
|
||||
string="Sequence Options",
|
||||
comodel_name="sequence.option",
|
||||
comodel_name="ir.sequence.option.line",
|
||||
inverse_name="base_id",
|
||||
)
|
||||
company_id = fields.Many2one(
|
||||
comodel_name="res.company",
|
||||
string="Company",
|
||||
required=True,
|
||||
readonly=False,
|
||||
index=True,
|
||||
default=lambda self: self.env.company,
|
||||
help="Company related to this sequence option",
|
||||
)
|
||||
|
||||
|
||||
class SequenceOption(models.Model):
|
||||
_name = "sequence.option"
|
||||
_description = "Sequence Options"
|
||||
class IrSequenceOptionLine(models.Model):
|
||||
_name = "ir.sequence.option.line"
|
||||
_description = "Sequence Option Line"
|
||||
_check_company_auto = True
|
||||
|
||||
base_id = fields.Many2one(
|
||||
comodel_name="base.sequence.option",
|
||||
comodel_name="ir.sequence.option",
|
||||
index=True,
|
||||
required=True,
|
||||
ondelete="cascade",
|
||||
|
@ -61,6 +73,7 @@ class SequenceOption(models.Model):
|
|||
comodel_name="ir.sequence",
|
||||
string="Sequence",
|
||||
required=True,
|
||||
check_company=True,
|
||||
)
|
||||
prefix = fields.Char(
|
||||
related="sequence_id.prefix",
|
||||
|
@ -77,6 +90,11 @@ class SequenceOption(models.Model):
|
|||
string="Implementation",
|
||||
readonly=True,
|
||||
)
|
||||
company_id = fields.Many2one(
|
||||
comodel_name="res.company",
|
||||
related="base_id.company_id",
|
||||
store=True,
|
||||
)
|
||||
|
||||
def get_model_options(self, model):
|
||||
return self.sudo().search(
|
||||
|
@ -89,6 +107,11 @@ class SequenceOption(models.Model):
|
|||
"""
|
||||
if not options:
|
||||
options = self.get_model_options(record._name)
|
||||
# multi-company
|
||||
company = (
|
||||
hasattr(record, "company_id") and record.company_id or self.env.company
|
||||
)
|
||||
options = options.filtered(lambda l: l.company_id == company)
|
||||
sequence = self.env["ir.sequence"]
|
||||
for option in options:
|
||||
domain = safe_eval.safe_eval(option.filter_domain)
|
|
@ -1,5 +1,5 @@
|
|||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
||||
access_sequence_option,access_sequence_option,model_sequence_option,base.group_user,1,0,0,0
|
||||
access_sequence_option_system,access_sequence_option_system,model_sequence_option,base.group_system,1,1,1,1
|
||||
access_base_sequence_option,access_base_sequence_option,model_base_sequence_option,base.group_user,1,0,0,0
|
||||
access_base_sequence_option_system,access_base_sequence_option_system,model_base_sequence_option,base.group_system,1,1,1,1
|
||||
access_ir_sequence_option_line,access_ir_sequence_option_line,model_ir_sequence_option_line,base.group_user,1,0,0,0
|
||||
access_ir_sequence_option_line_system,access_ir_sequence_option_line_system,model_ir_sequence_option_line,base.group_system,1,1,1,1
|
||||
access_ir_sequence_option,access_ir_sequence_option,model_ir_sequence_option,base.group_user,1,0,0,0
|
||||
access_ir_sequence_option_system,access_ir_sequence_option_system,model_ir_sequence_option,base.group_system,1,1,1,1
|
||||
|
|
|
|
@ -0,0 +1,18 @@
|
|||
<odoo noupdate="1">
|
||||
<record model="ir.rule" id="ir_sequence_option_multi_company_rule">
|
||||
<field name="name">Sequence Option: multi-company</field>
|
||||
<field name="model_id" ref="model_ir_sequence_option" />
|
||||
<field name="global" eval="True" />
|
||||
<field name="domain_force">
|
||||
[('company_id', 'in', company_ids)]
|
||||
</field>
|
||||
</record>
|
||||
<record model="ir.rule" id="ir_sequence_option_line_multi_company_rule">
|
||||
<field name="name">Sequence Option Line: multi-company</field>
|
||||
<field name="model_id" ref="model_ir_sequence_option_line" />
|
||||
<field name="global" eval="True" />
|
||||
<field name="domain_force">
|
||||
[('company_id', 'in', company_ids)]
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
|
@ -2,4 +2,4 @@
|
|||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
|
||||
|
||||
from . import common
|
||||
from . import test_base_sequence_option
|
||||
from . import test_ir_sequence_option
|
||||
|
|
|
@ -13,7 +13,7 @@ class BaseSequenceTester(models.Model):
|
|||
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
seq = self.env["sequence.option"].get_sequence(self.new(vals))
|
||||
seq = self.env["ir.sequence.option.line"].get_sequence(self.new(vals))
|
||||
if seq: # use sequence from sequence.option, instead of base.sequence.tester
|
||||
self = self.with_context(sequence_option_id=seq.id)
|
||||
new_seq = self.env["ir.sequence"].next_by_code("base.sequence.tester")
|
||||
|
@ -21,8 +21,8 @@ class BaseSequenceTester(models.Model):
|
|||
return super().create(vals)
|
||||
|
||||
|
||||
class BaseSequenceOption(models.Model):
|
||||
_inherit = "base.sequence.option"
|
||||
class IrSequenceOption(models.Model):
|
||||
_inherit = "ir.sequence.option"
|
||||
|
||||
model = fields.Selection(
|
||||
selection_add=[("base.sequence.tester", "base.sequence.tester")],
|
||||
|
|
|
@ -13,9 +13,9 @@ class CommonBaseSequenceOption(common.SavepointCase):
|
|||
|
||||
cls.loader = FakeModelLoader(cls.env, cls.__module__)
|
||||
cls.loader.backup_registry()
|
||||
from .base_sequence_tester import BaseSequenceOption, BaseSequenceTester
|
||||
from .base_sequence_tester import BaseSequenceTester, IrSequenceOption
|
||||
|
||||
cls.loader.update_registry((BaseSequenceTester, BaseSequenceOption))
|
||||
cls.loader.update_registry((BaseSequenceTester, IrSequenceOption))
|
||||
|
||||
cls.test_model = cls.env[BaseSequenceTester._name]
|
||||
|
||||
|
@ -60,8 +60,8 @@ class CommonBaseSequenceOption(common.SavepointCase):
|
|||
}
|
||||
)
|
||||
|
||||
# Create sequence options for model bsae.sequence.tester:
|
||||
cls.base_sequence_obj = cls.env["base.sequence.option"]
|
||||
# Create sequence options for model base.sequence.tester:
|
||||
cls.base_sequence_obj = cls.env["ir.sequence.option"]
|
||||
cls.base_seq = cls.base_sequence_obj.create(
|
||||
{
|
||||
"name": "Test Model",
|
||||
|
@ -69,7 +69,7 @@ class CommonBaseSequenceOption(common.SavepointCase):
|
|||
"use_sequence_option": True,
|
||||
}
|
||||
)
|
||||
cls.sequence_obj = cls.env["sequence.option"]
|
||||
cls.sequence_obj = cls.env["ir.sequence.option.line"]
|
||||
cls.sequence_obj.create(
|
||||
{
|
||||
"base_id": cls.base_seq.id,
|
||||
|
|
|
@ -4,21 +4,22 @@
|
|||
<odoo>
|
||||
|
||||
|
||||
<record id="view_base_sequence_option_tree" model="ir.ui.view">
|
||||
<field name="name">view.base.sequence.option.tree</field>
|
||||
<field name="model">base.sequence.option</field>
|
||||
<record id="view_ir_sequence_option_tree" model="ir.ui.view">
|
||||
<field name="name">view.ir.sequence.option.tree</field>
|
||||
<field name="model">ir.sequence.option</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Manage Sequence Options" create="0" delete="0">
|
||||
<tree string="Manage Sequence Options" create="1" delete="1">
|
||||
<field name="name" />
|
||||
<field name="model" />
|
||||
<field name="use_sequence_option" />
|
||||
<field name="company_id" groups="base.group_multi_company" />
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_sequence_option_tree" model="ir.ui.view">
|
||||
<field name="name">view.sequence.option.tree</field>
|
||||
<field name="model">sequence.option</field>
|
||||
<record id="view_ir_sequence_option_line_tree" model="ir.ui.view">
|
||||
<field name="name">view.ir.sequence.option.line.tree</field>
|
||||
<field name="model">ir.sequence.option.line</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Doctype Sequence">
|
||||
<field name="name" />
|
||||
|
@ -30,17 +31,18 @@
|
|||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_base_sequence_option_form" model="ir.ui.view">
|
||||
<field name="name">view.base.sequence.option.form</field>
|
||||
<field name="model">base.sequence.option</field>
|
||||
<record id="view_ir_sequence_option_form" model="ir.ui.view">
|
||||
<field name="name">view.ir.sequence.option.form</field>
|
||||
<field name="model">ir.sequence.option</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Doctype Sequence" create="0" delete="0">
|
||||
<form string="Doctype Sequence" create="1" delete="1">
|
||||
<h1>
|
||||
<field name="name" class="oe_inline" placeholder="Name" />
|
||||
</h1>
|
||||
<group>
|
||||
<group>
|
||||
<field name="model" />
|
||||
<field name="company_id" groups="base.group_multi_company" />
|
||||
</group>
|
||||
<group>
|
||||
<field name="use_sequence_option" widget="boolean_toggle" />
|
||||
|
@ -55,6 +57,7 @@
|
|||
<field name="prefix" />
|
||||
<field name="suffix" />
|
||||
<field name="implementation" />
|
||||
<field name="company_id" invisible="1" />
|
||||
</tree>
|
||||
<form>
|
||||
<group>
|
||||
|
@ -69,6 +72,7 @@
|
|||
</group>
|
||||
<group>
|
||||
<field name="sequence_id" />
|
||||
<field name="company_id" invisible="1" />
|
||||
</group>
|
||||
</group>
|
||||
</form>
|
||||
|
@ -77,17 +81,17 @@
|
|||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_base_sequence_option" model="ir.actions.act_window">
|
||||
<record id="action_ir_sequence_option" model="ir.actions.act_window">
|
||||
<field name="name">Manage Sequence Options</field>
|
||||
<field name="res_model">base.sequence.option</field>
|
||||
<field name="res_model">ir.sequence.option</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
<field name="view_id" ref="view_base_sequence_option_tree" />
|
||||
<field name="view_id" ref="view_ir_sequence_option_tree" />
|
||||
</record>
|
||||
|
||||
<menuitem
|
||||
name="Manage Sequence Options"
|
||||
id="menu_base_sequence_option"
|
||||
action="action_base_sequence_option"
|
||||
id="menu_ir_sequence_option"
|
||||
action="action_ir_sequence_option"
|
||||
parent="base.next_id_5"
|
||||
sequence="20"
|
||||
/>
|
||||
|
|
Loading…
Reference in New Issue