Skip to content

Commit

Permalink
Merge PR #1080 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by legalsylvain
  • Loading branch information
OCA-git-bot committed Nov 24, 2023
2 parents e27b77a + 85cd913 commit 81442c8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
8 changes: 5 additions & 3 deletions pos_order_to_sale_order/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand All @@ -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"]:
Expand Down
20 changes: 13 additions & 7 deletions pos_order_to_sale_order/models/sale_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 81442c8

Please sign in to comment.