[IMP] intrastat_product: method for XLSX filename

This commit is contained in:
Alexis de Lattre
2023-11-17 16:36:12 +01:00
parent e78a0fbf2a
commit c3888b72ba
2 changed files with 25 additions and 3 deletions

View File

@@ -936,6 +936,30 @@ class IntrastatProductDeclaration(models.Model):
"""
return {}
@api.model
def _get_xlsx_report_filename(self):
self.ensure_one()
declaration_type_label = dict(
self.fields_get("declaration_type", "selection")["declaration_type"][
"selection"
]
)[self.declaration_type]
draft_label = ""
if self.state == "draft":
draft_label = (
"-%s"
% dict(self.fields_get("state", "selection")["state"]["selection"])[
self.state
]
)
filename = _(
"intrastat-%(year_month)s-%(declaration_type)s%(draft)s",
year_month=self.year_month,
declaration_type=declaration_type_label,
draft=draft_label,
)
return filename
def done(self):
for decl in self:
decl.generate_declaration()

View File

@@ -12,9 +12,7 @@
<field name="report_type">xlsx</field>
<field name="report_name">intrastat_product.product_declaration_xls</field>
<field name="report_file">intrastat_product.product_declaration_xls</field>
<field
name="print_report_name"
>'intrastat-%s-%s%s' % (object.year_month, object.declaration_type, object.state == 'draft' and '-draft' or '')</field>
<field name="print_report_name">object._get_xlsx_report_filename()</field>
<field name="binding_model_id" ref="model_intrastat_product_declaration" />
</record>