[REF] account: refactors the onchange product_id on invoices
get the product_name thanks to a function, so that we can reuse it somewhere else (account_predictive_account) Part of PR #26876. Part of task #1882329
This commit is contained in:
@@ -560,6 +560,7 @@ class AccountInvoice(models.Model):
|
|||||||
return view.id
|
return view.id
|
||||||
|
|
||||||
context = self._context
|
context = self._context
|
||||||
|
supplier_form_view_id = get_view_id('invoice_supplier_form', 'account.invoice.supplier.form').id
|
||||||
if context.get('active_model') == 'res.partner' and context.get('active_ids'):
|
if context.get('active_model') == 'res.partner' and context.get('active_ids'):
|
||||||
partner = self.env['res.partner'].browse(context['active_ids'])[0]
|
partner = self.env['res.partner'].browse(context['active_ids'])[0]
|
||||||
if not view_type:
|
if not view_type:
|
||||||
@@ -567,9 +568,10 @@ class AccountInvoice(models.Model):
|
|||||||
view_type = 'tree'
|
view_type = 'tree'
|
||||||
elif view_type == 'form':
|
elif view_type == 'form':
|
||||||
if partner.supplier and not partner.customer:
|
if partner.supplier and not partner.customer:
|
||||||
view_id = get_view_id('invoice_supplier_form', 'account.invoice.supplier.form').id
|
view_id = supplier_form_view_id
|
||||||
elif partner.customer and not partner.supplier:
|
elif partner.customer and not partner.supplier:
|
||||||
view_id = get_view_id('invoice_form', 'account.invoice.form').id
|
view_id = get_view_id('invoice_form', 'account.invoice.form').id
|
||||||
|
|
||||||
return super(AccountInvoice, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu)
|
return super(AccountInvoice, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu)
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
@@ -1684,18 +1686,14 @@ class AccountInvoiceLine(models.Model):
|
|||||||
else:
|
else:
|
||||||
product = self.product_id
|
product = self.product_id
|
||||||
|
|
||||||
self.name = product.partner_ref
|
|
||||||
account = self.get_invoice_line_account(type, product, fpos, company)
|
account = self.get_invoice_line_account(type, product, fpos, company)
|
||||||
if account:
|
if account:
|
||||||
self.account_id = account.id
|
self.account_id = account.id
|
||||||
self._set_taxes()
|
self._set_taxes()
|
||||||
|
|
||||||
if type in ('in_invoice', 'in_refund'):
|
product_name = self._get_invoice_line_name_from_product()
|
||||||
if product.description_purchase:
|
if product_name != None:
|
||||||
self.name += '\n' + product.description_purchase
|
self.name = product_name
|
||||||
else:
|
|
||||||
if product.description_sale:
|
|
||||||
self.name += '\n' + product.description_sale
|
|
||||||
|
|
||||||
if not self.uom_id or product.uom_id.category_id.id != self.uom_id.category_id.id:
|
if not self.uom_id or product.uom_id.category_id.id != self.uom_id.category_id.id:
|
||||||
self.uom_id = product.uom_id.id
|
self.uom_id = product.uom_id.id
|
||||||
@@ -1707,6 +1705,24 @@ class AccountInvoiceLine(models.Model):
|
|||||||
self.price_unit = product.uom_id._compute_price(self.price_unit, self.uom_id)
|
self.price_unit = product.uom_id._compute_price(self.price_unit, self.uom_id)
|
||||||
return {'domain': domain}
|
return {'domain': domain}
|
||||||
|
|
||||||
|
def _get_invoice_line_name_from_product(self):
|
||||||
|
""" Returns the automatic name to give to the invoice line depending on
|
||||||
|
the product it is linked to.
|
||||||
|
"""
|
||||||
|
self.ensure_one()
|
||||||
|
if not self.product_id:
|
||||||
|
return ''
|
||||||
|
|
||||||
|
rslt = self.product_id.partner_ref
|
||||||
|
if type in ('in_invoice', 'in_refund'):
|
||||||
|
if self.product_id.description_purchase:
|
||||||
|
rslt += '\n' + self.product_id.description_purchase
|
||||||
|
else:
|
||||||
|
if self.product_id.description_sale:
|
||||||
|
rslt += '\n' + self.product_id.description_sale
|
||||||
|
|
||||||
|
return rslt
|
||||||
|
|
||||||
@api.onchange('account_id')
|
@api.onchange('account_id')
|
||||||
def _onchange_account_id(self):
|
def _onchange_account_id(self):
|
||||||
if not self.account_id:
|
if not self.account_id:
|
||||||
|
|||||||
Reference in New Issue
Block a user