[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
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user