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

create sale.order.line with tax_id(s) from windows application C#

By
Marc Wagener
on 10/8/14, 6:44 AM 1,728 views

I want to add sales order line to OE and the table sale_order_tax is not visible in OE-models.

tax_id (many2many)

is readonly in the model: "sale.order.line",

I've found that the tax-ids are stored in "sale_order_tax" -table, but this table is not accessible via models. What can I do write to this table.

I can't create a model for existing table, OE forces special prefixes x_

any suggestion?

0
Marc Wagener
On 10/8/14, 9:27 AM

Thank you for your response.

I'm pushing orders from a shopping-cart to OE. For that I'm using Openerp .netConnector with POCO entities.

Customer (incoice-contact, shipping-contact),
Order,
and Orderlines can be created. So now I must fine-tuning the taxes. Taxes are by product-line, but from shopping-cart perspective they are triggered on rules (invoice-country, shipping-country, EU, Extra-EU etc.) So the tax is coming from shopping-cart.When ignoring all this I can force a default tax (default class for now from OE = id 1 @ 15%). So I want to save this tax id with each sales.order.line  but I don't know how to handle this. I see that the table sale_order_tax contents this ids for each orderline as many as tax-classes.

Here is part of the order.item:

                   var neworderline = new OSalesOrderLine();
                   
                    //neworderline.productid = 19;// not uses until products are mapped
                    neworderline.taxId = ????
                    neworderline.orderId = orderId;
                    neworderline.name = item.Product.Name;
                    neworderline.productUomQty = Convert.ToDouble(item.Quantity);
                    neworderline.priceunit = Convert.ToDouble(item.PriceExclTax * currRate);
                    oeService.AddEntity<OSalesOrderLine>(neworderline);

Here is the propreties maping for this model:

[OpenErpMap("sale.order.line")]
    public class OSalesOrderLine : BaseNopModel
    {
        
            [OpenErpMap("name")]
            public string name
            {
                get;
                set;
            }
            [OpenErpMap("order_id")]
            public int orderId
            {
                get;
                set;
            }
            [OpenErpMap("price_unit")]
            public double priceunit
            {
                get;
                set;
            }
            [OpenErpMap("price_subtotal")]
            public double priceSubTotal
            {
                get;
                set;
            }
            [OpenErpMap("product_uom_qty")]
            public double productUomQty
            {
                get;
                set;
            }
            [OpenErpMap("tax_id")]
            public int[] taxId
            {
                get;
                set;
            }
            [OpenErpMap("id")]
            public int id { get; set; }
            [OpenErpMap("product_id")]
            public int productid { get; set; }
    }

I'm adding here the sniffed XML from actual code

<?xml version="1.0"?>
<methodCall>
  <methodName>execute</methodName>
  <params>
    <param>
      <value>
        <string>database</string>
      </value>
    </param>
    <param>
      <value>
        <i4>1</i4>
      </value>
    </param>
    <param>
      <value>
        <string>password</string>
      </value>
    </param>
    <param>
      <value>
        <string>sale.order.line</string>
      </value>
    </param>
    <param>
      <value>
        <string>create</string>
      </value>
    </param>
    <param>
      <value>
        <struct>
          <member>
            <name>name</name>
            <value>
              <string>product name</string>
            </value>
          </member>
          <member>
            <name>order_id</name>
            <value>
              <i4>65</i4>
            </value>
          </member>
          <member>
            <name>price_unit</name>
            <value>
              <double>1285</double>
            </value>
          </member>
          <member>
            <name>price_subtotal</name>
            <value>
              <double>0</double>
            </value>
          </member>
          <member>
            <name>product_uom_qty</name>
            <value>
              <double>2</double>
            </value>
          </member>
          <member>
            <name>product_id</name>
            <value>
              <i4>19</i4>
            </value>
          </member>
          <member>
            <name>tax_id</name>
            <value>
              <struct>
                <member>
                  <name>Item1</name>
                  <value>
                    <i4>6</i4>
                  </value>
                </member>
                <member>
                  <name>Item2</name>
                  <value>
                    <i4>0</i4>
                  </value>
                </member>
                <member>
                  <name>Item3</name>
                  <value>
                    <array>
                      <data>
                        <value>
                          <i4>1</i4>
                        </value>
                      </data>
                    </array>
                  </value>
                </member>
              </struct>
            </value>
          </member>
        </struct>
      </value>
    </param>
  </params>
</methodCall>


 

I have never worked with that extension, nor is my C# knowledge any good, so I'm afraid I can't help you any further. You could simply try the value I mentioned earlier in my example (something like [(6,0,[1])] and see if that gets accepted. Otherwise I don't know.

Ludo - Neobis
on 10/8/14, 11:26 AM

maybe you try to explain me this array : [(6,0,my_tax_ids)] what's the meaning of 6 and 0 - the taxid is clear I can use the default id=1, it seams to be a multidimensional array!

Marc Wagener
on 10/8/14, 11:35 AM

I sincerely wish I could. There was an explanation in the docs once (doc.odoo.com) but I'm unable to find it now. The 6 stood for insert, and there were numbers before that should for appending, deleting, etc. . It never made much sense to me, but I knew how to use it in previous Odoo versions.

Ludo - Neobis
on 10/9/14, 9:45 AM

I found the following information about these many2many fields, but it still doesn't work. I don't know if I have a syntax-problem, or if there is a server-side problem. I'm rying different ways to generate the correct xml: 1) working with tuples var _tax = new Tuple> (6,0, new Tuple(1)); var neworderline = new OrderLine(); neworderline.productid = 19; neworderline.taxId = _tax; 2) working with jagged array index error: int[][] _jaggedTaxArray = { new int[] {6,0}, new int[] {1} }; 3) other int[][,] jaggedArray4 = new int[2][,] { new int[,] { {6},{0} }, new int[,] { {1} } }; For a many2many field, a list of tuples is expected. Here is the list of tuple that are accepted, with the corresponding semantics (0, 0, { values }) link to a new record that needs to be created with the given values dictionary (1, ID, { values }) update the linked record with id = ID (write *values* on it) (2, ID) remove and delete the linked record with id = ID (calls unlink on ID, that will delete the object completely, and the link to it as well) (3, ID) cut the link to the linked record with id = ID (delete the relationship between the two objects but does not delete the target object itself) (4, ID) link to existing record with id = ID (adds a relationship) (5) unlink all (like using (3,ID) for all linked records) (6, 0, [IDs]) replace the list of linked IDs (like using (5) then (4,ID) for each ID in the list of IDs) Example: [(6, 0, [8, 5, 6, 4])] sets the many2many to ids [8, 5, 6, 4] For a one2many field, a lits of tuples is expected. Here is the list of tuple that are accepted, with the corresponding semantics (0, 0, { values }) link to a new record that needs to be created with the given values dictionary (1, ID, { values }) update the linked record with id = ID (write *values* on it) (2, ID) remove and delete the linked record with id = ID (calls unlink on ID, that will delete the object completely, and the link to it as well) Example: [(0, 0, {'field_name':field_value_record1, ...}), (0, 0, {'field_name':field_value_record2, ...})] For a many2one field, simply use the ID of target record, which must already exist, or False to remove the link. For a reference field, use a string with the model name, a comma, and the target object id (example: 'product.product, 5')

Marc Wagener
on 10/10/14, 4:15 AM
0

Ludo - Neobis

--Ludo - Neobis--
2387
| 2 2 5
Hoogvliet, Netherlands
--Ludo - Neobis--

Developer

Ludo - Neobis
On 10/8/14, 7:14 AM

No clue about your current implementation, but if you're using the (XML/JSON)RPC connection you might want to call an on_change method on the object.

Because taxes are configured per product, when creating the sale order line the taxes are automatically provided upon selecting the product. So, calling on_change_product_id (or something similair) should provide you with the right taxes based on the product. 

Otherwise, when not using the product, you can go for the method of input using a tuple of 2 defined settings and the ids. This will result in a value like this: [(6,0,my_tax_ids)]. Again, this is from the top of my head, so you need to verify in code if this works.

 

In general: I hope you are not working outside of the ORM methods. It is highly inadvisable to do so. You will miss certain object workflows like that.

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: 10/8/14, 6:44 AM
Seen: 1728 times
Last updated: 3/16/15, 8:10 AM