[FIX] account_analytic_default: Default analytic account for invoice on delivery

When creating an invoice from a DO,
if there is no analytical account defined on the SO,
then use the default analytical account for that product.

Closes #9725
opw-657492
This commit is contained in:
Xavier, Sodexis 2015-11-23 13:36:13 +05:30 committed by Denis Ledoux
parent 1b8c9aed9f
commit 70847ac5c0
1 changed files with 14 additions and 0 deletions

View File

@ -153,4 +153,18 @@ class product_template(osv.Model):
result['context'] = "{}"
return result
class stock_move(osv.Model):
_inherit = 'stock.move'
def _create_invoice_line_from_vals(self, cr, uid, move, invoice_line_vals, context=None):
# It will set the default analtyic account on the invoice line
partner_id = self.pool['account.invoice'].browse(cr, uid, invoice_line_vals.get('invoice_id'), context=context).partner_id.id
if 'account_analytic_id' not in invoice_line_vals or not invoice_line_vals.get('account_analytic_id'):
rec = self.pool['account.analytic.default'].account_get(cr, uid, move.product_id.id, partner_id, uid, time.strftime('%Y-%m-%d'), company_id=move.company_id.id, context=context)
if rec:
invoice_line_vals.update({'account_analytic_id': rec.analytic_id.id})
res = super(stock_move, self)._create_invoice_line_from_vals(cr, uid, move, invoice_line_vals, context=context)
return res
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: