IMP account_usability: set sale date on invoice (#101)

* IMP account_usability: set sale date on invoice
This commit is contained in:
David Beal
2019-08-19 13:06:41 +02:00
committed by GitHub
parent c5ffe375a5
commit e220da006f
3 changed files with 39 additions and 3 deletions

View File

@@ -37,6 +37,10 @@ class AccountInvoice(models.Model):
has_attachment = fields.Boolean(
compute='_compute_has_attachment',
search='_search_has_attachment', readonly=True)
sale_dates = fields.Char(
compute="_compute_sales_dates", readonly=True,
help="This information appears on invoice qweb report "
"(you may use it for your own report)")
def _compute_has_discount(self):
prec = self.env['decimal.precision'].precision_get('Discount')
@@ -170,6 +174,24 @@ class AccountInvoice(models.Model):
# ]
return res
def _compute_sales_dates(self):
""" French law requires to set sale order dates into invoice
returned string: "sale1 (date1), sale2 (date2) ..."
"""
for inv in self:
sales = inv.invoice_line_ids.mapped(
'sale_line_ids').mapped('order_id')
lang = inv.partner_id.commercial_partner_id.lang
date_format = self.env["res.lang"]._lang_get(
lang or "").date_format
dates = ["%s%s" % (
x.name,
x.confirmation_date and " (%s)" %
# only when confirmation_date display it
x.confirmation_date.strftime(date_format) or "")
for x in sales]
inv.sale_dates = ", ".join(dates)
class AccountInvoiceLine(models.Model):
_inherit = 'account.invoice.line'