From 6c0ddbf2ed794e74dfca445781296d675430de27 Mon Sep 17 00:00:00 2001 From: miguel-S73 Date: Wed, 14 Aug 2024 18:25:06 +0200 Subject: [PATCH] [MIG] sale_global_discount: Migration to 17.0 --- sale_global_discount/README.rst | 4 ++++ sale_global_discount/__manifest__.py | 2 +- sale_global_discount/hooks.py | 22 ++++++++++--------- sale_global_discount/models/sale_order.py | 5 +++-- sale_global_discount/readme/CONTRIBUTORS.md | 4 ++++ .../static/description/index.html | 4 ++++ .../tests/test_sale_global_discount.py | 4 +++- 7 files changed, 31 insertions(+), 14 deletions(-) diff --git a/sale_global_discount/README.rst b/sale_global_discount/README.rst index a460bd6fd97c..c690545cec54 100644 --- a/sale_global_discount/README.rst +++ b/sale_global_discount/README.rst @@ -93,6 +93,10 @@ Contributors - Omar Castiñeira +- `Studio73 `__ + + - Miguel Gandia + Maintainers ----------- diff --git a/sale_global_discount/__manifest__.py b/sale_global_discount/__manifest__.py index 458331b06b86..2fc524e9beed 100644 --- a/sale_global_discount/__manifest__.py +++ b/sale_global_discount/__manifest__.py @@ -3,7 +3,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { "name": "Sale Global Discount", - "version": "16.0.1.0.0", + "version": "17.0.1.0.0", "category": "Sales Management", "author": "Tecnativa," "Odoo Community Association (OCA)", "website": "https://github.com/OCA/sale-workflow", diff --git a/sale_global_discount/hooks.py b/sale_global_discount/hooks.py index 7738bfe0612d..3557886c8348 100644 --- a/sale_global_discount/hooks.py +++ b/sale_global_discount/hooks.py @@ -1,39 +1,41 @@ from odoo.tools.sql import column_exists -def _pre_init_global_discount_fields(cr): - if not column_exists(cr, "sale_order", "amount_global_discount"): - cr.execute( +def _pre_init_global_discount_fields(env): + if not column_exists(env.cr, "sale_order", "amount_global_discount"): + env.cr.execute( """ ALTER TABLE "sale_order" ADD COLUMN "amount_global_discount" double precision DEFAULT 0 """ ) - cr.execute( + env.cr.execute( """ ALTER TABLE "sale_order" ALTER COLUMN "amount_global_discount" DROP DEFAULT """ ) - if not column_exists(cr, "sale_order", "amount_untaxed_before_global_discounts"): - cr.execute( + if not column_exists( + env.cr, "sale_order", "amount_untaxed_before_global_discounts" + ): + env.cr.execute( """ ALTER TABLE "sale_order" ADD COLUMN "amount_untaxed_before_global_discounts" double precision """ ) - cr.execute( + env.cr.execute( """ update sale_order set amount_untaxed_before_global_discounts = amount_untaxed """ ) - if not column_exists(cr, "sale_order", "amount_total_before_global_discounts"): - cr.execute( + if not column_exists(env.cr, "sale_order", "amount_total_before_global_discounts"): + env.cr.execute( """ ALTER TABLE "sale_order" ADD COLUMN "amount_total_before_global_discounts" double precision """ ) - cr.execute( + env.cr.execute( """ update sale_order set amount_total_before_global_discounts = amount_total """ diff --git a/sale_global_discount/models/sale_order.py b/sale_global_discount/models/sale_order.py index fc66211ddb16..f874dcb87d9a 100644 --- a/sale_global_discount/models/sale_order.py +++ b/sale_global_discount/models/sale_order.py @@ -68,7 +68,7 @@ def _check_global_discounts_sanity(self): return True taxes_keys = {} for line in self.order_line.filtered( - lambda l: not l.display_type and l.product_id + lambda _line: not _line.display_type and _line.product_id ): if not line.tax_id: raise exceptions.UserError( @@ -141,11 +141,12 @@ def _compute_tax_totals(self): @api.onchange("partner_id") def onchange_partner_id_set_gbl_disc(self): + commercial = self.partner_id.commercial_partner_id self.global_discount_ids = ( self.partner_id.customer_global_discount_ids.filtered( lambda d: d.company_id == self.company_id ) - or self.partner_id.commercial_partner_id.customer_global_discount_ids.filtered( + or commercial.customer_global_discount_ids.filtered( lambda d: d.company_id == self.company_id ) ) diff --git a/sale_global_discount/readme/CONTRIBUTORS.md b/sale_global_discount/readme/CONTRIBUTORS.md index 17320ded8376..c4e205a2a7ff 100644 --- a/sale_global_discount/readme/CONTRIBUTORS.md +++ b/sale_global_discount/readme/CONTRIBUTORS.md @@ -2,3 +2,7 @@ - David Vidal - Pedro M. Baeza - Omar Castiñeira \<\> + +- [Studio73](https://www.studio73.es) + - Miguel Gandia + \ No newline at end of file diff --git a/sale_global_discount/static/description/index.html b/sale_global_discount/static/description/index.html index 9bc8303c2993..f24897325068 100644 --- a/sale_global_discount/static/description/index.html +++ b/sale_global_discount/static/description/index.html @@ -441,6 +441,10 @@

Contributors

  • Omar Castiñeira <omar@comunitea.com>
  • +
  • Studio73
      +
    • Miguel Gandia
    • +
    +
  • diff --git a/sale_global_discount/tests/test_sale_global_discount.py b/sale_global_discount/tests/test_sale_global_discount.py index febdcf98ffd9..7e36898c110a 100644 --- a/sale_global_discount/tests/test_sale_global_discount.py +++ b/sale_global_discount/tests/test_sale_global_discount.py @@ -52,7 +52,9 @@ def setUpClass(cls, chart_template_ref=None): "account_id": cls.account.id, } ) - cls.pricelist = cls.env.ref("product.list0") + cls.pricelist = cls.env["product.pricelist"].create( + {"name": "Public Pricelist", "sequence": 1} + ) cls.partner_1 = cls.env["res.partner"].create( {"name": "Mr. Odoo", "property_product_pricelist": cls.pricelist.id} )