[STYLE] black
This commit is contained in:
parent
b2ff60057d
commit
5b4c0b2876
@ -110,7 +110,11 @@ class PartnerContract(models.Model, IDocument, Extension):
|
||||
|
||||
def get_filename_by_document_template(self, document_template_id):
|
||||
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
|
||||
)
|
||||
),
|
||||
number=self.name,
|
||||
date=self.get_date().strftime("%d.%m.%Y"),
|
||||
)
|
||||
|
@ -27,7 +27,7 @@ class ContractOrderAnnex(models.Model, IDocument, Extension):
|
||||
date_conclusion = fields.Date(
|
||||
string="Conclusion Date", default=fields.Date.today(),
|
||||
)
|
||||
number = fields.Integer(string="№",help="Counter of Contract Annexes")
|
||||
number = fields.Integer(string="№", help="Counter of Contract Annexes")
|
||||
|
||||
development_period = fields.Integer("Product Development Period (days)",)
|
||||
|
||||
@ -70,12 +70,14 @@ class ContractOrderAnnex(models.Model, IDocument, Extension):
|
||||
}
|
||||
|
||||
@api.multi
|
||||
@api.depends('name')
|
||||
@api.depends("name")
|
||||
def _compute_display_name(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')
|
||||
@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),
|
||||
@ -111,30 +113,41 @@ class ContractOrderAnnex(models.Model, IDocument, Extension):
|
||||
}
|
||||
|
||||
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,
|
||||
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):
|
||||
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
|
||||
)
|
||||
),
|
||||
name={
|
||||
"bill": "{number} {type} {name}",
|
||||
"specification": "{number} {type} {name}",
|
||||
"approval_list": "{number}.1 {type} {name}-1",
|
||||
"act_at": "{number}.2 {type} {name}-2",
|
||||
"act_ad": "{number}.3 {type} {name}-3",
|
||||
}.get(document_template_id.document_type_name).format(
|
||||
}
|
||||
.get(document_template_id.document_type_name)
|
||||
.format(
|
||||
number=self.number,
|
||||
type=_(dict(document_template_id._fields['document_type_name'].selection).get(document_template_id.document_type_name)),
|
||||
type=_(
|
||||
dict(
|
||||
document_template_id._fields["document_type_name"].selection
|
||||
).get(document_template_id.document_type_name)
|
||||
),
|
||||
name=self.name,
|
||||
)
|
||||
),
|
||||
)
|
||||
|
||||
def modf(self, arg):
|
||||
|
@ -8,7 +8,10 @@ class DocumentTemplate(models.Model):
|
||||
|
||||
name = fields.Char()
|
||||
attachment_id = fields.Many2one(
|
||||
"ir.attachment", string="Template Attachment", ondelete="cascade", required=True,
|
||||
"ir.attachment",
|
||||
string="Template Attachment",
|
||||
ondelete="cascade",
|
||||
required=True,
|
||||
)
|
||||
document_type = fields.Selection(
|
||||
string="Type of document",
|
||||
@ -16,7 +19,7 @@ class DocumentTemplate(models.Model):
|
||||
("contract", _("Contract")),
|
||||
("annex", _("Annex")),
|
||||
("addition", _("Addition")),
|
||||
]
|
||||
],
|
||||
)
|
||||
document_type_name = fields.Selection(
|
||||
string="Document",
|
||||
@ -26,7 +29,7 @@ class DocumentTemplate(models.Model):
|
||||
("approval_list", _("Approval List")),
|
||||
("act_at", _("Act of Acceptance and Transfer")),
|
||||
("act_ad", _("Act of Acceptance and Delivery")),
|
||||
]
|
||||
],
|
||||
)
|
||||
company_type = fields.Selection(
|
||||
selection=[
|
||||
|
@ -9,14 +9,17 @@ class IDocument(object):
|
||||
"""Class must be used as an interface for create new document based model"""
|
||||
|
||||
def get_name_by_document_template(self, document_template_id: fields.Many2one):
|
||||
raise NotImplementedError('Method {} is not implemented'.format(inspect.currentframe().f_code.co_name))
|
||||
raise NotImplementedError(
|
||||
"Method {} is not implemented".format(inspect.currentframe().f_code.co_name)
|
||||
)
|
||||
|
||||
def get_filename_by_document_template(self, document_template_id: fields.Many2one):
|
||||
raise NotImplementedError('Method {} is not implemented'.format(inspect.currentframe().f_code.co_name))
|
||||
raise NotImplementedError(
|
||||
"Method {} is not implemented".format(inspect.currentframe().f_code.co_name)
|
||||
)
|
||||
|
||||
|
||||
class Extension(object):
|
||||
|
||||
def parse_odoo_date(self, date: str):
|
||||
return dt.datetime.strptime(date, DEFAULT_SERVER_DATE_FORMAT)
|
||||
|
||||
|
@ -24,9 +24,7 @@ class ContractWizard(models.TransientModel):
|
||||
"res.partner.contract": "contract",
|
||||
"res.partner.contract.annex": "annex",
|
||||
}.get(self.active_model, False)
|
||||
company_type = (
|
||||
partner_id.company_form if partner_id.is_company else "person"
|
||||
)
|
||||
company_type = partner_id.company_form if partner_id.is_company else "person"
|
||||
|
||||
document_template_domain = [
|
||||
("template_type", "=", template_type),
|
||||
@ -45,11 +43,17 @@ class ContractWizard(models.TransientModel):
|
||||
string="Target",
|
||||
)
|
||||
company_id = fields.Many2one("res.partner", string="Company")
|
||||
partner_id = fields.Many2one("res.partner", string="Partner", default=_get_default_partner)
|
||||
document_template = fields.Many2one(
|
||||
"res.partner.document.template", string="Document Template", default=_get_default_template,
|
||||
partner_id = fields.Many2one(
|
||||
"res.partner", string="Partner", default=_get_default_partner
|
||||
)
|
||||
document_template = fields.Many2one(
|
||||
"res.partner.document.template",
|
||||
string="Document Template",
|
||||
default=_get_default_template,
|
||||
)
|
||||
document_name = fields.Char(
|
||||
string="Document Name", compute="_compute_document_name"
|
||||
)
|
||||
document_name = fields.Char(string="Document Name", compute='_compute_document_name')
|
||||
transient_field_ids = fields.One2many(
|
||||
"res.partner.contract.field.transient",
|
||||
"_contract_wizard_id",
|
||||
@ -64,9 +68,11 @@ class ContractWizard(models.TransientModel):
|
||||
if not self.document_template:
|
||||
raise ValidationError("You did not set up the template...")
|
||||
|
||||
@api.depends('document_name', 'document_template', 'target')
|
||||
@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)
|
||||
self.document_name = self.target.get_name_by_document_template(
|
||||
self.document_template
|
||||
)
|
||||
|
||||
@api.onchange("document_template")
|
||||
def _onchange_document_template(self):
|
||||
@ -143,7 +149,14 @@ class ContractWizard(models.TransientModel):
|
||||
self.partner_id.company_form if self.partner_id.is_company else "person"
|
||||
)
|
||||
|
||||
return {"domain": {"document_template": [("template_type", "=", template_type),("company_type", "=", company_type),],}}
|
||||
return {
|
||||
"domain": {
|
||||
"document_template": [
|
||||
("template_type", "=", template_type),
|
||||
("company_type", "=", company_type),
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
@api.multi
|
||||
def get_docx_contract(self):
|
||||
@ -159,15 +172,20 @@ class ContractWizard(models.TransientModel):
|
||||
if transient_field.technical_name and transient_field.value
|
||||
}
|
||||
if self.target._name == "res.partner.contract.annex":
|
||||
fields.update({
|
||||
"annex_name": self.document_name,
|
||||
"specification_name": self.target.specification_name,
|
||||
})
|
||||
fields.update(
|
||||
{
|
||||
"annex_name": self.document_name,
|
||||
"specification_name": self.target.specification_name,
|
||||
}
|
||||
)
|
||||
|
||||
binary_data = get_document_from_values_stream(path_to_template, fields).read()
|
||||
encoded_data = base64.b64encode(binary_data)
|
||||
|
||||
attachment_name = self.target.get_filename_by_document_template(self.document_template) or "Unknown"
|
||||
attachment_name = (
|
||||
self.target.get_filename_by_document_template(self.document_template)
|
||||
or "Unknown"
|
||||
)
|
||||
attachment_name = "{}.docx".format(attachment_name)
|
||||
|
||||
document_as_attachment = self.env["ir.attachment"].create(
|
||||
|
Loading…
x
Reference in New Issue
Block a user