Skip to content

Commit

Permalink
[FIX] pos_order_to_sale_order: Module flow is updated.
Browse files Browse the repository at this point in the history
  • Loading branch information
geomer198 committed Oct 19, 2023
1 parent c5673c1 commit a96796a
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 34 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",
)
28 changes: 14 additions & 14 deletions pos_order_to_sale_order/models/sale_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +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, fields, models
from odoo import api, 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):
return {
vals = {
"product_id": order_line_data["product_id"],
"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"),
}
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
42 changes: 22 additions & 20 deletions pos_order_to_sale_order/tests/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,32 +42,34 @@ def test_pos_order_to_sale_order(self):
self.assertEqual(order.delivery_status, "full")
self.assertEqual(order.invoice_status, "invoiced")

def test_sale_order_line_compute_name(self):
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"}
)

self.so = self.env["sale.order"].create(
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(
{
"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",
},
)
],
"product_id": self.product.id,
"qrt": 100,
"discount": 0,
"price_unit": 14.2,
"customer_note": "Test Note",
}
)
self.assertIn(
"Customer Note",
self.so.order_line.name,
msg="'Customer Note' string must be contains in name field",
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,
"qrt": 100,
"discount": 0,
"price_unit": 14.2,
"customer_note": "Test Note",
}
)
self.assertIn("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 a96796a

Please sign in to comment.