Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[17.0][ADD]: Improve pos_order_to_sale_order #1252

Open
wants to merge 1 commit into
base: 17.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.id
)
self.pricelist_id = partner_pricelist
Comment on lines +16 to +23
Copy link
Contributor

@legalsylvain legalsylvain Oct 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pricelist is selected on pos.order. Why the pricelist is not selected correctly in the point of sale ?

order_lines = [
Command.create(SaleOrderLine._prepare_from_pos(sequence, line_data[2]))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess adding lang context over there should made the work.

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,
"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
Loading