Skip to content

Commit

Permalink
[17.0][ADD]: Improve pos_order_to_sale_order
Browse files Browse the repository at this point in the history
  • Loading branch information
victorvermot committed Oct 7, 2024
1 parent 3b99258 commit 6103b98
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions pos_order_to_sale_order/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
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)
Expand All @@ -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.id,
"fiscal_position_id": order_data["fiscal_position_id"],
"order_line": order_lines,
}
Expand All @@ -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"]:
Expand Down

0 comments on commit 6103b98

Please sign in to comment.