Commit 1d83c96f by François C.

Fix wrong PO name displayed in Orders helper after PO has been created

parent e29e6648
Pipeline #2478 passed with stage
in 1 minute 29 seconds
...@@ -238,69 +238,76 @@ class Order(models.Model): ...@@ -238,69 +238,76 @@ class Order(models.Model):
@staticmethod @staticmethod
def create(supplier_id, date_planned, order_lines): def create(supplier_id, date_planned, order_lines):
order_data = { res = {}
"partner_id": int(supplier_id), try:
"partner_ref": False, order_data = {
"currency_id": 1, "partner_id": int(supplier_id),
"date_order": datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"), "partner_ref": False,
"origin": "Aide à la commande", "currency_id": 1,
"company_id": 1, "date_order": datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
"order_line": [], "origin": "Aide à la commande",
"notes": False, "company_id": 1,
"date_planned": date_planned, "order_line": [],
"picking_type_id": 1, "notes": False,
"dest_address_id": False, "date_planned": date_planned,
"incoterm_id": False, "picking_type_id": 1,
"payment_term_id": False, "dest_address_id": False,
"fiscal_position_id": False, "incoterm_id": False,
"message_follower_ids": False, "payment_term_id": False,
"message_ids": False "fiscal_position_id": False,
} "message_follower_ids": False,
"message_ids": False
for line in order_lines: }
product_line_name = line["name"]
if "product_code" in line and line["product_code"] is not False: for line in order_lines:
product_code = str(line["product_code"]) product_line_name = line["name"]
product_line_name = "[" + product_code + "] " + product_line_name if "product_code" in line and line["product_code"] is not False:
product_code = str(line["product_code"])
order_data["order_line"].append( product_line_name = "[" + product_code + "] " + product_line_name
[
0, order_data["order_line"].append(
False, [
{ 0,
"package_qty": line["package_qty"], False,
"price_policy": "uom", {
"indicative_package": True, "package_qty": line["package_qty"],
"product_id": line["product_variant_ids"][0], "price_policy": "uom",
"name": product_line_name, "indicative_package": True,
"date_planned": date_planned, "product_id": line["product_variant_ids"][0],
"account_analytic_id": False, "name": product_line_name,
"product_qty_package":line["product_qty_package"], "date_planned": date_planned,
"product_qty": line["product_qty"], "account_analytic_id": False,
"product_uom": line["product_uom"], "product_qty_package":line["product_qty_package"],
"price_unit": line["price_unit"], "product_qty": line["product_qty"],
"discount": 0, "product_uom": line["product_uom"],
"taxes_id": [ "price_unit": line["price_unit"],
[ "discount": 0,
6, "taxes_id": [
False, [
line["supplier_taxes_id"] 6,
False,
line["supplier_taxes_id"]
]
] ]
] }
} ]
] )
)
api = OdooAPI() api = OdooAPI()
id_po = api.create('purchase.order', order_data) id_po = api.create('purchase.order', order_data)
res_confirm = api.execute('purchase.order', 'button_confirm', [id_po]) res_confirm = api.execute('purchase.order', 'button_confirm', [id_po])
res_for_name = api.search_read('purchase.order', [['id', '=', int(id_po)]], ['display_name'])
res = {
'id_po': id_po, res = {
'confirm_po': True, 'id_po': id_po,
'supplier_id': supplier_id, 'display_name': res_for_name[0]['display_name'],
'date_planned': date_planned 'confirm_po': True,
} 'supplier_id': supplier_id,
'date_planned': date_planned
}
except Exception as e:
res = {'error': str(e)}
coop_logger.error("Error while creating PO : %s (order_data = %s order_lines = %s)", str(e), str(order_data), str(order_lines))
return res return res
......
...@@ -1344,7 +1344,7 @@ function create_orders() { ...@@ -1344,7 +1344,7 @@ function create_orders() {
let new_order_template = $("#templates #new_order_item_template"); let new_order_template = $("#templates #new_order_item_template");
new_order_template.find(".new_order_supplier_name").text(supplier_name); new_order_template.find(".new_order_supplier_name").text(supplier_name);
new_order_template.find(".new_order_po").text(`PO${new_order.id_po}`); new_order_template.find(".new_order_po").text(`${new_order.display_name}`);
new_order_template.find(".new_order_date_planned").text(`Date de livraison prévue: ${date_planned}`); new_order_template.find(".new_order_date_planned").text(`Date de livraison prévue: ${date_planned}`);
new_order_template.find(".download_order_file_button").attr('id', `download_attachment_${new_order.id_po}`); new_order_template.find(".download_order_file_button").attr('id', `download_attachment_${new_order.id_po}`);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment