[REF] account_analytic_analysis: extract a method for preparing invoice lines
In recurring invoices from contracts. It allows to inherit and modify the prepared values for the lines. Closes #6822
This commit is contained in:
parent
1e8f8eabec
commit
26c7ea4de6
|
@ -707,6 +707,28 @@ class account_analytic_account(osv.osv):
|
|||
}
|
||||
return invoice
|
||||
|
||||
def _prepare_invoice_line(self, cr, uid, line, fiscal_position, context=None):
|
||||
fpos_obj = self.pool.get('account.fiscal.position')
|
||||
res = line.product_id
|
||||
account_id = res.property_account_income.id
|
||||
if not account_id:
|
||||
account_id = res.categ_id.property_account_income_categ.id
|
||||
account_id = fpos_obj.map_account(cr, uid, fiscal_position, account_id)
|
||||
|
||||
taxes = res.taxes_id or False
|
||||
tax_id = fpos_obj.map_tax(cr, uid, fiscal_position, taxes)
|
||||
values = {
|
||||
'name': line.name,
|
||||
'account_id': account_id,
|
||||
'account_analytic_id': line.analytic_account_id.id,
|
||||
'price_unit': line.price_unit or 0.0,
|
||||
'quantity': line.quantity,
|
||||
'uos_id': line.uom_id.id or False,
|
||||
'product_id': line.product_id.id or False,
|
||||
'invoice_line_tax_id': [(6, 0, tax_id)],
|
||||
}
|
||||
return values
|
||||
|
||||
def _prepare_invoice_lines(self, cr, uid, contract, fiscal_position_id, context=None):
|
||||
fpos_obj = self.pool.get('account.fiscal.position')
|
||||
fiscal_position = None
|
||||
|
@ -714,26 +736,8 @@ class account_analytic_account(osv.osv):
|
|||
fiscal_position = fpos_obj.browse(cr, uid, fiscal_position_id, context=context)
|
||||
invoice_lines = []
|
||||
for line in contract.recurring_invoice_line_ids:
|
||||
|
||||
res = line.product_id
|
||||
account_id = res.property_account_income.id
|
||||
if not account_id:
|
||||
account_id = res.categ_id.property_account_income_categ.id
|
||||
account_id = fpos_obj.map_account(cr, uid, fiscal_position, account_id)
|
||||
|
||||
taxes = res.taxes_id or False
|
||||
tax_id = fpos_obj.map_tax(cr, uid, fiscal_position, taxes)
|
||||
|
||||
invoice_lines.append((0, 0, {
|
||||
'name': line.name,
|
||||
'account_id': account_id,
|
||||
'account_analytic_id': contract.id,
|
||||
'price_unit': line.price_unit or 0.0,
|
||||
'quantity': line.quantity,
|
||||
'uos_id': line.uom_id.id or False,
|
||||
'product_id': line.product_id.id or False,
|
||||
'invoice_line_tax_id': [(6, 0, tax_id)],
|
||||
}))
|
||||
values = self._prepare_invoice_line(cr, uid, line, fiscal_position, context=context)
|
||||
invoice_lines.append((0, 0, values))
|
||||
return invoice_lines
|
||||
|
||||
def _prepare_invoice(self, cr, uid, contract, context=None):
|
||||
|
|
Loading…
Reference in New Issue