Skip to content

Commit

Permalink
[FIX] pos_order_to_sale_order: Sale order line create is changed.
Browse files Browse the repository at this point in the history
At creating SO from pos, description computed by default with adding customer note from POS.
  • Loading branch information
geomer198 committed Oct 15, 2023
1 parent 2f827c1 commit c5673c1
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 7 deletions.
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 @@ -2,24 +2,30 @@
# @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 api, fields, models


class SaleOrderLine(models.Model):
_inherit = "sale.order.line"

# POS Customer Note
customer_note = fields.Char()

@api.depends("product_id")
def _compute_name(self):
super(SaleOrderLine, self)._compute_name()
# Adding customer_note field in description, if customer_note field is existing
for rec in self.filtered("customer_note"):
rec.name += "\n%s" % rec.customer_note
return

@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"]
return {
"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"],
"customer_note": order_line_data.get("customer_note"),
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Sale order line description computed by default with adding Customer note.
30 changes: 30 additions & 0 deletions pos_order_to_sale_order/tests/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,33 @@ def test_pos_order_to_sale_order(self):
self.assertEqual(order.state, "sale")
self.assertEqual(order.delivery_status, "full")
self.assertEqual(order.invoice_status, "invoiced")

def test_sale_order_line_compute_name(self):
self.partner = self.env["res.partner"].create({"name": "Test Partner"})
self.product = self.env["product.product"].create(
{"name": "Test Product", "default_code": "test_01"}
)

self.so = self.env["sale.order"].create(
{
"partner_id": self.partner.id,
"origin": "Point of Sale",
"order_line": [
(
0,
0,
{
"product_id": self.product.id,
"product_uom_qty": 1.0,
"price_unit": 100.0,
"customer_note": "Customer Note",
},
)
],
}
)
self.assertIn(
"Customer Note",
self.so.order_line.name,
msg="'Customer Note' string must be contains in name field",
)

0 comments on commit c5673c1

Please sign in to comment.