From 319a88e318318959dd59b4401b0b626c3f35de31 Mon Sep 17 00:00:00 2001 From: Antonio Buric Date: Mon, 8 Jul 2024 23:54:26 +0200 Subject: [PATCH] [MIG] sale_order_import: Migration to 17.0 --- sale_order_import/__manifest__.py | 2 +- sale_order_import/models/sale.py | 20 ++++++++----------- sale_order_import/tests/test_sale_order.py | 12 +++++++---- sale_order_import/wizard/sale_order_import.py | 19 +++++++----------- .../wizard/sale_order_import_view.xml | 19 +++++++++--------- 5 files changed, 34 insertions(+), 38 deletions(-) diff --git a/sale_order_import/__manifest__.py b/sale_order_import/__manifest__.py index fef8e7da2d..5ab1f7bf32 100644 --- a/sale_order_import/__manifest__.py +++ b/sale_order_import/__manifest__.py @@ -3,7 +3,7 @@ { "name": "Sale Order Import", - "version": "16.0.1.2.0", + "version": "17.0.1.0.0", "category": "Sales Management", "license": "AGPL-3", "summary": "Import RFQ or sale orders from files", diff --git a/sale_order_import/models/sale.py b/sale_order_import/models/sale.py index ca43a8d9c8..d411f5c872 100644 --- a/sale_order_import/models/sale.py +++ b/sale_order_import/models/sale.py @@ -7,21 +7,17 @@ class SaleOrder(models.Model): _inherit = "sale.order" - def name_get(self): + def _compute_display_name(self): """Add amount_untaxed in name_get of sale orders""" - res = super().name_get() + res = super()._compute_display_name() if self._context.get("sale_order_show_amount"): - new_res = [] - for sale_id, name in res: - sale = self.browse(sale_id) + for order in self: # TODO: find a python method to easily display a float + currency # symbol (before or after) depending on lang of context and currency - name += _( + name = _( " Amount w/o tax: %(amount)s %(currency)s", - amount=sale.amount_untaxed, - currency=sale.currency_id.name, + amount=order.amount_untaxed, + currency=order.currency_id.name, ) - new_res.append((sale_id, name)) - return new_res - else: - return res + order.display_name = name + return res diff --git a/sale_order_import/tests/test_sale_order.py b/sale_order_import/tests/test_sale_order.py index b923e1d286..ff6203fb21 100644 --- a/sale_order_import/tests/test_sale_order.py +++ b/sale_order_import/tests/test_sale_order.py @@ -13,13 +13,17 @@ def setUpClass(cls): super().setUpClass() cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) - def test_name_get(self): + def test_display_name(self): sale_order = self.env.ref("sale.sale_order_1") name = sale_order.name + _( " Amount w/o tax: %(amount)s %(currency)s", amount=sale_order.amount_untaxed, currency=sale_order.currency_id.name, ) - so = self.env["sale.order"].with_context(sale_order_show_amount=True) - name_get_res = so.search([("id", "=", sale_order.id)]).name_get() - self.assertEqual(name, name_get_res[0][1]) + so = ( + self.env["sale.order"] + .with_context(sale_order_show_amount=True) + .browse(sale_order.id) + ) + so._compute_display_name() + self.assertEqual(name, so.display_name) diff --git a/sale_order_import/wizard/sale_order_import.py b/sale_order_import/wizard/sale_order_import.py index 7d7c2dc98f..f561d0b7e0 100644 --- a/sale_order_import/wizard/sale_order_import.py +++ b/sale_order_import/wizard/sale_order_import.py @@ -101,8 +101,8 @@ def _parse_file(self, filename, filecontent, detect_doc_type=False): type=self.import_type.upper(), ) ) - if hasattr(self, "parse_%s_order" % self.import_type): - return getattr(self, "parse_%s_order" % self.import_type)( + if hasattr(self, f"parse_{self.import_type}_order"): + return getattr(self, f"parse_{self.import_type}_order")( filecontent, detect_doc_type=detect_doc_type ) else: @@ -486,8 +486,9 @@ def _prepare_create_order_line( vals.pop("order_id") # Handle additional fields dynamically if available. - # This way, if you add a field to a record and it's value is injected by a parser - # you won't have to override `_prepare_create_order_line` to let it propagate. + # This way, if you add a field to a record + # and it's value is injected by a parser, you won't have to + # override `_prepare_create_order_line` to let it propagate. for k, v in import_line.items(): if k not in vals and k in solo._fields: vals[k] = v @@ -582,8 +583,7 @@ def update_order_lines(self, parsed_order, order, price_source): oline.write(write_vals) if compare_res["to_remove"]: to_remove_label = [ - "%s %s x %s" - % (line.product_uom_qty, line.product_uom.name, line.product_id.name) + f"{line.product_uom_qty} {line.product_uom.name} x {line.product_id.name}" # noqa for line in compare_res["to_remove"] ] chatter.append( @@ -603,12 +603,7 @@ def update_order_lines(self, parsed_order, order, price_source): line_vals["order_id"] = order.id new_line = solo.create(line_vals) to_create_label.append( - "%s %s x %s" - % ( - new_line.product_uom_qty, - new_line.product_uom.name, - new_line.name, - ) + f"{new_line.product_uom_qty} {new_line.product_uom.name} x {new_line.name}" # noqa ) chatter.append( _( diff --git a/sale_order_import/wizard/sale_order_import_view.xml b/sale_order_import/wizard/sale_order_import_view.xml index bf7e4b329c..f6ef5d470e 100644 --- a/sale_order_import/wizard/sale_order_import_view.xml +++ b/sale_order_import/wizard/sale_order_import_view.xml @@ -12,7 +12,7 @@ - +

Upload below the customer order or request for quotation as XML or PDF file. When you click on the Import button:

@@ -28,22 +28,22 @@
- +

Some quotations have been found for this customer ; one of them may correspond to the order or RFQ that you are importing. You can either select an existing quotation to update or create a new one.

- + - +