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