diff --git a/pos_order_to_sale_order/models/sale_order.py b/pos_order_to_sale_order/models/sale_order.py index 91295a425d..17dedff121 100644 --- a/pos_order_to_sale_order/models/sale_order.py +++ b/pos_order_to_sale_order/models/sale_order.py @@ -2,7 +2,7 @@ # @author: Sylvain LE GAL (https://twitter.com/legalsylvain) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from odoo import _, api, models +from odoo import Command, _, api, models class SaleOrder(models.Model): @@ -12,6 +12,11 @@ class SaleOrder(models.Model): 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"] + order_lines = [ + Command.create(SaleOrderLine._prepare_from_pos(line[2])) + for line in order_data["lines"] + ] return { "partner_id": order_data["partner_id"], "origin": _("Point of Sale %s") % (session.name), @@ -19,24 +24,15 @@ def _prepare_from_pos(self, order_data): "user_id": order_data["user_id"], "pricelist_id": order_data["pricelist_id"], "fiscal_position_id": order_data["fiscal_position_id"], + "order_lines": order_lines, } @api.model def create_order_from_pos(self, order_data, action): - SaleOrderLine = self.env["sale.order.line"] - # Create Draft Sale order order_vals = self._prepare_from_pos(order_data) sale_order = self.create(order_vals) - # create Sale order lines - for order_line_data in order_data["lines"]: - # Create Sale order lines - order_line_vals = SaleOrderLine._prepare_from_pos( - sale_order, order_line_data[2] - ) - SaleOrderLine.create(order_line_vals) - # Confirm Sale Order if action in ["confirmed", "delivered", "invoiced"]: sale_order.action_confirm() 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 db24df03e9..157f2badc0 100644 --- a/pos_order_to_sale_order/models/sale_order_line.py +++ b/pos_order_to_sale_order/models/sale_order_line.py @@ -9,14 +9,13 @@ class SaleOrderLine(models.Model): _inherit = "sale.order.line" @api.model - def _prepare_from_pos(self, sale_order, order_line_data): + 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"] return { - "order_id": sale_order.id, "product_id": order_line_data["product_id"], "name": product_name, "product_uom_qty": order_line_data["qty"],