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