[UPD] Black reformat

This commit is contained in:
Stepan Savelyev 2020-02-26 17:31:04 +05:00
parent 4e0f925969
commit a262298b5f
2 changed files with 25 additions and 20 deletions

View File

@ -2,8 +2,7 @@ import datetime as dt
import inspect import inspect
from odoo import fields from odoo import fields
from odoo.tools.misc import (DEFAULT_SERVER_DATE_FORMAT, from odoo.tools.misc import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT
DEFAULT_SERVER_DATETIME_FORMAT)
class IDocument(object): class IDocument(object):

View File

@ -20,7 +20,9 @@ class ContractWizard(models.TransientModel, Extension):
) )
def _default_document_template(self): def _default_document_template(self):
return self.env["res.partner.document.template"].search(self._get_template_domain(), limit=1) return self.env["res.partner.document.template"].search(
self._get_template_domain(), limit=1
)
def _get_template_domain(self): def _get_template_domain(self):
template_type = { template_type = {
@ -90,13 +92,9 @@ class ContractWizard(models.TransientModel, Extension):
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.onchange('document_template') @api.onchange("document_template")
def _domain_document_template(self): def _domain_document_template(self):
return { return {"domain": {"document_template": self._get_template_domain(),}}
"domain": {
"document_template": self._get_template_domain(),
}
}
@api.onchange("document_template") @api.onchange("document_template")
def _onchange_document_template(self): def _onchange_document_template(self):
@ -159,7 +157,10 @@ class ContractWizard(models.TransientModel, Extension):
get_fn = self.target.get_filename_by_document_template get_fn = self.target.get_filename_by_document_template
attachment_name = "{}.docx".format(get_fn(self.document_template or "Unknown")) attachment_name = "{}.docx".format(get_fn(self.document_template or "Unknown"))
document_as_attachment = self.env["ir.attachment"].sudo().create( document_as_attachment = (
self.env["ir.attachment"]
.sudo()
.create(
{ {
"name": attachment_name, "name": attachment_name,
"datas_fname": attachment_name, "datas_fname": attachment_name,
@ -167,6 +168,7 @@ class ContractWizard(models.TransientModel, Extension):
"datas": encoded_data, "datas": encoded_data,
} }
) )
)
return self.afterload(document_as_attachment) return self.afterload(document_as_attachment)
@ -188,8 +190,9 @@ class ContractWizard(models.TransientModel, Extension):
) )
# Extend with order product lines # Extend with order product lines
if hasattr(self.target, "order_id") and self.target.order_id.order_line: if hasattr(self.target, "order_id") and self.target.order_id.order_line:
def number_generator(n=1): def number_generator(n=1):
while (True): while True:
yield n yield n
n += 1 n += 1
@ -206,9 +209,12 @@ class ContractWizard(models.TransientModel, Extension):
"unit": item.product_uom.name, "unit": item.product_uom.name,
"cost": self.to_fixed(item.price_unit), "cost": self.to_fixed(item.price_unit),
"subtotal": self.to_fixed(item.price_subtotal), "subtotal": self.to_fixed(item.price_subtotal),
} for item in self.target.order_id.order_line or [] }
for item in self.target.order_id.order_line or []
], ],
"total_amount": self.to_fixed(sum(self.target.order_id.order_line.mapped("price_subtotal"))) "total_amount": self.to_fixed(
sum(self.target.order_id.order_line.mapped("price_subtotal"))
),
} }
) )
return self.middleware_fields(fields) return self.middleware_fields(fields)