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 20, 2023
1 parent 2f827c1 commit 0188833
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 7 deletions.
10 changes: 10 additions & 0 deletions pos_order_to_sale_order/models/res_config_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,13 @@ class ResConfigSettings(models.TransientModel):
pos_iface_create_invoiced_sale_order = fields.Boolean(
related="pos_config_id.iface_create_invoiced_sale_order", readonly=False
)

sol_name_mode = fields.Selection(
selection=[
("product_pos", "Product name + POS Comment"),
("multiline", "Sale Multiline Description"),
],
string="SO Line Name Mode",
default="product_pos",
config_parameter="pos_order_to_sale_order.sol_name_mode",
)
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 @@ -10,16 +10,22 @@ class SaleOrderLine(models.Model):

@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 {
vals = {
"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"],
}
if (
order_line_data.get("customer_note")
and self.env["ir.config_parameter"]
.sudo()
.get_param("pos_order_to_sale_order.sol_name_mode", "product_pos")
== "product_pos"
):
product = self.env["product.product"].browse(order_line_data["product_id"])
product_name = product.name
product_name += "\n" + order_line_data["customer_note"]
vals.update(name=product_name)
return vals
1 change: 1 addition & 0 deletions pos_order_to_sale_order/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
* Go to Point Of Sale / Configuration / Point of Sale
* Check the box 'Create Sale Orders'
* Select the desired default behaviour
* Select the SO Line Name mode

.. figure:: ../static/description/res_config_settings_form.png
:width: 800 px
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.
34 changes: 34 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,37 @@ 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_prepare_from_pos(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"}
)

ICPSudo = self.env["ir.config_parameter"].sudo()
ICPSudo.set_param("pos_order_to_sale_order.sol_name_mode", "product_pos")
vals = self.env["sale.order.line"]._prepare_from_pos(
{
"product_id": self.product.id,
"qty": 100,
"discount": 0,
"price_unit": 14.2,
"customer_note": "Test Note",
"tax_ids": False,
}
)
self.assertEqual(
vals.get("name"), "Test Product\nTest Note", msg="Name must be the same"
)
ICPSudo.set_param("pos_order_to_sale_order.sol_name_mode", "multiline")
vals = self.env["sale.order.line"]._prepare_from_pos(
{
"product_id": self.product.id,
"qty": 100,
"discount": 0,
"price_unit": 14.2,
"customer_note": "Test Note",
"tax_ids": False,
}
)
self.assertNotIn("name", vals.keys(), msg="Name key must be contain in dict")
13 changes: 13 additions & 0 deletions pos_order_to_sale_order/views/view_res_config_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@
<label for="pos_iface_create_invoiced_sale_order" />
</div>
</div>

<div class="col-12 col-lg-6 o_setting_box">
<div class="o_setting_left_pane" />
<div class="o_setting_right_pane">
<label for="sol_name_mode" />
<div class="text-muted">
Sales Order Line Name Composition Mode
</div>
<div class="content-group mt16">
<field name="sol_name_mode" />
</div>
</div>
</div>
</div>
</xpath>
</field>
Expand Down

0 comments on commit 0188833

Please sign in to comment.