mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
[FIX] Add check_company=True on contracts and contract lines
Add check_company=True in field definition and
[('company_id', '=', company_id)] in the domain (in view or in field definition)
This commit is contained in:
@@ -22,7 +22,12 @@ class ContractAbstractContract(models.AbstractModel):
|
|||||||
partner_id = fields.Many2one(
|
partner_id = fields.Many2one(
|
||||||
comodel_name="res.partner", string="Partner", index=True
|
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(
|
contract_type = fields.Selection(
|
||||||
selection=[("sale", "Customer"), ("purchase", "Supplier")],
|
selection=[("sale", "Customer"), ("purchase", "Supplier")],
|
||||||
default="sale",
|
default="sale",
|
||||||
@@ -36,6 +41,7 @@ class ContractAbstractContract(models.AbstractModel):
|
|||||||
store=True,
|
store=True,
|
||||||
readonly=False,
|
readonly=False,
|
||||||
index=True,
|
index=True,
|
||||||
|
check_company=True,
|
||||||
)
|
)
|
||||||
company_id = fields.Many2one(
|
company_id = fields.Many2one(
|
||||||
"res.company",
|
"res.company",
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ class ContractContract(models.Model):
|
|||||||
_name = "contract.contract"
|
_name = "contract.contract"
|
||||||
_description = "Contract"
|
_description = "Contract"
|
||||||
_order = "code, name asc"
|
_order = "code, name asc"
|
||||||
|
_check_company_auto = True
|
||||||
_inherit = [
|
_inherit = [
|
||||||
"mail.thread",
|
"mail.thread",
|
||||||
"mail.activity.mixin",
|
"mail.activity.mixin",
|
||||||
@@ -39,6 +40,8 @@ class ContractContract(models.Model):
|
|||||||
string="Group",
|
string="Group",
|
||||||
comodel_name="account.analytic.account",
|
comodel_name="account.analytic.account",
|
||||||
ondelete="restrict",
|
ondelete="restrict",
|
||||||
|
check_company=True,
|
||||||
|
domain="[('company_id', '=', company_id)]",
|
||||||
)
|
)
|
||||||
currency_id = fields.Many2one(
|
currency_id = fields.Many2one(
|
||||||
compute="_compute_currency_id",
|
compute="_compute_currency_id",
|
||||||
@@ -81,13 +84,19 @@ class ContractContract(models.Model):
|
|||||||
)
|
)
|
||||||
date_end = fields.Date(compute="_compute_date_end", store=True, readonly=False)
|
date_end = fields.Date(compute="_compute_date_end", store=True, readonly=False)
|
||||||
payment_term_id = fields.Many2one(
|
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")
|
invoice_count = fields.Integer(compute="_compute_invoice_count")
|
||||||
fiscal_position_id = fields.Many2one(
|
fiscal_position_id = fields.Many2one(
|
||||||
comodel_name="account.fiscal.position",
|
comodel_name="account.fiscal.position",
|
||||||
string="Fiscal Position",
|
string="Fiscal Position",
|
||||||
ondelete="restrict",
|
ondelete="restrict",
|
||||||
|
check_company=True,
|
||||||
|
domain="[('company_id', '=', company_id)]",
|
||||||
)
|
)
|
||||||
invoice_partner_id = fields.Many2one(
|
invoice_partner_id = fields.Many2one(
|
||||||
string="Invoicing contact",
|
string="Invoicing contact",
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ from .contract_line_constraints import get_allowed
|
|||||||
class ContractLine(models.Model):
|
class ContractLine(models.Model):
|
||||||
_name = "contract.line"
|
_name = "contract.line"
|
||||||
_description = "Contract Line"
|
_description = "Contract Line"
|
||||||
|
_check_company_auto = True
|
||||||
_inherit = [
|
_inherit = [
|
||||||
"contract.abstract.contract.line",
|
"contract.abstract.contract.line",
|
||||||
"contract.recurrency.mixin",
|
"contract.recurrency.mixin",
|
||||||
@@ -36,10 +37,14 @@ class ContractLine(models.Model):
|
|||||||
analytic_account_id = fields.Many2one(
|
analytic_account_id = fields.Many2one(
|
||||||
string="Analytic account",
|
string="Analytic account",
|
||||||
comodel_name="account.analytic.account",
|
comodel_name="account.analytic.account",
|
||||||
|
check_company=True,
|
||||||
|
domain="['|', ('company_id', '=', company_id), ('company_id', '=', False)]",
|
||||||
)
|
)
|
||||||
analytic_tag_ids = fields.Many2many(
|
analytic_tag_ids = fields.Many2many(
|
||||||
comodel_name="account.analytic.tag",
|
comodel_name="account.analytic.tag",
|
||||||
string="Analytic Tags",
|
string="Analytic Tags",
|
||||||
|
check_company=True,
|
||||||
|
domain="['|', ('company_id', '=', company_id), ('company_id', '=', False)]",
|
||||||
)
|
)
|
||||||
date_start = fields.Date(required=True)
|
date_start = fields.Date(required=True)
|
||||||
date_end = fields.Date(compute="_compute_date_end", store=True, readonly=False)
|
date_end = fields.Date(compute="_compute_date_end", store=True, readonly=False)
|
||||||
@@ -59,6 +64,7 @@ class ContractLine(models.Model):
|
|||||||
readonly=True,
|
readonly=True,
|
||||||
index=True,
|
index=True,
|
||||||
copy=False,
|
copy=False,
|
||||||
|
check_company=True,
|
||||||
help="In case of restart after suspension, this field contain the new "
|
help="In case of restart after suspension, this field contain the new "
|
||||||
"contract line created.",
|
"contract line created.",
|
||||||
)
|
)
|
||||||
@@ -69,6 +75,7 @@ class ContractLine(models.Model):
|
|||||||
readonly=True,
|
readonly=True,
|
||||||
index=True,
|
index=True,
|
||||||
copy=False,
|
copy=False,
|
||||||
|
check_company=True,
|
||||||
help="Contract Line origin of this one.",
|
help="Contract Line origin of this one.",
|
||||||
)
|
)
|
||||||
manual_renew_needed = fields.Boolean(
|
manual_renew_needed = fields.Boolean(
|
||||||
|
|||||||
@@ -2210,8 +2210,21 @@ class TestContract(TestContractBase):
|
|||||||
parent_partner = self.env["res.partner"].create(
|
parent_partner = self.env["res.partner"].create(
|
||||||
{"name": "parent partner", "is_company": True}
|
{"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
|
# 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
|
# Update the partner attached to both contracts
|
||||||
self.partner.with_user(unprivileged_user).with_company(company2).with_context(
|
self.partner.with_user(unprivileged_user).with_company(company2).with_context(
|
||||||
company_id=company2.id
|
company_id=company2.id
|
||||||
@@ -2410,6 +2423,7 @@ class TestContract(TestContractBase):
|
|||||||
"code": "TCAD",
|
"code": "TCAD",
|
||||||
"type": "sale",
|
"type": "sale",
|
||||||
"currency_id": currency_cad.id,
|
"currency_id": currency_cad.id,
|
||||||
|
"company_id": self.contract2.company_id.id,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
self.contract2.journal_id = journal.id
|
self.contract2.journal_id = journal.id
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
<header attrs="{'invisible': [('display_type', '!=', False)]}" />
|
<header attrs="{'invisible': [('display_type', '!=', False)]}" />
|
||||||
<sheet>
|
<sheet>
|
||||||
<field name="specific_price" invisible="1" />
|
<field name="specific_price" invisible="1" />
|
||||||
|
<field name="company_id" invisible="1" />
|
||||||
<group
|
<group
|
||||||
col="4"
|
col="4"
|
||||||
attrs="{'invisible': [('display_type', '!=', False)]}"
|
attrs="{'invisible': [('display_type', '!=', False)]}"
|
||||||
|
|||||||
@@ -256,6 +256,7 @@
|
|||||||
<field name="is_cancel_allowed" invisible="1" />
|
<field name="is_cancel_allowed" invisible="1" />
|
||||||
<field name="is_un_cancel_allowed" invisible="1" />
|
<field name="is_un_cancel_allowed" invisible="1" />
|
||||||
<field name="is_canceled" invisible="1" />
|
<field name="is_canceled" invisible="1" />
|
||||||
|
<field name="company_id" invisible="1" />
|
||||||
<button
|
<button
|
||||||
name="action_plan_successor"
|
name="action_plan_successor"
|
||||||
string="Plan Start"
|
string="Plan Start"
|
||||||
@@ -361,6 +362,7 @@
|
|||||||
<field name="is_un_cancel_allowed" invisible="1" />
|
<field name="is_un_cancel_allowed" invisible="1" />
|
||||||
<field name="is_auto_renew" invisible="1" />
|
<field name="is_auto_renew" invisible="1" />
|
||||||
<field name="is_canceled" invisible="1" />
|
<field name="is_canceled" invisible="1" />
|
||||||
|
<field name="company_id" invisible="1" />
|
||||||
<button
|
<button
|
||||||
name="action_plan_successor"
|
name="action_plan_successor"
|
||||||
string="Plan Start"
|
string="Plan Start"
|
||||||
|
|||||||
@@ -133,6 +133,7 @@
|
|||||||
<field name="is_un_cancel_allowed" invisible="1" />
|
<field name="is_un_cancel_allowed" invisible="1" />
|
||||||
<field name="is_auto_renew" invisible="1" />
|
<field name="is_auto_renew" invisible="1" />
|
||||||
<field name="is_canceled" invisible="1" />
|
<field name="is_canceled" invisible="1" />
|
||||||
|
<field name="company_id" invisible="1" />
|
||||||
<button
|
<button
|
||||||
name="action_plan_successor"
|
name="action_plan_successor"
|
||||||
title="Plan Start"
|
title="Plan Start"
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ class ContractContract(models.Model):
|
|||||||
help="If mandate required in payment method and not set mandate, "
|
help="If mandate required in payment method and not set mandate, "
|
||||||
"invoice takes the first valid mandate",
|
"invoice takes the first valid mandate",
|
||||||
index=True,
|
index=True,
|
||||||
|
check_company=True,
|
||||||
)
|
)
|
||||||
mandate_required = fields.Boolean(
|
mandate_required = fields.Boolean(
|
||||||
related="payment_mode_id.payment_method_id.mandate_required", readonly=True
|
related="payment_mode_id.payment_method_id.mandate_required", readonly=True
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
<field name="payment_mode_id" position="after">
|
<field name="payment_mode_id" position="after">
|
||||||
<field
|
<field
|
||||||
name="mandate_id"
|
name="mandate_id"
|
||||||
domain="[('partner_id', '=', commercial_partner_id), ('state', '=', 'valid')]"
|
domain="[('partner_id', '=', commercial_partner_id), ('state', '=', 'valid'), ('company_id', '=', company_id)]"
|
||||||
attrs="{'invisible': [('mandate_required', '=', False)]}"
|
attrs="{'invisible': [('mandate_required', '=', False)]}"
|
||||||
/>
|
/>
|
||||||
<field name="commercial_partner_id" invisible="1" />
|
<field name="commercial_partner_id" invisible="1" />
|
||||||
|
|||||||
@@ -7,8 +7,9 @@ class ContractContract(models.Model):
|
|||||||
payment_mode_id = fields.Many2one(
|
payment_mode_id = fields.Many2one(
|
||||||
comodel_name="account.payment.mode",
|
comodel_name="account.payment.mode",
|
||||||
string="Payment Mode",
|
string="Payment Mode",
|
||||||
domain=[("payment_type", "=", "inbound")],
|
domain="[('payment_type', '=', 'inbound'), ('company_id', '=', company_id)]",
|
||||||
index=True,
|
index=True,
|
||||||
|
check_company=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
@api.onchange("partner_id")
|
@api.onchange("partner_id")
|
||||||
|
|||||||
@@ -49,7 +49,9 @@
|
|||||||
<field name="inherit_id" ref="contract.contract_contract_supplier_form_view" />
|
<field name="inherit_id" ref="contract.contract_contract_supplier_form_view" />
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<field name="payment_mode_id" position="attributes">
|
<field name="payment_mode_id" position="attributes">
|
||||||
<attribute name="domain">[('payment_type', '=', 'outbound')]</attribute>
|
<attribute
|
||||||
|
name="domain"
|
||||||
|
>[('payment_type', '=', 'outbound'), ('company_id', '=', company_id)]</attribute>
|
||||||
</field>
|
</field>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|||||||
Reference in New Issue
Block a user