diff --git a/pos_order_to_sale_order/models/sale_order.py b/pos_order_to_sale_order/models/sale_order.py index be32ace84d..54768e6ab5 100644 --- a/pos_order_to_sale_order/models/sale_order.py +++ b/pos_order_to_sale_order/models/sale_order.py @@ -14,8 +14,8 @@ def _prepare_from_pos(self, order_data): session = PosSession.browse(order_data["pos_session_id"]) SaleOrderLine = self.env["sale.order.line"] order_lines = [ - Command.create(SaleOrderLine._prepare_from_pos(line[2])) - for line in order_data["lines"] + Command.create(SaleOrderLine._prepare_from_pos(i + 1, line_data[2])) + for (i, line_data) in enumerate(order_data["lines"]) ] return { "partner_id": order_data["partner_id"], @@ -31,7 +31,9 @@ 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) - sale_order = self.create(order_vals) + sale_order = self.with_context( + pos_order_lines_data=[x[2] for x in order_data.get("lines", [])] + ).create(order_vals) # Confirm Sale Order if action in ["confirmed", "delivered", "invoiced"]: diff --git a/pos_order_to_sale_order/models/sale_order_line.py b/pos_order_to_sale_order/models/sale_order_line.py index 157f2badc0..3a4ec24fc9 100644 --- a/pos_order_to_sale_order/models/sale_order_line.py +++ b/pos_order_to_sale_order/models/sale_order_line.py @@ -9,17 +9,23 @@ class SaleOrderLine(models.Model): _inherit = "sale.order.line" @api.model - def _prepare_from_pos(self, order_line_data): - ProductProduct = self.env["product.product"] - product = ProductProduct.browse(order_line_data["product_id"]) - product_name = product.name - if order_line_data.get("customer_note"): - product_name += "\n" + order_line_data["customer_note"] + def _prepare_from_pos(self, sequence, order_line_data): return { + "sequence": sequence, "product_id": order_line_data["product_id"], - "name": product_name, "product_uom_qty": order_line_data["qty"], "discount": order_line_data["discount"], "price_unit": order_line_data["price_unit"], "tax_id": order_line_data["tax_ids"], } + + def _get_sale_order_line_multiline_description_sale(self): + res = super()._get_sale_order_line_multiline_description_sale() + + for (i, line_data) in enumerate( + self.env.context.get("pos_order_lines_data", []) + ): + if line_data.get("customer_note", False) and self.sequence == i + 1: + res += "\n" + line_data.get("customer_note") + + return res