[IMP] compute the custom name of document
This commit is contained in:
parent
cfe0fb0d7a
commit
822b095cdf
@ -105,6 +105,9 @@ class PartnerContract(models.Model, Extension):
|
|||||||
"context": {"self_id": self.id},
|
"context": {"self_id": self.id},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def get_name_by_document_template(self, document_template_id):
|
||||||
|
return self.name
|
||||||
|
|
||||||
def get_filename_by_document_template(self, document_template_id):
|
def get_filename_by_document_template(self, document_template_id):
|
||||||
return _("{type} {number} from {date}").format(
|
return _("{type} {number} from {date}").format(
|
||||||
type=_(dict(document_template_id._fields['document_type'].selection).get(document_template_id.document_type)),
|
type=_(dict(document_template_id._fields['document_type'].selection).get(document_template_id.document_type)),
|
||||||
|
@ -85,6 +85,17 @@ class ContractOrderAnnex(models.Model, Extension):
|
|||||||
"context": {"self_id": self.id},
|
"context": {"self_id": self.id},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def get_name_by_document_template(self, document_template_id):
|
||||||
|
return {
|
||||||
|
"specification": "{number} {name}",
|
||||||
|
"approval_list": "{number}.1 {name}-1",
|
||||||
|
"act_at": "{number}.2 {name}-2",
|
||||||
|
"act_ad": "{number}.3 {name}-3",
|
||||||
|
}.get(document_template_id.document_type_name, "Unknown").format(
|
||||||
|
number=self.number,
|
||||||
|
name=self.name,
|
||||||
|
)
|
||||||
|
|
||||||
def get_filename_by_document_template(self, document_template_id):
|
def get_filename_by_document_template(self, document_template_id):
|
||||||
return "{type} №{name}".format(
|
return "{type} №{name}".format(
|
||||||
type=_(dict(document_template_id._fields['document_type'].selection).get(document_template_id.document_type)),
|
type=_(dict(document_template_id._fields['document_type'].selection).get(document_template_id.document_type)),
|
||||||
|
@ -30,6 +30,7 @@ class ContractWizard(models.TransientModel):
|
|||||||
document_template = fields.Many2one(
|
document_template = fields.Many2one(
|
||||||
"res.partner.document.template", string="Document Template",
|
"res.partner.document.template", string="Document Template",
|
||||||
)
|
)
|
||||||
|
document_name = fields.Char(string="Document Name", compute='_compute_document_name')
|
||||||
transient_field_ids = fields.One2many(
|
transient_field_ids = fields.One2many(
|
||||||
"res.partner.contract.field.transient",
|
"res.partner.contract.field.transient",
|
||||||
"_contract_wizard_id",
|
"_contract_wizard_id",
|
||||||
@ -44,6 +45,10 @@ class ContractWizard(models.TransientModel):
|
|||||||
if not self.document_template:
|
if not self.document_template:
|
||||||
raise ValidationError("You did not set up the template...")
|
raise ValidationError("You did not set up the template...")
|
||||||
|
|
||||||
|
@api.depends('document_name', 'document_template', 'target')
|
||||||
|
def _compute_document_name(self):
|
||||||
|
self.document_name = self.target.get_name_by_document_template(self.document_template)
|
||||||
|
|
||||||
@api.onchange("document_template")
|
@api.onchange("document_template")
|
||||||
def _onchange_document_template(self):
|
def _onchange_document_template(self):
|
||||||
"""Creates transient fields for generate contract template
|
"""Creates transient fields for generate contract template
|
||||||
@ -158,15 +163,7 @@ class ContractWizard(models.TransientModel):
|
|||||||
if self.target._name == "res.partner.contract.annex":
|
if self.target._name == "res.partner.contract.annex":
|
||||||
# TODO: bad
|
# TODO: bad
|
||||||
fields.update({
|
fields.update({
|
||||||
"annex_name": {
|
"annex_name": self.document_name,
|
||||||
"specification": "{number} {name}",
|
|
||||||
"approval_list": "{number}.1 {name}-1",
|
|
||||||
"act_at": "{number}.2 {name}-2",
|
|
||||||
"act_ad": "{number}.3 {name}-3",
|
|
||||||
}.get(self.document_template.document_type_name).format(
|
|
||||||
number=self.target.number,
|
|
||||||
name=self.target.name,
|
|
||||||
),
|
|
||||||
"specification_name": _("{name} from {date}").format(
|
"specification_name": _("{name} from {date}").format(
|
||||||
name="{}-{}".format(self.target.contract_id.name, self.target.order_id.name),
|
name="{}-{}".format(self.target.contract_id.name, self.target.order_id.name),
|
||||||
date=self.target.contract_id.get_date().strftime("%d.%m.%Y"),
|
date=self.target.contract_id.get_date().strftime("%d.%m.%Y"),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user