Skip to content

Commit

Permalink
[IMP] pos_order_to_sale_order : performance : directly overload _get_…
Browse files Browse the repository at this point in the history
…sale_order_line_multiline_description_sale to avoid to write on sale.order.line after having creating the sale.order.line
  • Loading branch information
legalsylvain committed Nov 10, 2023
1 parent 2b18895 commit 85cd913
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
15 changes: 3 additions & 12 deletions pos_order_to_sale_order/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +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)

for (i, line_data) in enumerate(order_data["lines"]):
if line_data[2].get("customer_note", False):
order_line = sale_order.order_line.filtered(
lambda x: x.sequence == i + 1
)
order_line.write(
{
"name": f"{order_line.name}\n{line_data[2].get('customer_note', False)}"
}
)
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
11 changes: 11 additions & 0 deletions pos_order_to_sale_order/models/sale_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,14 @@ def _prepare_from_pos(self, sequence, order_line_data):
"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")

Check warning on line 29 in pos_order_to_sale_order/models/sale_order_line.py

View check run for this annotation

Codecov / codecov/patch

pos_order_to_sale_order/models/sale_order_line.py#L29

Added line #L29 was not covered by tests

return res

0 comments on commit 85cd913

Please sign in to comment.