[ADD] domain to choice of order in annex, new way to generate name
This commit is contained in:
parent
da869db151
commit
75a51ed982
@ -20,6 +20,9 @@ class PartnerContract(models.Model):
|
||||
string="Annexes",
|
||||
help="Annexes to this contract",
|
||||
)
|
||||
contract_annex_number = fields.Integer(
|
||||
default=1, help="Counter for generate Annex name"
|
||||
)
|
||||
partner_id = fields.Many2one(
|
||||
"res.partner",
|
||||
string="Partner",
|
||||
|
@ -8,30 +8,42 @@ class ContractOrderAnnex(models.Model):
|
||||
_description = "Contract Order Annex"
|
||||
|
||||
name = fields.Char(string="Name", help="The Number of Annex")
|
||||
order_id = fields.Many2one(
|
||||
"sale.order",
|
||||
string="Order",
|
||||
domain=[("contract_annex_id", "=", False)],
|
||||
required=True,
|
||||
)
|
||||
order_id = fields.Many2one("sale.order", string="Order", required=True,)
|
||||
contract_id = fields.Many2one(
|
||||
"res.partner.contract", string="Contract", readonly=True
|
||||
"res.partner.contract", string="Contract", readonly=True,
|
||||
)
|
||||
|
||||
@api.onchange("contract_id")
|
||||
def _onchange_contract_id(self):
|
||||
# Compute name if there is no custom name
|
||||
contract_number = self.contract_id.name
|
||||
annex_number = self.contract_id.contract_annex_number
|
||||
|
||||
self.name = "{contract}--{annex}".format(
|
||||
contract=contract_number, annex=annex_number
|
||||
)
|
||||
|
||||
# Compute domain for order_id because of bug with
|
||||
# not working correctly domain in model
|
||||
return {
|
||||
"domain": {
|
||||
"order_id": [
|
||||
("partner_id", "=", self.contract_id.partner_id.id),
|
||||
("contract_annex_id", "=", False),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@api.model
|
||||
def create(self, values):
|
||||
record = super().create(values)
|
||||
|
||||
# Compute name if there is no custom name
|
||||
if not record.name:
|
||||
contract_number = record.contract_id.name
|
||||
annex_number = len(record.contract_id.contract_annex_ids.ids)
|
||||
|
||||
record.name = "{contract}--{annex}".format(
|
||||
contract=contract_number, annex=annex_number
|
||||
)
|
||||
# Fill annex_id to domain it in future
|
||||
record.order_id.contract_annex_id = record.id
|
||||
|
||||
# Add counter
|
||||
record.contract_id.contract_annex_number += 1
|
||||
|
||||
return record
|
||||
|
||||
@api.multi
|
||||
|
@ -36,6 +36,9 @@
|
||||
<field name="date_conclusion" attrs="{'readonly': [('state', 'in', ['sign', 'close'])]}"/>
|
||||
<field name="date_conclusion_fix"/>
|
||||
<field name="partner_id" readonly="1"/>
|
||||
|
||||
<!-- Uses to generate number of Annex -->
|
||||
<field name="contract_annex_number" invisible="1"/>
|
||||
</group>
|
||||
<group string="Annexed orders" name="multi_params">
|
||||
<field name="contract_annex_ids" attrs="{'readonly': [('state', 'in', ['sign', 'close'])]}">
|
||||
|
Loading…
x
Reference in New Issue
Block a user