I want to set a tax for each lines of an invoice.

Asked by Angel

Hi

Actually I need to set a tax for each lines of an invoice. I have tried but its not working. How do I get the rate dynamically.....please help

Kind regards

Nandini

Question information

Language:
English Edit question
Status:
Solved
For:
Odoo Addons (MOVED TO GITHUB) Edit question
Assignee:
No assignee Edit question
Solved by:
Husen Daudi
Solved:
Last query:
Last reply:
Revision history for this message
Parthiv Patel (parthiv-patel-deactivatedaccount) said :
#1

can you elaborate the exact scenario ?

Regards,
Parthiv

Revision history for this message
Angel (nandini2306) said :
#2

Thanks for your prompt reply...

Well when I go to Sales module---> Sales Orders----> Click on New
          1. select the customer
          2. click on Advance Invoice
          3. select Advance Product/Amount
          4. Click on Create Invoice
          5. Prompt you a message "You invoice has been successfully created! ----Close or Open Invoice
         6. Click on "Open Invoice"
         7. Now you create several invoices - suppose you have 2 records in the invoice line as shown below:

        Product Qty Unit Price Discount Subtotal
        xxxxx 1 100 0 100
        yyyy 1 200 0 200

       8 Now I want to add a column Line Vat Amount with the actual vat rate from table account.tax field amount as shown below :
     Product Qty Unit Price Discount Line Vat Amount Subtotal
        xxxxx 1 100 0 15 115
        yyyy 1 200 0 30 230

     I have selected tax rate 15%

Should you need any other info please let me know.
Please help.

Revision history for this message
Husen Daudi (husendaudi) said :
#3

You can add one function field in invoice.line object which will compute line wise tax.
you can reuse code of account.invoice to compute line wise tax in new function field.

Revision history for this message
Angel (nandini2306) said :
#4

Actually I wrote a class that inherit the account.invoice.line class and created a function field. But it doesn't work. It gives following error :

ProgrammingError: column account_invoice_line.vatt does not exist
LINE 1: ...voice_line.uos_id,account_invoice_line.account_id,account_in...

Here's .py file

import decimal_precision as dp
from osv import osv,fields

class account_invoice_line(osv.osv):

 def _amount_tax_linee(self,cr,uid,ids,name,args,context=None):
  res = {}
  tax_obj = self.pool.get('account.tax')
  for line in self.browse(cr,uid,ids):
   price = line.price_unit * (1-(line.discount or 0.0)/100.0)
   taxes = tax_obj.compute_all(cr, uid, line.invoice_line_tax_id, price, line.quantity, product=line.product_id,address_id=line.invoice_id.address_invoice_id,partner=line.invoice_id.partner_id)
   for tax in tax_obj.compute_all(cr, uid, line.invoice_line_tax_id, (line.price_unit* (1-(line.discount or 0.0)/100.0)), line.quantity, line.invoice_id.address_invoice_id,line.product_id,line.invoice_id.partner_id)['taxes']:
    val = {}
    val['amount'] = tax['amount']
    res[line.id] = val['amount']
  return res

 _name="account.invoice.line"
 _inherit="account.invoice.line"
 _columns = {
  'vatt' : fields.function(_amount_tax_linee, method=True, string='Line Vat', type="float",
            digits_compute= dp.get_precision('Account'), store=True),

 }

account_invoice_line()

Kindly advise where am I wrong.

Best regards
Angel

Revision history for this message
Best Husen Daudi (husendaudi) said :
#5

try to upgrade your module or check by creating new database, code seems correct so it must work as expected.

Revision history for this message
Angel (nandini2306) said :
#6

Complete error message

Environment Information :
System : Windows-Vista-6.1.7600
OS Name : nt
Operating System Release : Vista
Operating System Version : 6.1.7600
Operating System Architecture : 32bit
Operating System Locale : en_GB.cp1252
Python Version : 2.5.2
OpenERP-Client Version : 6.0.1
Last revision No. & ID :Bazaar Package not Found !Traceback (most recent call last):
  File "netsvc.pyo", line 489, in dispatch
  File "service\web_services.pyo", line 599, in dispatch
  File "osv\osv.pyo", line 122, in wrapper
  File "osv\osv.pyo", line 176, in execute
  File "osv\osv.pyo", line 167, in execute_cr
  File "osv\orm.pyo", line 2921, in read
  File "osv\orm.pyo", line 3041, in _read_flat
  File "osv\fields.pyo", line 793, in get
  File "C:\Program Files\OpenERP 6.0\Server\addons\account_invoice_layout\account_invoice_layout.py", line 136, in _fnct
  File "osv\orm.pyo", line 285, in __getattr__
  File "osv\orm.pyo", line 205, in __getitem__
  File "osv\orm.pyo", line 2921, in read
  File "osv\orm.pyo", line 2980, in _read_flat
  File "sql_db.pyo", line 78, in wrapper
  File "sql_db.pyo", line 131, in execute
ProgrammingError: column account_invoice_line.vatt does not exist
LINE 1: ...voice_line.uos_id,account_invoice_line.account_id,account_in...

Revision history for this message
xrg (xrg) said :
#7

On Wednesday 16 February 2011, you wrote:
> Question #144173 on OpenERP Addons changed:
> https://answers.launchpad.net/openobject-addons/+question/144173

> ProgrammingError: column account_invoice_line.vatt does not exist
> LINE 1: ...voice_line.uos_id,account_invoice_line.account_id,account_in...

did you put a double 't' there? "vatt" ??

Revision history for this message
Angel (nandini2306) said :
#8

Thanks Husen Daudi, that solved my question.