From 30656599de3a5ea61d3b54be35a73066ddf008b6 Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Fri, 30 Sep 2016 14:06:26 +0200 Subject: [PATCH] [FIX] account_asset: asset creation from a vendor bill It wasn't possible to validate a vendor bill using a product with an asset type due to the fact the `default_type: in_invoice` was propagated through the context to the asset creation, and `in_invoice` is not a valid type for an asset. opw-689897 --- addons/account_asset/models/account_invoice.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/addons/account_asset/models/account_invoice.py b/addons/account_asset/models/account_invoice.py index 91e6336d23c..105354f6509 100644 --- a/addons/account_asset/models/account_invoice.py +++ b/addons/account_asset/models/account_invoice.py @@ -20,7 +20,13 @@ class AccountInvoice(models.Model): asset_ids = self.env['account.asset.asset'].sudo().search([('invoice_id', '=', inv.id), ('company_id', '=', inv.company_id.id)]) if asset_ids: asset_ids.write({'active': False}) - inv.invoice_line_ids.asset_create() + context = dict(self.env.context) + # Within the context of an invoice, + # this default value is for the type of the invoice, not the type of the asset. + # This has to be cleaned from the context before creating the asset, + # otherwise it tries to create the asset with the type of the invoice. + context.pop('default_type', None) + inv.invoice_line_ids.with_context(context).asset_create() return result