[IMP] compute specification name

This commit is contained in:
Stepan Savelyev 2020-01-17 17:38:40 +05:00
parent 096a4d7b80
commit 1c9d75326a
2 changed files with 9 additions and 5 deletions

View File

@ -12,6 +12,7 @@ class ContractOrderAnnex(models.Model, IDocument, Extension):
name = fields.Char(string="Name",) name = fields.Char(string="Name",)
display_name = fields.Char(compute="_compute_display_name",) display_name = fields.Char(compute="_compute_display_name",)
specification_name = fields.Char(compute="_compute_specification_name",)
order_id = fields.Many2one( order_id = fields.Many2one(
"sale.order", "sale.order",
string="Order", string="Order",
@ -57,6 +58,13 @@ class ContractOrderAnnex(models.Model, IDocument, Extension):
for record in self: for record in self:
record.display_name = "{} {}".format(record.number or record.contract_id.contract_annex_number, record.name) record.display_name = "{} {}".format(record.number or record.contract_id.contract_annex_number, record.name)
@api.depends('specification_name', 'contract_id', 'order_id')
def _compute_specification_name(self):
self.specification_name = _("{name} from {date}").format(
name="{}-{}".format(self.contract_id.name, self.order_id.name),
date=self.contract_id.get_date().strftime("%d.%m.%Y"),
)
@api.model @api.model
def create(self, values): def create(self, values):
record = super().create(values) record = super().create(values)

View File

@ -161,13 +161,9 @@ class ContractWizard(models.TransientModel):
if transient_field.technical_name and transient_field.value if transient_field.technical_name and transient_field.value
} }
if self.target._name == "res.partner.contract.annex": if self.target._name == "res.partner.contract.annex":
# TODO: bad
fields.update({ fields.update({
"annex_name": self.document_name, "annex_name": self.document_name,
"specification_name": _("{name} from {date}").format( "specification_name": self.target.specification_name,
name="{}-{}".format(self.target.contract_id.name, self.target.order_id.name),
date=self.target.contract_id.get_date().strftime("%d.%m.%Y"),
),
}) })
binary_data = get_document_from_values_stream(path_to_template, fields).read() binary_data = get_document_from_values_stream(path_to_template, fields).read()