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(
|
||||
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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
<header attrs="{'invisible': [('display_type', '!=', False)]}" />
|
||||
<sheet>
|
||||
<field name="specific_price" invisible="1" />
|
||||
<field name="company_id" invisible="1" />
|
||||
<group
|
||||
col="4"
|
||||
attrs="{'invisible': [('display_type', '!=', False)]}"
|
||||
|
||||
@@ -256,6 +256,7 @@
|
||||
<field name="is_cancel_allowed" invisible="1" />
|
||||
<field name="is_un_cancel_allowed" invisible="1" />
|
||||
<field name="is_canceled" invisible="1" />
|
||||
<field name="company_id" invisible="1" />
|
||||
<button
|
||||
name="action_plan_successor"
|
||||
string="Plan Start"
|
||||
@@ -361,6 +362,7 @@
|
||||
<field name="is_un_cancel_allowed" invisible="1" />
|
||||
<field name="is_auto_renew" invisible="1" />
|
||||
<field name="is_canceled" invisible="1" />
|
||||
<field name="company_id" invisible="1" />
|
||||
<button
|
||||
name="action_plan_successor"
|
||||
string="Plan Start"
|
||||
|
||||
@@ -133,6 +133,7 @@
|
||||
<field name="is_un_cancel_allowed" invisible="1" />
|
||||
<field name="is_auto_renew" invisible="1" />
|
||||
<field name="is_canceled" invisible="1" />
|
||||
<field name="company_id" invisible="1" />
|
||||
<button
|
||||
name="action_plan_successor"
|
||||
title="Plan Start"
|
||||
|
||||
@@ -14,6 +14,7 @@ class ContractContract(models.Model):
|
||||
help="If mandate required in payment method and not set mandate, "
|
||||
"invoice takes the first valid mandate",
|
||||
index=True,
|
||||
check_company=True,
|
||||
)
|
||||
mandate_required = fields.Boolean(
|
||||
related="payment_mode_id.payment_method_id.mandate_required", readonly=True
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<field name="payment_mode_id" position="after">
|
||||
<field
|
||||
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)]}"
|
||||
/>
|
||||
<field name="commercial_partner_id" invisible="1" />
|
||||
|
||||
@@ -7,8 +7,9 @@ class ContractContract(models.Model):
|
||||
payment_mode_id = fields.Many2one(
|
||||
comodel_name="account.payment.mode",
|
||||
string="Payment Mode",
|
||||
domain=[("payment_type", "=", "inbound")],
|
||||
domain="[('payment_type', '=', 'inbound'), ('company_id', '=', company_id)]",
|
||||
index=True,
|
||||
check_company=True,
|
||||
)
|
||||
|
||||
@api.onchange("partner_id")
|
||||
|
||||
@@ -49,7 +49,9 @@
|
||||
<field name="inherit_id" ref="contract.contract_contract_supplier_form_view" />
|
||||
<field name="arch" type="xml">
|
||||
<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>
|
||||
</record>
|
||||
|
||||
Reference in New Issue
Block a user