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

[16.0][FIX] pos_order_to_sale_order #1065

Closed
Closed
Show file tree
Hide file tree
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
20 changes: 19 additions & 1 deletion pos_order_to_sale_order/models/res_config_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import fields, models
from odoo import api, fields, models


class ResConfigSettings(models.TransientModel):
Expand All @@ -23,3 +23,21 @@ 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",
Copy link
Member

Choose a reason for hiding this comment

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

What happens if user will remove selection value? So no option is selected

config_parameter="pos_order_to_sale_order.sol_name_mode",
)

@api.model
def set_values(self):
result = super(ResConfigSettings, self).set_values()
ICPSudo = self.env["ir.config_parameter"].sudo()
value = self.sol_name_mode or "product_pos"
ICPSudo.set_param("pos_order_to_sale_order.sol_name_mode", value)
return result
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
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe I'm wrong, but it looks like if the previous condition is wrong, the vals returned doesn't contain any "name" value. Did I missed something ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe I'm wrong, but it looks like if the previous condition is wrong, the vals returned doesn't contain any "name" value. Did I missed something ?

Thank you for you question!
Name field is auto complete after creating SOL. And this solution for the set custom value for SOL description.

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 Sales Order Line name composition mode

.. figure:: ../static/description/res_config_settings_form.png
:width: 800 px
Empty file.
5 changes: 5 additions & 0 deletions pos_order_to_sale_order/readme/newsfragments/2928.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
In Settings "Sales Order Line name composition mode" is added.
This mode regulates preparing sale order line description at creating Sale Order from Point of Sale.
Modes:
- Product name + POS Comment
- Sale Multiline Description
58 changes: 57 additions & 1 deletion pos_order_to_sale_order/tests/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html


from odoo.tests import tagged
from odoo.tests import Form, tagged

from odoo.addons.point_of_sale.tests.test_frontend import TestPointOfSaleHttpCommon

Expand Down Expand Up @@ -41,3 +41,59 @@ 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")

def test_config_settings_sol_name_mode(self):
Settings = self.env["res.config.settings"].with_user(self.env.user).create({})
with Form(Settings) as form:
form.sol_name_mode = "product_pos"
Settings.set_values()
Config = self.env["ir.config_parameter"].sudo()
self.assertEqual(
Config.get_param("pos_order_to_sale_order.sol_name_mode"), "product_pos"
)
with Form(Settings) as form:
form.sol_name_mode = "multiline"
Settings.set_values()
self.assertEqual(
Config.get_param("pos_order_to_sale_order.sol_name_mode"), "multiline"
)
with Form(Settings) as form:
form.sol_name_mode = False
Settings.set_values()
self.assertEqual(
Config.get_param("pos_order_to_sale_order.sol_name_mode"), "product_pos"
)
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
Loading