I want to add Purchase orders with my software, using the Odoo API. Adding the purchase order works fine, but adding lines throws an exception.
-I have made sure all variables with "required" tags are included.
-If I add an order through the web page, and try to add lines to that one (with the API); results in the same error.
It's written in c#, Odoo version is 13.0
Code:
int orderId = -1;
{
var properties = new
{
company_id = 1,
currency_id = 1,
date_order = "2020-09-28 08:00:08",
name = "P00012",
partner_id = 7,
picking_type_id = 1
};
orderId = (int)model.execute_kw(DB, userId, password, "purchase.order", "create", new object[] { properties });
Console.WriteLine("New order: " + orderId);
}
{
var properties = new
{
order_id = orderId,
product_id = 7,
//product_uom = 5757,
name = "Tavla",
product_uom = 1,//Units of measure, is pointer with id
product_uom_qty = 1,
price_unit = 1.5,
price_total = 1.5,
product_qty = 1.0,
};
//The project crashes here:
var res = model.execute_kw(DB, userId, password, "purchase.order.line", "create", new object[] { properties });
Console.WriteLine("New order line: " + res);
}
Error message:
psycopg2.IntegrityError: new row for relation "purchase_order_line" violates check constraint "purchase_order_line_accountable_required_fields"DETAIL: Failing row contains (17, Tavla, 10, 1.000, 1, null, 1, 7, 1.50, null, 1.5, null, 3, null, null, null, null, null, null, null, null, null, null, 2, 2020-09-29 06:29:11.019109, 2, 2020-09-29 06:29:11.019109, null, null, null, t, null, null).During handling of the above exception, another exception occurred: File "/opt/bitnami/apps/odoo/lib/odoo-13.0.post20200815-py3.7.egg/odoo/service/model.py", line 116, in wrapper raise ValidationError(tr(key, 'sql_constraint') or inst.pgerror)odoo.exceptions.ValidationError: ('purchase_order_line_accountable_required_fields', None)