[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
This commit is contained in:
Nicolas Martinelli
2016-01-21 15:51:20 +01:00
parent be0ff1946d
commit 564fda4d8f
3 changed files with 17 additions and 0 deletions
+10
View File
@@ -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"
@@ -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'
+1
View File
@@ -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