From 025a362c9a430cfb816e0af6147130e9a8ede065 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adasat=20Torres=20de=20Le=C3=B3n?= Date: Mon, 16 Sep 2024 15:13:11 +0100 Subject: [PATCH] [MIG]rental_pricelist: Migration to 16.0 --- rental_pricelist/README.rst | 82 ++++++++-- rental_pricelist/README/CONFIGURATION.rst | 4 - rental_pricelist/README/CONTRIBUTORS.rst | 4 - rental_pricelist/README/DESCRIPTION.rst | 9 -- rental_pricelist/README/HISTORY.rst | 4 - rental_pricelist/README/USAGE.rst | 4 - rental_pricelist/__manifest__.py | 2 +- rental_pricelist/models/__init__.py | 4 +- rental_pricelist/models/product.py | 46 +++--- .../models/product_pricelist_item.py | 5 +- rental_pricelist/models/sale_order.py | 20 +++ .../models/{sale.py => sale_order_line.py} | 145 +++++++----------- .../tests/test_rental_pricelist.py | 119 +++++--------- rental_pricelist/views/product_view.xml | 20 +-- 14 files changed, 226 insertions(+), 242 deletions(-) create mode 100644 rental_pricelist/models/sale_order.py rename rental_pricelist/models/{sale.py => sale_order_line.py} (67%) diff --git a/rental_pricelist/README.rst b/rental_pricelist/README.rst index 1ec12cac..3307ed1b 100644 --- a/rental_pricelist/README.rst +++ b/rental_pricelist/README.rst @@ -1,23 +1,48 @@ +================ Rental Pricelist -==================================================== +================ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:abb8d54f6920d71a4ca8c6ffe2552ecebbbca7f055e9029cc8ef05bc6d3779db + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fvertical--rental-lightgray.png?logo=github + :target: https://github.com/OCA/vertical-rental/tree/16.0/rental_pricelist + :alt: OCA/vertical-rental +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/vertical-rental-16-0/vertical-rental-16-0-rental_pricelist + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/vertical-rental&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| *This file has been generated on 2022-05-04-12-21-41. Changes to it will be overwritten.* -Summary -------- - Enables the user to define different rental prices with time uom (Month, Day and Hour). -Description ------------ - Rental prices are usually scaled prices based on a time unit, typically day, sometimes months or hour. This modules integrates the standard Odoo pricelists into rental use cases and allows the user an easy way to specify the prices in a product tab as well as to use all the enhanced pricelist features. +**Table of contents** + +.. contents:: + :local: Usage ------ +===== Create a rentable product: * Go to Rentals > Configuration > Settings. @@ -55,8 +80,47 @@ Create a rental order: Please also see the usage section of sale_rental and rental_base module. Changelog ---------- +========= - 8d191ff7 2022-04-10 15:41:16 +0200 wagner@elegosoft.com add missing/lost documentation (issue #4516) - 4509f78a 2022-02-23 20:48:33 +0100 wagner@elegosoft.com (origin/feature_4516_add_files_ported_from_v12_v14, feature_4516_add_files_ported_from_v12_v14) add files ported to v14 by cpatel and khanhbui (issue #4516) +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* elego Software Solutions GmbH + +Contributors +~~~~~~~~~~~~ + +elego Software Solutions GmbH, Odoo Community Association (OCA) + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/vertical-rental `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/rental_pricelist/README/CONFIGURATION.rst b/rental_pricelist/README/CONFIGURATION.rst index 0d373c35..cff41a13 100644 --- a/rental_pricelist/README/CONFIGURATION.rst +++ b/rental_pricelist/README/CONFIGURATION.rst @@ -1,7 +1,3 @@ - -Configuration -------------- - To configure this module, you need to: #. Go to company settings and define the default interval ranges on 'Rental Interval Prices' tab. diff --git a/rental_pricelist/README/CONTRIBUTORS.rst b/rental_pricelist/README/CONTRIBUTORS.rst index 0f2e7ff6..980305e1 100644 --- a/rental_pricelist/README/CONTRIBUTORS.rst +++ b/rental_pricelist/README/CONTRIBUTORS.rst @@ -1,5 +1 @@ - -Contributors ------------- - elego Software Solutions GmbH, Odoo Community Association (OCA) diff --git a/rental_pricelist/README/DESCRIPTION.rst b/rental_pricelist/README/DESCRIPTION.rst index ec93a970..4afffbf0 100644 --- a/rental_pricelist/README/DESCRIPTION.rst +++ b/rental_pricelist/README/DESCRIPTION.rst @@ -1,16 +1,7 @@ -Rental Pricelist -==================================================== - *This file has been generated on 2022-05-04-12-21-41. Changes to it will be overwritten.* -Summary -------- - Enables the user to define different rental prices with time uom (Month, Day and Hour). -Description ------------ - Rental prices are usually scaled prices based on a time unit, typically day, sometimes months or hour. This modules integrates the standard Odoo pricelists into rental use cases and allows the user an easy way to specify the prices in a product tab as well as to use all the enhanced pricelist features. diff --git a/rental_pricelist/README/HISTORY.rst b/rental_pricelist/README/HISTORY.rst index 8daf5fc7..0ffc209c 100644 --- a/rental_pricelist/README/HISTORY.rst +++ b/rental_pricelist/README/HISTORY.rst @@ -1,6 +1,2 @@ - -Changelog ---------- - - 8d191ff7 2022-04-10 15:41:16 +0200 wagner@elegosoft.com add missing/lost documentation (issue #4516) - 4509f78a 2022-02-23 20:48:33 +0100 wagner@elegosoft.com (origin/feature_4516_add_files_ported_from_v12_v14, feature_4516_add_files_ported_from_v12_v14) add files ported to v14 by cpatel and khanhbui (issue #4516) diff --git a/rental_pricelist/README/USAGE.rst b/rental_pricelist/README/USAGE.rst index 4edc042f..f4f0519b 100644 --- a/rental_pricelist/README/USAGE.rst +++ b/rental_pricelist/README/USAGE.rst @@ -1,7 +1,3 @@ - -Usage ------ - Create a rentable product: * Go to Rentals > Configuration > Settings. * Please activate the checkbox for using 'Product Variants'. diff --git a/rental_pricelist/__manifest__.py b/rental_pricelist/__manifest__.py index 32232f08..bf912a89 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": "14.0.1.0.2", + "version": "16.0.1.0.1", "category": "Rental", "author": "elego Software Solutions GmbH, Odoo Community Association (OCA)", "website": "https://github.com/OCA/vertical-rental", diff --git a/rental_pricelist/models/__init__.py b/rental_pricelist/models/__init__.py index 7e2c4d63..f6329b88 100644 --- a/rental_pricelist/models/__init__.py +++ b/rental_pricelist/models/__init__.py @@ -1,6 +1,6 @@ # Part of rental-vertical See LICENSE file for full copyright and licensing details. - -from . import sale +from . import sale_order_line +from . import sale_order from . import product from . import product_pricelist_item from . import res_company diff --git a/rental_pricelist/models/product.py b/rental_pricelist/models/product.py index 4f1ec840..6a831b03 100644 --- a/rental_pricelist/models/product.py +++ b/rental_pricelist/models/product.py @@ -106,21 +106,25 @@ def _check_rental(self): if product.rented_product_id: if product.type != "service": raise ValidationError( - _("The rental product '%s' must be of type 'Service'.") - % product.name + _("The rental product '%(name)s' must be of type 'Service'.") + % {"name": product.name} ) if not product.must_have_dates: raise ValidationError( _( - "The rental product '%s' must have the option " + "The rental product '%(name)s' must have the option " "'Must Have Start and End Dates' checked." ) - % product.name + % {"name": product.name} ) @api.model def _get_rental_service_prefix_suffix(self, field, str_type, rental_type): - field_name = "rental_service_%s_%s_%s" % (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, + } res = getattr(self.env.user.company_id, field_name) return res @@ -128,14 +132,13 @@ def _get_rental_service(self, rental_type): self.ensure_one() if rental_type == "month" and self.product_rental_month_id: return self.product_rental_month_id - elif rental_type == "day" and self.product_rental_day_id: + if rental_type == "day" and self.product_rental_day_id: return self.product_rental_day_id - elif rental_type == "hour" and self.product_rental_hour_id: + if rental_type == "hour" and self.product_rental_hour_id: return self.product_rental_hour_id - else: - raise exceptions.ValidationError( - _("The product has no related rental services.") - ) + raise exceptions.ValidationError( + _("The product has no related rental services.") + ) def _get_rental_service_list(self): self.ensure_one() @@ -183,9 +186,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 = "%s %s" % (prefix, name) + name = "%(prefix)s %(name)s" % {"prefix": prefix, "name": name} if suffix: - name = "%s %s" % (name, suffix) + name = "%(name)s %(suffix)s" % {"name": name, "suffix": suffix} return name def _get_rental_service_default_code(self, rental_type, sp_code): @@ -199,9 +202,15 @@ def _get_rental_service_default_code(self, rental_type, sp_code): default_code = sp_code if default_code: if prefix: - default_code = "%s-%s" % (prefix, default_code) + default_code = "%(prefix)s-%(default_code)s" % { + "prefix": prefix, + "default_code": default_code, + } if suffix: - default_code = "%s-%s" % (default_code, suffix) + default_code = "%(default_code)s-%(suffix)s" % { + "default_code": default_code, + "suffix": suffix, + } else: default_code = "" return default_code @@ -211,10 +220,12 @@ 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 %s (%s)") % (product.name, uom.name), + "name": _("Rental of %(product_name)s (%(uom_name)s)") + % {"product_name": product.name, "uom_name": uom.name}, "categ_id": product.categ_id.id, "copy_image": True, - "default_code": "RENT-%s-%s" % (rental_type.upper(), product.default_code), + "default_code": "RENT-%(rental)s-%(code)s" + % {"rental": rental_type.upper(), "code": product.default_code}, } res = ( self.env["create.rental.product"] @@ -290,7 +301,6 @@ def _update_rental_service_fields(self, vals, fields, rental_services): for field in fields: if field in vals: service_vals[field] = vals.get(field, False) - # check 'active' becomes True from False check_rental_services = ( service_vals.get("active", False) and not self.rental_service_ids diff --git a/rental_pricelist/models/product_pricelist_item.py b/rental_pricelist/models/product_pricelist_item.py index 63118532..1bc91001 100644 --- a/rental_pricelist/models/product_pricelist_item.py +++ b/rental_pricelist/models/product_pricelist_item.py @@ -26,11 +26,14 @@ def _onchange_product_id(self): uom_month = self.env.ref("rental_base.product_uom_month") uom_day = self.env.ref("uom.product_uom_day") uom_hour = self.env.ref("uom.product_uom_hour") - super()._onchange_product_id() + res = super()._onchange_product_id() if self.product_id.rented_product_id: if self.product_id.uom_id.id == uom_month.id: self.month_item_id = self.product_id.rented_product_id.id + if self.product_id.uom_id.id == uom_day.id: self.day_item_id = self.product_id.rented_product_id.id + if self.product_id.uom_id.id == uom_hour.id: self.hour_item_id = self.product_id.rented_product_id.id + return res diff --git a/rental_pricelist/models/sale_order.py b/rental_pricelist/models/sale_order.py new file mode 100644 index 00000000..b505b963 --- /dev/null +++ b/rental_pricelist/models/sale_order.py @@ -0,0 +1,20 @@ +from odoo import _, models +from odoo.exceptions import UserError + + +class SaleOrder(models.Model): + _inherit = "sale.order" + + def _check_rental_order_line(self): + for order in self: + for line in order.order_line: + if line.rental and line.product_id: + if line.product_id.type != "service": + raise UserError( + _("The product %(name)s is not correctly configured.") + % {"name": line.product_id.name} + ) + + def action_confirm(self): + self._check_rental_order_line() + return super().action_confirm() diff --git a/rental_pricelist/models/sale.py b/rental_pricelist/models/sale_order_line.py similarity index 67% rename from rental_pricelist/models/sale.py rename to rental_pricelist/models/sale_order_line.py index 8e67a28f..bcd2e336 100644 --- a/rental_pricelist/models/sale.py +++ b/rental_pricelist/models/sale_order_line.py @@ -1,6 +1,4 @@ -# Part of rental-vertical See LICENSE file for full copyright and licensing details. - -from odoo import _, api, exceptions, fields, models +from odoo import _, api, fields, models from odoo.exceptions import ValidationError from odoo.tools import float_compare @@ -122,20 +120,18 @@ def _check_rental_availability(self): res["warning"] = { "title": _("Not enough stock!"), "message": _( - "You want to rent %.2f %s but you only " - "have %.2f %s currently available on the " - 'stock location "%s"! Make sure that you ' + "You want to rent %(rental_qty).2f %(rental_uom)s but you only " + "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 "%s".' + 're-supply the stock location "%(rental_name)s".' ) - % ( - self.rental_qty, - self.product_id.rented_product_id.uom_id.name, - in_location_available_qty, - self.product_id.rented_product_id.uom_id.name, - rental_in_location.name, - rental_in_location.name, - ), + % { + "rental_qty": self.rental_qty, + "rental_uom": self.product_id.rented_product_id.uom_id.name, + "available_qty": in_location_available_qty, + "rental_name": rental_in_location.name, + }, } return res @@ -188,48 +184,49 @@ def _check_sale_line_rental(self): raise ValidationError( _( 'Missing "Rental to Extend" on the sale order line ' - "with rental service %s." + "with rental service %(name)s." ) - % line.product_id.name + % {"name": line.product_id.name} ) if line.rental_qty != line.extension_rental_id.rental_qty: raise ValidationError( _( - "On the sale order line with rental service %s, " + "On the sale order line with rental service %(name)s, " "you are trying to extend a rental with a rental " - "quantity (%s) that is different from the quantity " - "of the original rental (%s). This is not supported." - ) - % ( - line.product_id.name, - line.rental_qty, - line.extension_rental_id.rental_qty, + "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, + "rental_qty": line.rental_qty, + "ext_rental_qty": line.extension_rental_id.rental_qty, + } ) if line.rental_type in ("new_rental", "rental_extension"): if not line.product_id.rented_product_id: raise ValidationError( _( 'On the "new rental" sale order line with product ' - '"%s", we should have a rental service product!' + '"%(name)s", we should have a rental service product!' ) - % (line.product_id.name) + % {"name": line.product_id.name} ) elif line.sell_rental_id: if line.product_uom_qty != line.sell_rental_id.rental_qty: raise ValidationError( _( - "On the sale order line with product %s " + "On the sale order line with product %(name)s " "you are trying to sell a rented product with a " - "quantity (%s) that is different from the rented " - "quantity (%s). This is not supported." - ) - % ( - line.product_id.name, - line.product_uom_qty, - line.sell_rental_id.rental_qty, + "quantity (%(qty)s) that is different from the rented " + "quantity (%(rental_qty)s). This is not supported." ) + % { + "name": line.product_id.name, + "qty": line.product_uom_qty, + "rental_qty": line.sell_rental_id.rental_qty, + } ) @api.onchange("rental_qty", "number_of_time_unit", "product_id") @@ -251,68 +248,32 @@ def _get_product_rental_uom_ids(self): return uom_ids @api.onchange("product_id") - def product_id_change(self): - res = super(SaleOrderLine, self).product_id_change() - if self.rental: - if self.display_product_id.rental: - if "domain" not in res: - res["domain"] = {} - uom_ids = self._get_product_rental_uom_ids() - res["domain"]["product_uom"] = [("id", "in", uom_ids)] - if uom_ids and self.product_uom.id not in uom_ids: - self.product_uom = uom_ids[0] - return res + def _onchange_product_id(self): + for line in self: + if line.rental: + if line.display_product_id.rental: + uom_ids = line._get_product_rental_uom_ids() + if line.product_uom.id not in uom_ids: + line.product_uom = uom_ids and uom_ids[0] or False + return True @api.onchange("product_uom", "product_uom_qty") - def product_uom_change(self): - if self.display_product_id and self.product_uom and self.rental: - if self.product_uom.id != self.product_id.uom_id.id: - time_uoms = self._get_time_uom() - for key in time_uoms: - if self.product_uom.id == time_uoms[key].id: - self.product_id = self.display_product_id._get_rental_service( - key + def _onchange_product_uom(self): + for line in self: + if line.rental and line.display_product_id: + if line.product_uom.id != line.product_id.uom_id.id: + time_uoms = line._get_time_uom() + key = list( + filter( + lambda key: time_uoms[key].id == line.product_uom.id, + time_uoms.keys(), ) - break - return super(SaleOrderLine, self).product_uom_change() + )[-1] + line.product_id = line.display_product_id._get_rental_service(key) + return True @api.onchange("start_date", "end_date", "product_uom") - def onchange_start_end_date(self): + def _onchange_start_end_date(self): if self.start_date and self.end_date: number = self._get_number_of_time_unit() self.number_of_time_unit = number - - # Override function from module sale_start_end_dates - @api.onchange("product_id") - def start_end_dates_product_id_change(self): - if self.product_id.must_have_dates: - if not self.start_date and not self.end_date: - if self.order_id.default_start_date: - self.start_date = self.order_id.default_start_date - else: - self.start_date = False - if self.order_id.default_end_date: - self.end_date = self.order_id.default_end_date - else: - self.end_date = False - else: - self.start_date = False - self.end_date = False - - -class SaleOrder(models.Model): - _inherit = "sale.order" - - def _check_rental_order_line(self): - for order in self: - for line in order.order_line: - if line.rental and line.product_id: - if line.product_id.type != "service": - raise exceptions.UserError( - _("The product %s is not correctly configured.") - % line.product_id.name - ) - - def action_confirm(self): - self._check_rental_order_line() - return super().action_confirm() diff --git a/rental_pricelist/tests/test_rental_pricelist.py b/rental_pricelist/tests/test_rental_pricelist.py index c56b4736..4ee51fe2 100644 --- a/rental_pricelist/tests/test_rental_pricelist.py +++ b/rental_pricelist/tests/test_rental_pricelist.py @@ -10,10 +10,10 @@ def _run_sol_onchange_display_product_id(line): line.onchange_display_product_id() # product_id, rental changed - line.product_id_change() + line._onchange_product_id() line.onchange_rental() # product_id changed again - line.product_id_change() # product_uom changed - line.product_uom_change() + line._onchange_product_id() # product_uom changed + line._onchange_product_uom() line.rental_product_id_change() # set start end date manually @@ -22,26 +22,26 @@ def _run_sol_onchange_date(line, start_date=False, end_date=False): line.start_date = start_date if end_date: line.end_date = end_date - line.onchange_start_end_date() # number_of_time_unit changed - line.rental_qty_number_of_days_change() # product_uom_qty changed - line.product_uom_change() + line._onchange_start_end_date() + line.rental_qty_number_of_days_change() + line._onchange_product_uom() def _run_sol_onchange_product_uom(line, product_uom): line.product_uom = product_uom - line.product_uom_change() - line.product_id_change() - line.onchange_start_end_date() + line._onchange_product_uom() + line._onchange_product_id() + line._onchange_start_end_date() line.rental_qty_number_of_days_change() - line.product_uom_change() + line._onchange_product_uom() def _run_sol_onchange_can_sell_rental(line, can_sell_rental): line.can_sell_rental = can_sell_rental line.onchange_can_sell_rental() line.onchange_rental() - line.product_id_change() - line.product_uom_change() + line._onchange_product_id() + line._onchange_product_uom() def _run_sol_onchange_rental(line, rental): @@ -49,24 +49,32 @@ def _run_sol_onchange_rental(line, rental): line.onchange_rental() line.onchange_can_sell_rental() line.rental_product_id_change() - line.product_id_change() - line.product_uom_change() + line._onchange_product_id() + line._onchange_product_uom() class TestRentalPricelist(RentalStockCommon): def setUp(self): super().setUp() + self.analytic_plan = self.env["account.analytic.plan"].create( + { + "name": "Analytic Plan Test", + } + ) + self.analytic_account_A = self.env["account.analytic.account"].create( { "name": "Analytic Account A", "code": "100001", + "plan_id": self.analytic_plan.id, } ) self.analytic_account_B = self.env["account.analytic.account"].create( { "name": "Analytic Account B", "code": "100002", + "plan_id": self.analytic_plan.id, } ) @@ -137,7 +145,7 @@ def setUp(self): self.rental_order = ( self.env["sale.order"] .with_context( - { + **{ "default_type_id": self.rental_sale_type.id, } ) @@ -229,7 +237,7 @@ def test_01_rental_onchange_productA(self): line = ( self.env["sale.order.line"] .with_context( - { + **{ "type_id": self.rental_sale_type.id, } ) @@ -243,18 +251,11 @@ def test_01_rental_onchange_productA(self): ) ) line.onchange_display_product_id() - line.product_id_change() - # check uom domain - # check_uom_domain = False - # if "domain" in res and "product_uom" in res["domain"]: - # self.assertEqual(len(res["domain"]["product_uom"][0][2]), 3) - # check_uom_domain = True - # self.assertTrue(check_uom_domain) + line._onchange_product_id() line.onchange_rental() - line.product_uom_change() + line._onchange_product_uom() line.rental_product_id_change() _run_sol_onchange_date(line) - # self._print_sol(line) self.assertEqual(line.rental, True) self.assertEqual(line.rental_type, "new_rental") self.assertEqual(line.can_sell_rental, False) @@ -264,10 +265,7 @@ def test_01_rental_onchange_productA(self): self.assertEqual(line.product_uom_qty > 80, True) self.assertEqual(line.rental_qty, 1) self.assertEqual(line.number_of_time_unit > 80, True) - - # Change product_uom manually _run_sol_onchange_product_uom(line, self.uom_month) - # self._print_sol(line) self.assertEqual(line.product_id, self.productA.product_rental_month_id) self.assertEqual(line.display_product_id, self.productA) self.assertEqual(line.product_uom, self.uom_month) @@ -289,7 +287,7 @@ def test_02_rental_onchange_productC(self): line = ( self.env["sale.order.line"] .with_context( - { + **{ "type_id": self.rental_sale_type.id, } ) @@ -303,18 +301,11 @@ def test_02_rental_onchange_productC(self): ) ) line.onchange_display_product_id() - line.product_id_change() - # check uom domain - # check_uom_domain = False - # if "domain" in res and "product_uom" in res["domain"]: - # self.assertEqual(res["domain"]["product_uom"][0][2][0], self.uom_month.id) - # check_uom_domain = True - # self.assertTrue(check_uom_domain) + line._onchange_product_id() line.onchange_rental() - line.product_uom_change() + line._onchange_product_uom() line.rental_product_id_change() _run_sol_onchange_date(line) - # self._print_sol(line) self.assertEqual(line.rental, True) self.assertEqual(line.rental_type, "new_rental") self.assertEqual(line.can_sell_rental, False) @@ -324,10 +315,7 @@ def test_02_rental_onchange_productC(self): self.assertEqual(line.product_uom_qty, 3) self.assertEqual(line.rental_qty, 1) self.assertEqual(line.number_of_time_unit, 3) - - # Change can_sell_rental -> True manually _run_sol_onchange_can_sell_rental(line, True) - # self._print_sol(line) self.assertEqual(line.rental, False) self.assertEqual(line.rental_type, False) self.assertEqual(line.can_sell_rental, True) @@ -335,10 +323,7 @@ def test_02_rental_onchange_productC(self): self.assertEqual(line.display_product_id, self.productC) self.assertEqual(line.product_uom, self.uom_unit) self.assertEqual(line.rental_qty, 0) - - # Change rental -> True manually _run_sol_onchange_rental(line, True) - # self._print_sol(line) self.assertEqual(line.rental, True) self.assertEqual(line.rental_type, "new_rental") self.assertEqual(line.can_sell_rental, False) @@ -348,19 +333,6 @@ def test_02_rental_onchange_productC(self): self.assertEqual(line.rental_qty, 1) def test_03_rental_pricelist_items(self): - # add scale price of product A - # Day Price - # 1 100 - # 20 90 - # 45 80 - # 80 70 - # - # Month Price - # 1 1000 - # 2 900 - # 3 800 - # - # add item from product form view self.productA.write( { "day_scale_pricelist_item_ids": [ @@ -409,8 +381,6 @@ def test_03_rental_pricelist_items(self): ], } ) - - # add item from pricelist item1 = self.env["product.pricelist.item"].create( { "applied_on": "0_product_variant", @@ -439,7 +409,7 @@ def test_03_rental_pricelist_items(self): line = ( self.env["sale.order.line"] .with_context( - { + **{ "type_id": self.rental_sale_type.id, } ) @@ -453,7 +423,6 @@ def test_03_rental_pricelist_items(self): ) ) _run_sol_onchange_display_product_id(line) - # check price of days _run_sol_onchange_date(line) self.assertEqual(line.product_uom_qty > 80, True) self.assertEqual(line.price_unit, 70) @@ -466,8 +435,6 @@ def test_03_rental_pricelist_items(self): _run_sol_onchange_date(line, end_date=self.tomorrow) self.assertEqual(line.product_uom_qty, 2) self.assertEqual(line.price_unit, 100) - - # check price of months _run_sol_onchange_product_uom(line, self.uom_month) _run_sol_onchange_date(line, end_date=self.date_28_day_later) # check round self.assertEqual(line.product_uom_qty, 1) @@ -486,7 +453,7 @@ def test_04_check_rental_order_line_productD(self): line = ( self.env["sale.order.line"] .with_context( - { + **{ "type_id": self.rental_sale_type.id, } ) @@ -498,7 +465,7 @@ def test_04_check_rental_order_line_productD(self): ) ) line.onchange_display_product_id() - line.product_id_change() + line._onchange_product_id() line.rental = True vals = line._convert_to_write(line._cache) self.env["sale.order.line"].create(vals) @@ -527,7 +494,6 @@ def test_05_check_rental_productE(self): " must have the option 'Must Have Start and End Dates' checked.", str(e.exception), ) - # check onchange method of product.pricelist.item self.productE.write( { "hour_scale_pricelist_item_ids": [ @@ -546,7 +512,6 @@ def test_05_check_rental_productE(self): ], } ) - # add item from pricelist item1 = self.env["product.pricelist.item"].create( { "applied_on": "0_product_variant", @@ -559,17 +524,13 @@ def test_05_check_rental_productE(self): ) item1._onchange_product_id() self.assertEqual(item1.day_item_id, self.productE) - # check default_code self.assertEqual(self.productE.default_code, "PRD-E123") self.assertEqual(rental_serviceE.default_code, "RENT-D-PRD-E123") - # update and check default_code self.productE.default_code = "PRD-E110" self.assertEqual(self.productE.default_code, "PRD-E110") self.assertEqual(rental_serviceE.default_code, "RENT-D-PRD-E110") - # update and check name self.productE.name = "Product E1" self.assertEqual(rental_serviceE.name, "Rental of Product E1 (Day(s))") - # update active self.productE.active = False self.assertEqual(rental_serviceE.active, False) self.productE.active = True @@ -579,7 +540,7 @@ def test_06_check_start_end_dates_productF(self): rental_order = ( self.env["sale.order"] .with_context( - { + **{ "default_type_id": self.rental_sale_type.id, } ) @@ -593,7 +554,7 @@ def test_06_check_start_end_dates_productF(self): line = ( self.env["sale.order.line"] .with_context( - { + **{ "type_id": self.rental_sale_type.id, } ) @@ -605,22 +566,22 @@ def test_06_check_start_end_dates_productF(self): ) ) line.onchange_display_product_id() - line.product_id_change() + line._onchange_product_id() line.onchange_rental() - line.product_uom_change() + line._onchange_product_uom() line.rental_product_id_change() _run_sol_onchange_date(line) - line.start_end_dates_product_id_change() - # no dates avaiavlbe + line._compute_start_date() + line._compute_end_date() self.assertEqual(line.start_date, False) self.assertEqual(line.end_date, False) - # set dates on rental order rental_order.update( { "default_start_date": self.today, "default_end_date": self.tomorrow, } ) - line.start_end_dates_product_id_change() + line._compute_start_date() + line._compute_end_date() self.assertEqual(line.start_date, self.today) self.assertEqual(line.end_date, self.tomorrow) diff --git a/rental_pricelist/views/product_view.xml b/rental_pricelist/views/product_view.xml index 6eae6cb2..ebc15163 100644 --- a/rental_pricelist/views/product_view.xml +++ b/rental_pricelist/views/product_view.xml @@ -4,11 +4,10 @@ view.product.product.form product.product - 112 + 112 + - - + + + - - - - view.product.template.form - product.template - 111 - - - - - -