From 1d776c694ca978c2bf50dc26b790d5448f5ed8e8 Mon Sep 17 00:00:00 2001 From: victorvermot Date: Mon, 7 Oct 2024 16:17:06 +0200 Subject: [PATCH] [17.0][ADD]: Improve pos_order_to_sale_order --- pos_order_to_sale_order/models/sale_order.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/pos_order_to_sale_order/models/sale_order.py b/pos_order_to_sale_order/models/sale_order.py index 162d20898a..d82f6c89a9 100644 --- a/pos_order_to_sale_order/models/sale_order.py +++ b/pos_order_to_sale_order/models/sale_order.py @@ -13,6 +13,14 @@ def _prepare_from_pos(self, order_data): PosSession = self.env["pos.session"] session = PosSession.browse(order_data["pos_session_id"]) SaleOrderLine = self.env["sale.order.line"] + partner_pricelist = ( + order_data["pricelist_id"] + if order_data["pricelist_id"] + else self.env["res.partner"] + .browse(order_data["partner_id"]) + .property_product_pricelist.id + ) + self.pricelist_id = partner_pricelist order_lines = [ Command.create(SaleOrderLine._prepare_from_pos(sequence, line_data[2])) for sequence, line_data in enumerate(order_data["lines"], start=1) @@ -22,7 +30,7 @@ def _prepare_from_pos(self, order_data): "origin": _("Point of Sale %s") % (session.name), "client_order_ref": order_data["name"], "user_id": order_data["user_id"], - "pricelist_id": order_data["pricelist_id"], + "pricelist_id": partner_pricelist, "fiscal_position_id": order_data["fiscal_position_id"], "order_line": order_lines, } @@ -31,9 +39,15 @@ def _prepare_from_pos(self, order_data): def create_order_from_pos(self, order_data, action): # Create Draft Sale order order_vals = self._prepare_from_pos(order_data) + partner_lang = self.env["res.partner"].browse(order_vals["partner_id"]).lang sale_order = self.with_context( - pos_order_lines_data=[x[2] for x in order_data.get("lines", [])] + pos_order_lines_data=[x[2] for x in order_data.get("lines", [])], + lang=partner_lang, ).create(order_vals) + for line in sale_order.order_line: + line._compute_discount() + line._compute_price_unit() + line._compute_tax_id() # Confirm Sale Order if action in ["confirmed", "delivered", "invoiced"]: