From 34b6776ccc9cbf3726649b7063e0b7ffd618baa7 Mon Sep 17 00:00:00 2001 From: Edilio Daciel Escalona Almira Date: Wed, 27 Nov 2024 20:41:00 -0500 Subject: [PATCH] [MIG] rental_pricelist: Migration to 17.0 --- rental_pricelist/__manifest__.py | 2 +- rental_pricelist/hooks.py | 6 +--- rental_pricelist/models/product.py | 33 +++++-------------- rental_pricelist/models/sale_order_line.py | 10 +++--- .../tests/test_rental_pricelist.py | 5 ++- rental_pricelist/views/product_view.xml | 30 ++++++----------- rental_pricelist/views/res_company_view.xml | 1 - rental_pricelist/views/sale_view.xml | 1 - 8 files changed, 27 insertions(+), 61 deletions(-) diff --git a/rental_pricelist/__manifest__.py b/rental_pricelist/__manifest__.py index bf912a89..2012855d 100644 --- a/rental_pricelist/__manifest__.py +++ b/rental_pricelist/__manifest__.py @@ -4,7 +4,7 @@ "name": "Rental Pricelist", "summary": "Enables the user to define different rental prices with " "time uom (Month, Day and Hour).", - "version": "16.0.1.0.1", + "version": "17.0.1.0.0", "category": "Rental", "author": "elego Software Solutions GmbH, Odoo Community Association (OCA)", "website": "https://github.com/OCA/vertical-rental", diff --git a/rental_pricelist/hooks.py b/rental_pricelist/hooks.py index 6de85953..771d767f 100644 --- a/rental_pricelist/hooks.py +++ b/rental_pricelist/hooks.py @@ -1,11 +1,7 @@ # Part of rental-vertical See LICENSE file for full copyright and licensing details. -from odoo import SUPERUSER_ID -from odoo.api import Environment - -def set_multi_sales_price(cr, registry): - env = Environment(cr, SUPERUSER_ID, {}) +def set_multi_sales_price(env): conf_page = env["res.config.settings"].create({}) conf_page.group_uom = True conf_page.group_product_pricelist = True diff --git a/rental_pricelist/models/product.py b/rental_pricelist/models/product.py index 6a831b03..1ed2051a 100644 --- a/rental_pricelist/models/product.py +++ b/rental_pricelist/models/product.py @@ -7,10 +7,6 @@ class ProductProduct(models.Model): _inherit = "product.product" - def _default_pricelist(self): - # TODO change default pricelist if country group exist - return self.env.ref("product.list0").id - rental_of_month = fields.Boolean( string="Rented in months", copy=False, @@ -95,7 +91,6 @@ def _default_pricelist(self): def_pricelist_id = fields.Many2one( comodel_name="product.pricelist", string="Default Pricelist", - default=lambda self: self._default_pricelist(), ) # override from sale_rental, to remove Uom constrain @@ -120,11 +115,7 @@ def _check_rental(self): @api.model def _get_rental_service_prefix_suffix(self, field, str_type, rental_type): - field_name = "rental_service_%(field)s_%(str_type)s_%(rental_type)s" % { - "field": field, - "str_type": str_type, - "rental_type": rental_type, - } + field_name = f"rental_service_{field}_{str_type}_{rental_type}" res = getattr(self.env.user.company_id, field_name) return res @@ -186,9 +177,9 @@ def _get_rental_service_name(self, rental_type, sp_name): suffix = self._get_rental_service_prefix_suffix("name", "suffix", rental_type) name = sp_name if prefix: - name = "%(prefix)s %(name)s" % {"prefix": prefix, "name": name} + name = f"{prefix} {name}" if suffix: - name = "%(name)s %(suffix)s" % {"name": name, "suffix": suffix} + name = f"{name} {suffix}" return name def _get_rental_service_default_code(self, rental_type, sp_code): @@ -202,15 +193,9 @@ def _get_rental_service_default_code(self, rental_type, sp_code): default_code = sp_code if default_code: if prefix: - default_code = "%(prefix)s-%(default_code)s" % { - "prefix": prefix, - "default_code": default_code, - } + default_code = f"{prefix}-{default_code}" if suffix: - default_code = "%(default_code)s-%(suffix)s" % { - "default_code": default_code, - "suffix": suffix, - } + default_code = f"{default_code}-{suffix}" else: default_code = "" return default_code @@ -220,12 +205,10 @@ def _create_rental_service(self, rental_type, product, price=0): uom = self._get_rental_service_uom(rental_type) values = { "hw_product_id": product.id, - "name": _("Rental of %(product_name)s (%(uom_name)s)") - % {"product_name": product.name, "uom_name": uom.name}, + "name": _(f"Rental of {product.name} ({uom.name})"), "categ_id": product.categ_id.id, "copy_image": True, - "default_code": "RENT-%(rental)s-%(code)s" - % {"rental": rental_type.upper(), "code": product.default_code}, + "default_code": f"RENT-{rental_type.upper()}-{product.default_code}", } res = ( self.env["create.rental.product"] @@ -312,7 +295,7 @@ def _update_rental_service_fields(self, vals, fields, rental_services): self.rental_service_ids.write(service_vals) def write(self, vals): - res = super(ProductProduct, self).write(vals) + res = super().write(vals) for p in self: # Create service product automatically if vals.get("rental_of_month", False): diff --git a/rental_pricelist/models/sale_order_line.py b/rental_pricelist/models/sale_order_line.py index bcd2e336..8b6d9987 100644 --- a/rental_pricelist/models/sale_order_line.py +++ b/rental_pricelist/models/sale_order_line.py @@ -56,7 +56,6 @@ def _set_product_id(self): else: self.rental = False self.product_id = self.display_product_id - # raise exceptions.UserError(_('The product has no related rental services.')) elif not self.rental and self.display_product_id: self.product_id = self.display_product_id @@ -121,7 +120,8 @@ def _check_rental_availability(self): "title": _("Not enough stock!"), "message": _( "You want to rent %(rental_qty).2f %(rental_uom)s but you only " - "have %(available_qty).2f %(rental_uom)s currently available on the " + "have %(available_qty).2f %(rental_uom)s currently available " + "on the " 'stock location "%(rental_name)s"! Make sure that you ' "get some units back in the meantime or " 're-supply the stock location "%(rental_name)s".' @@ -194,9 +194,9 @@ def _check_sale_line_rental(self): _( "On the sale order line with rental service %(name)s, " "you are trying to extend a rental with a rental " - "quantity (%(rental_qty)s) that is different from the quantity " - "of the original rental (%(ext_rental_qty)s). " - "This is not supported." + "quantity (%(rental_qty)s) that is different from " + "the quantity of the original rental " + "(%(ext_rental_qty)s). This is not supported." ) % { "name": line.product_id.name, diff --git a/rental_pricelist/tests/test_rental_pricelist.py b/rental_pricelist/tests/test_rental_pricelist.py index 4ee51fe2..f64baf30 100644 --- a/rental_pricelist/tests/test_rental_pricelist.py +++ b/rental_pricelist/tests/test_rental_pricelist.py @@ -152,7 +152,6 @@ def setUp(self): .create( { "partner_id": self.partnerA.id, - "pricelist_id": self.env.ref("product.list0").id, } ) ) @@ -484,7 +483,8 @@ def test_05_check_rental_productE(self): with self.assertRaises(ValidationError) as e: rental_serviceE.type = "consu" self.assertEqual( - "The rental product 'Rental of Product E (Day(s))' must be of type 'Service'.", + "The rental product 'Rental of Product E (Day(s))' must be " + "of type 'Service'.", str(e.exception), ) with self.assertRaises(ValidationError) as e: @@ -547,7 +547,6 @@ def test_06_check_start_end_dates_productF(self): .create( { "partner_id": self.partnerA.id, - "pricelist_id": self.env.ref("product.list0").id, } ) ) diff --git a/rental_pricelist/views/product_view.xml b/rental_pricelist/views/product_view.xml index ebc15163..a4f6cafa 100644 --- a/rental_pricelist/views/product_view.xml +++ b/rental_pricelist/views/product_view.xml @@ -1,4 +1,3 @@ - @@ -12,7 +11,7 @@ @@ -20,17 +19,14 @@ - + Bulk Prices @@ -67,17 +63,14 @@ - + Bulk Prices @@ -114,17 +107,14 @@ - + Bulk Prices diff --git a/rental_pricelist/views/res_company_view.xml b/rental_pricelist/views/res_company_view.xml index d71dfbbc..038c4c38 100644 --- a/rental_pricelist/views/res_company_view.xml +++ b/rental_pricelist/views/res_company_view.xml @@ -1,4 +1,3 @@ - res.company.form diff --git a/rental_pricelist/views/sale_view.xml b/rental_pricelist/views/sale_view.xml index 5a6dad05..7c9225f5 100644 --- a/rental_pricelist/views/sale_view.xml +++ b/rental_pricelist/views/sale_view.xml @@ -1,4 +1,3 @@ -