diff --git a/contract/models/abstract_contract.py b/contract/models/abstract_contract.py
index f66650b63..46cdc9220 100644
--- a/contract/models/abstract_contract.py
+++ b/contract/models/abstract_contract.py
@@ -22,7 +22,12 @@ class ContractAbstractContract(models.AbstractModel):
partner_id = fields.Many2one(
comodel_name="res.partner", string="Partner", index=True
)
- pricelist_id = fields.Many2one(comodel_name="product.pricelist", string="Pricelist")
+ pricelist_id = fields.Many2one(
+ comodel_name="product.pricelist",
+ string="Pricelist",
+ check_company=True,
+ domain="[('company_id', '=', company_id)]",
+ )
contract_type = fields.Selection(
selection=[("sale", "Customer"), ("purchase", "Supplier")],
default="sale",
@@ -36,6 +41,7 @@ class ContractAbstractContract(models.AbstractModel):
store=True,
readonly=False,
index=True,
+ check_company=True,
)
company_id = fields.Many2one(
"res.company",
diff --git a/contract/models/contract.py b/contract/models/contract.py
index d29eb896c..489d79eef 100644
--- a/contract/models/contract.py
+++ b/contract/models/contract.py
@@ -21,6 +21,7 @@ class ContractContract(models.Model):
_name = "contract.contract"
_description = "Contract"
_order = "code, name asc"
+ _check_company_auto = True
_inherit = [
"mail.thread",
"mail.activity.mixin",
@@ -39,6 +40,8 @@ class ContractContract(models.Model):
string="Group",
comodel_name="account.analytic.account",
ondelete="restrict",
+ check_company=True,
+ domain="[('company_id', '=', company_id)]",
)
currency_id = fields.Many2one(
compute="_compute_currency_id",
@@ -81,13 +84,19 @@ class ContractContract(models.Model):
)
date_end = fields.Date(compute="_compute_date_end", store=True, readonly=False)
payment_term_id = fields.Many2one(
- comodel_name="account.payment.term", string="Payment Terms", index=True
+ comodel_name="account.payment.term",
+ string="Payment Terms",
+ index=True,
+ check_company=True,
+ domain="[('company_id', '=', company_id)]",
)
invoice_count = fields.Integer(compute="_compute_invoice_count")
fiscal_position_id = fields.Many2one(
comodel_name="account.fiscal.position",
string="Fiscal Position",
ondelete="restrict",
+ check_company=True,
+ domain="[('company_id', '=', company_id)]",
)
invoice_partner_id = fields.Many2one(
string="Invoicing contact",
diff --git a/contract/models/contract_line.py b/contract/models/contract_line.py
index 80a3592ad..9c5b51381 100644
--- a/contract/models/contract_line.py
+++ b/contract/models/contract_line.py
@@ -16,6 +16,7 @@ from .contract_line_constraints import get_allowed
class ContractLine(models.Model):
_name = "contract.line"
_description = "Contract Line"
+ _check_company_auto = True
_inherit = [
"contract.abstract.contract.line",
"contract.recurrency.mixin",
@@ -36,10 +37,14 @@ class ContractLine(models.Model):
analytic_account_id = fields.Many2one(
string="Analytic account",
comodel_name="account.analytic.account",
+ check_company=True,
+ domain="['|', ('company_id', '=', company_id), ('company_id', '=', False)]",
)
analytic_tag_ids = fields.Many2many(
comodel_name="account.analytic.tag",
string="Analytic Tags",
+ check_company=True,
+ domain="['|', ('company_id', '=', company_id), ('company_id', '=', False)]",
)
date_start = fields.Date(required=True)
date_end = fields.Date(compute="_compute_date_end", store=True, readonly=False)
@@ -59,6 +64,7 @@ class ContractLine(models.Model):
readonly=True,
index=True,
copy=False,
+ check_company=True,
help="In case of restart after suspension, this field contain the new "
"contract line created.",
)
@@ -69,6 +75,7 @@ class ContractLine(models.Model):
readonly=True,
index=True,
copy=False,
+ check_company=True,
help="Contract Line origin of this one.",
)
manual_renew_needed = fields.Boolean(
diff --git a/contract/tests/test_contract.py b/contract/tests/test_contract.py
index e4ced1f34..e3046258f 100644
--- a/contract/tests/test_contract.py
+++ b/contract/tests/test_contract.py
@@ -2210,8 +2210,21 @@ class TestContract(TestContractBase):
parent_partner = self.env["res.partner"].create(
{"name": "parent partner", "is_company": True}
)
+ journal2 = self.env["account.journal"].create(
+ {
+ "name": "Test journal Company2",
+ "code": "VTC2",
+ "type": "sale",
+ "company_id": company2.id,
+ }
+ )
# Assume contract 2 is for company 2
- self.contract2.company_id = company2
+ self.contract2.write(
+ {
+ "company_id": company2.id,
+ "journal_id": journal2.id,
+ }
+ )
# Update the partner attached to both contracts
self.partner.with_user(unprivileged_user).with_company(company2).with_context(
company_id=company2.id
@@ -2410,6 +2423,7 @@ class TestContract(TestContractBase):
"code": "TCAD",
"type": "sale",
"currency_id": currency_cad.id,
+ "company_id": self.contract2.company_id.id,
}
)
self.contract2.journal_id = journal.id
diff --git a/contract/views/abstract_contract_line.xml b/contract/views/abstract_contract_line.xml
index bc3ca6aee..505d2155b 100644
--- a/contract/views/abstract_contract_line.xml
+++ b/contract/views/abstract_contract_line.xml
@@ -12,6 +12,7 @@
+
+
+
+