Odoo Help

1

Problem with custom_field VAT price per account.invoice.line and recompute taxe account.invoice

By
dark
on 4/2/15, 11:34 AM 708 views

I try to add a field in treeview account_invoice_line in invoice which compute and display VAT price per account_invoice_line (1). It's done but when try to recompute total tax (2), the VAT price per line is recompute to 0 (Except for line create in sale.order)



Have you an idea for VAT prices are good for all account.invoice.line 


My code : 

class cap_account_invoice_line(osv.osv):

_inherit = 'account.invoice.line'

_columns = {

'price_with_tax':fields.float(string='Prix TTC', store=True, readonly=True,),

}

@api.multi

def product_id_change(self, product, account_id, uom_id, qty=0, name='', type_x='out_invoice',

partner_id=False, fposition_id=False, price_unit=False, currency_id=False, company_id=None,context = None):

if context is None:

context = {}

if partner_id:

res = super(cap_account_invoice_line, self).product_id_change(product, uom_id, qty=qty, name=name, type=type_x,

partner_id=partner_id, fposition_id=fposition_id, price_unit=price_unit, currency_id=currency_id,

company_id=company_id)

if res == 0:

return res

context = self._context

company_id = company_id if company_id is not None else context.get('company_id', False)

self = self.with_context(company_id=company_id, force_company=company_id)

part = self.env['res.partner'].browse(partner_id)

product = self.env['product.product'].browse(product)

fpos = self.env['account.fiscal.position'].browse(fposition_id)

if type in ('out_invoice', 'out_refund'):

account = product.property_account_income or product.categ_id.property_account_income_categ

else:

account = product.property_account_expense or product.categ_id.property_account_expense_categ

account = fpos.map_account(account)

if type in ('out_invoice', 'out_refund'):

taxes = product.taxes_id or account.tax_ids

else:

taxes = product.supplier_taxes_id or account.tax_ids

taxes = fpos.map_tax(taxes)

taxes.ids

values = res['value']

price = values.get('price_unit', 0) * (1 - values.get('discount', 0) / 100.0)

taxes = values.get('invoice_line_tax_id')

taxes = self.env['account.tax'].browse(taxes)

tax_res = taxes.compute_all(price, qty,product=product, partner=part)

values['price_with_tax'] = tax_res['total_included']

res['value'] = values

return res

@api.multi

def uos_id_change(self, product, uom, qty=0, name='', type_x='out_invoice', partner_id=False,

fposition_id=False, price_unit=False, currency_id=False, company_id=None):

if uom:

super(cap_account_invoice_line, self).uos_id_change(product, uom, qty, name, type_x, partner_id, fposition_id, price_unit, currency_id, company_id)





0

Serpent Consulting Services Pvt. Ltd.

--Serpent Consulting Services Pvt. Ltd.--
4434
| 6 6 8
Gandhinagar, India
--Serpent Consulting Services Pvt. Ltd.--

Serpent Consulting Services Pvt. Ltd. Your Odoo/OpenERP Solution, just an email away!

Serpent Consulting Services Pvt. Ltd.
On 4/2/15, 11:53 AM

Hi,

While you recompute the invoice, did you make sure your vat price is already affecting the price_subtotal of the invoice line?

Logically, your new field should affect the calculations of the field subtotal. And that subtotal will affect the other float fields of the invoice.

Hope this helps.

Thanks.

1

Cyril Gaspard (GEM)

--Cyril Gaspard (GEM)--
4136
| 5 6 8
Paris, France
--Cyril Gaspard (GEM)--

Forum contributor since 2008

Cyril Gaspard (GEM)
On 4/2/15, 8:23 PM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 4/2/15, 11:34 AM
Seen: 708 times
Last updated: 5/6/15, 9:38 AM