Odoo Help

Welcome!

This community 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.

0

Creating an invoice line using Odoo (OpenERP) WebService API for PHP

By
Mauricio Rodriguez
on 2/3/15, 10:42 AM 1,929 views

Hi,

I'm trying to create an invoice line using next code:

    // Invoice line creation
    $result = $models->execute_kw($db, $uid, $password,
        'account.invoice.line', 'create',
        array(array(
            'Invoice'=>$invoice,
            'invoice_id'=>$invoice_id,
            'product_id'=>$product_id,
            'quantity'=>$product_quantity,
            'name'=>$product_name,
            'price_unit'=>$product_price,
            'invoice_line_tax_id'=>array($odoo_tax_id)
        )));

The invoice line is created within invoice, but it hasn't any tax.

The existence of that tax is checked and I tried to relate the tax using others ways as:

    'invoice_line_tax'=>array('id'=>$tax['id'],'name'=>$tax['name']),

But it doesn't work either.

The product and invoice used for the invoice line was created before using:

        // Product creation
        $product_id = $models->execute_kw($db, $uid, $password,
            'product.product', 'create',
            array(array(
                'default_code'=>$product_ref,
                'name'=>$product_name,
                'list_price'=>$product_price,
            ))
        );

    // Invoice creation
    $invoice_id = $models->execute_kw($db,$uid,$password,
        'account.invoice',
        'create',
        array(array(
            'partner_id'=>$parter_id,
            'account_id'=>$odoo_invoice_account_id
        )));

    $invoice = $models->execute_kw($db,$uid,$password,
        'account.invoice',
        'read',
        array($invoice_id),
        array());

One person in other forum ask me if the product has the tax enabled, the product has the tax enabled for the clients and suppliers and  I try to do an invoice directly in Odoo with the same product working fine.

I think that the main problem is how to create the relation between invoice line and the tax, because after creating invoice line appears next field:

    ["invoice_line_tax_id"]=> array(0) { }

But in an correct invoice line appears as:

    ["invoice_line_tax_id"]=> array(1) { [0]=> int(4) }

One person in other forum has suggested to install account.tax module, but that module depends on other module (base table) that generates an error during their installation and I don't want to depends on other modules if it's possible.

Thanks

 

0
Paul McDermott
On 10/21/15, 1:41 PM

Well, I had been struggling for most of the afternoon with the same issue. Then I found this question, which triggered some ideas...after poking around the database a bit further I found a solution! Here it is:

The relationship between the invoice line and the taxes is a many-to-many relationship. So there is no invoice_line_tax_id field in the account_invoice_line table. The relationship is instead stored in the account_invoice_line_tax table. Importantly, this table needs a valid account_invoice_line ID before new taxes can be assigned. So what I did is (using Python and OERPlib) is:

    1. Create the new invoice line, forgetting about the taxes.

    2.  Retrieve the new invoice line from the database.

    3.  Now set invoice_line_tax_id to an array of appropriate ints.

    4.  Save the updated invoice line object in the database.

Here it is in Python:

# Get the new line and add the tax

lines = oerp.get('account.invoice.line')

new_line = lines.browse(line_id)

new_line.invoice_line_tax_id = tax_ids_array

oerp.write_record(new_line)

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 2/3/15, 10:42 AM
Seen: 1929 times
Last updated: 10/21/15, 1:42 PM