From 564fda4d8f557734109520128061f05cbeec6897 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Thu, 21 Jan 2016 15:25:03 +0100 Subject: [PATCH] [FIX] account, account_asset, purchase: extra field in auto fill The Purchase module provides a functionality to add pre-filled invoice lines to an invoice. The issue is that extensions of the accounting modules might add fields on an invoice line, and one would like to see these fields populated as well. This is the case for account_asset, which adds an asset_category_id on an invoice line. However, the Purchase module is not aware of the fields added by account_asset, and therefore it cannot populate them. This fix adds a method, _auto_fill_extra, which is intended to manage these extra fields. opw-667162 --- addons/account/models/account_invoice.py | 10 ++++++++++ addons/account_asset/account_asset_invoice.py | 6 ++++++ addons/purchase/invoice.py | 1 + 3 files changed, 17 insertions(+) diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py index 1cb676ee3b5..ba922150f89 100644 --- a/addons/account/models/account_invoice.py +++ b/addons/account/models/account_invoice.py @@ -1185,6 +1185,16 @@ class AccountInvoiceLine(models.Model): result['warning'] = warning return result + def _set_additional_fields(self, invoice): + """ Some modules, such as Purchase, provide a feature to add automatically pre-filled + invoice lines. However, these modules might not be aware of extra fields which are + added by extensions of the accounting module. + This method is intended to be overridden by these extensions, so that any new field can + easily be auto-filled as well. + :param invoice : account.invoice corresponding record + :rtype line : account.invoice.line record + """ + pass class AccountInvoiceTax(models.Model): _name = "account.invoice.tax" diff --git a/addons/account_asset/account_asset_invoice.py b/addons/account_asset/account_asset_invoice.py index 276a6a22d43..7a0b90c3581 100644 --- a/addons/account_asset/account_asset_invoice.py +++ b/addons/account_asset/account_asset_invoice.py @@ -72,6 +72,12 @@ class AccountInvoiceLine(models.Model): elif self.invoice_id.type == 'in_invoice': self.asset_category_id = self.product_id.product_tmpl_id.asset_category_id + def _set_additional_fields(self, invoice): + if invoice.type == 'out_invoice': + self.asset_category_id = self.product_id.product_tmpl_id.deferred_revenue_category_id.id + elif invoice.type == 'in_invoice': + self.asset_category_id = self.product_id.product_tmpl_id.asset_category_id.id + super(AccountInvoiceLine, self)._set_additional_fields(invoice) class ProductTemplate(models.Model): _inherit = 'product.template' diff --git a/addons/purchase/invoice.py b/addons/purchase/invoice.py index 66faa5ca7b5..9c6f3294d13 100644 --- a/addons/purchase/invoice.py +++ b/addons/purchase/invoice.py @@ -68,6 +68,7 @@ class AccountInvoice(models.Model): if account: data['account_id'] = account.id new_line = new_lines.new(data) + new_line._set_additional_fields(self) new_lines += new_line self.invoice_line_ids += new_lines