From 53dd36f5c0009147ec86a706c4490695d79f988e Mon Sep 17 00:00:00 2001 From: Unai Beristain Date: Tue, 16 Jul 2024 09:03:59 +0200 Subject: [PATCH] [MIG] repair_discount: Migration to 16.0 --- repair_discount/README.rst | 16 ++-- repair_discount/__manifest__.py | 4 +- repair_discount/models/mrp_repair.py | 94 +++++-------------- repair_discount/static/description/index.html | 20 ++-- .../tests/test_mrp_repair_discount.py | 23 ++++- .../odoo/addons/repair_discount | 1 + setup/repair_discount/setup.py | 6 ++ 7 files changed, 73 insertions(+), 91 deletions(-) create mode 120000 setup/repair_discount/odoo/addons/repair_discount create mode 100644 setup/repair_discount/setup.py diff --git a/repair_discount/README.rst b/repair_discount/README.rst index 8b2b0879..0508747a 100644 --- a/repair_discount/README.rst +++ b/repair_discount/README.rst @@ -16,14 +16,14 @@ Repair Discount .. |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%2Fmanufacture-lightgray.png?logo=github - :target: https://github.com/OCA/manufacture/tree/14.0/repair_discount - :alt: OCA/manufacture +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Frepair-lightgray.png?logo=github + :target: https://github.com/OCA/repair/tree/16.0/repair_discount + :alt: OCA/repair .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/manufacture-14-0/manufacture-14-0-repair_discount + :target: https://translation.odoo-community.org/projects/repair-16-0/repair-16-0-repair_discount :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/manufacture&target_branch=14.0 + :target: https://runboat.odoo-community.org/builds?repo=OCA/repair&target_branch=16.0 :alt: Try me on Runboat |badge1| |badge2| |badge3| |badge4| |badge5| @@ -39,10 +39,10 @@ new field discount on operations lines Bug Tracker =========== -Bugs are tracked on `GitHub Issues `_. +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 `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -78,6 +78,6 @@ 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/manufacture `_ project on GitHub. +This module is part of the `OCA/repair `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/repair_discount/__manifest__.py b/repair_discount/__manifest__.py index d0a55e15..4848be82 100644 --- a/repair_discount/__manifest__.py +++ b/repair_discount/__manifest__.py @@ -4,11 +4,11 @@ { "name": "Repair Discount", - "version": "14.0.1.0.0", + "version": "16.0.1.0.0", "category": "Manufacturing", "license": "AGPL-3", "author": "Agile Business Group, " "Tecnativa, " "Odoo Community Association (OCA)", - "website": "https://github.com/OCA/manufacture", + "website": "https://github.com/OCA/repair", "depends": ["repair"], "data": [ "views/mrp_repair_view.xml", diff --git a/repair_discount/models/mrp_repair.py b/repair_discount/models/mrp_repair.py index fc1be5ec..245632c4 100644 --- a/repair_discount/models/mrp_repair.py +++ b/repair_discount/models/mrp_repair.py @@ -9,94 +9,50 @@ class RepairFee(models.Model): _inherit = "repair.fee" - discount = fields.Float(string="Discount (%)") - - @api.depends("price_unit", "repair_id", "product_uom_qty", "product_id", "discount") - def _compute_price_subtotal(self): - for fee in self: - taxes = self.env["account.tax"].compute_all( - fee.price_unit, - fee.repair_id.pricelist_id.currency_id, - fee.product_uom_qty, - fee.product_id, - fee.repair_id.partner_id, - ) - fee.price_subtotal = taxes["total_excluded"] * ( - 1 - (fee.discount or 0.0) / 100.0 - ) + discount = fields.Float( + string="Discount (%)", + store=True, + ) @api.depends( - "price_unit", "repair_id", "product_uom_qty", "product_id", "tax_id", "discount" + "discount", ) - def _compute_price_total(self): + def _compute_price_total_and_subtotal(self): + res = super()._compute_price_total_and_subtotal() for fee in self: - taxes = fee.tax_id.compute_all( - fee.price_unit, - fee.repair_id.pricelist_id.currency_id, - fee.product_uom_qty, - fee.product_id, - fee.repair_id.partner_id, - ) - fee.price_total = taxes["total_included"] * ( + fee.price_total = fee.price_total * (1 - (fee.discount or 0.0) / 100.0) + fee.price_subtotal = fee.price_subtotal * ( 1 - (fee.discount or 0.0) / 100.0 ) + return res class RepairLine(models.Model): _inherit = "repair.line" - discount = fields.Float(string="Discount (%)") - - @api.depends( - "price_unit", - "repair_id", - "product_uom_qty", - "product_id", - "repair_id.invoice_method", - "discount", + discount = fields.Float( + string="Discount (%)", + store=True, ) - def _compute_price_subtotal(self): - for line in self: - taxes = self.env["account.tax"].compute_all( - line.price_unit, - line.repair_id.pricelist_id.currency_id, - line.product_uom_qty, - line.product_id, - line.repair_id.partner_id, - ) - line.price_subtotal = taxes["total_excluded"] * ( - 1 - (line.discount or 0.0) / 100.0 - ) @api.depends( - "price_unit", - "repair_id", - "product_uom_qty", - "product_id", - "tax_id", - "repair_id.invoice_method", "discount", ) - def _compute_price_total(self): + def _compute_price_total_and_subtotal(self): + res = super()._compute_price_total_and_subtotal() for line in self: - taxes = line.tax_id.compute_all( - line.price_unit, - line.repair_id.pricelist_id.currency_id, - line.product_uom_qty, - line.product_id, - line.repair_id.partner_id, - ) - line.price_total = taxes["total_included"] * ( + line.price_total = line.price_total * (1 - (line.discount or 0.0) / 100.0) + line.price_subtotal = line.price_subtotal * ( 1 - (line.discount or 0.0) / 100.0 ) + return res class RepairOrder(models.Model): _inherit = "repair.order" def _create_invoices(self, group=False): - - res = super(RepairOrder, self)._create_invoices(group) + res = super()._create_invoices(group) for repair in self.filtered(lambda _repair: _repair.invoice_method != "none"): operations = repair.operations fees_lines = repair.fees_lines @@ -112,20 +68,20 @@ def _create_invoices(self, group=False): fee_lines.invoice_line_id.with_context( check_move_validity=False ).update({"discount": fee_lines.discount}) - self.invoice_id.with_context( - check_move_validity=False - )._recompute_dynamic_lines( - recompute_all_taxes=True, recompute_tax_base_amount=True - ) + return res def _calculate_line_base_price(self, line): return line.price_unit * (1 - (line.discount or 0.0) / 100.0) + amount_tax = fields.Monetary( + string="Tax Amount", compute="_compute_amount_tax_depends" + ) + @api.depends( "operations", "fees_lines", "operations.invoiced", "fees_lines.invoiced" ) - def _amount_tax(self): + def _compute_amount_tax_depends(self): for repair in self: taxed_amount = 0.0 currency = repair.pricelist_id.currency_id diff --git a/repair_discount/static/description/index.html b/repair_discount/static/description/index.html index 79ad9301..a531072e 100644 --- a/repair_discount/static/description/index.html +++ b/repair_discount/static/description/index.html @@ -1,4 +1,3 @@ - @@ -9,10 +8,11 @@ /* :Author: David Goodger (goodger@python.org) -:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $ +:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $ :Copyright: This stylesheet has been placed in the public domain. Default cascading style sheet for the HTML output of Docutils. +Despite the name, some widely supported CSS2 features are used. See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to customize this style sheet. @@ -275,7 +275,7 @@ margin-left: 2em ; margin-right: 2em } -pre.code .ln { color: grey; } /* line numbers */ +pre.code .ln { color: gray; } /* line numbers */ pre.code, code { background-color: #eeeeee } pre.code .comment, code .comment { color: #5C6576 } pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold } @@ -301,7 +301,7 @@ span.pre { white-space: pre } -span.problematic { +span.problematic, pre.problematic { color: red } span.section-subtitle { @@ -369,7 +369,7 @@

Repair Discount

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! source digest: sha256:9ff7aad831adc2c669cd1e07926e8eb8da381c855dd588790b2ff98cf3eb6498 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

Beta License: AGPL-3 OCA/manufacture Translate me on Weblate Try me on Runboat

+

Beta License: AGPL-3 OCA/repair Translate me on Weblate Try me on Runboat

This module extends the functionality of mrp repair adding new field discount on operations lines

Table of contents

@@ -386,10 +386,10 @@

Repair Discount

Bug Tracker

-

Bugs are tracked on GitHub Issues. +

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.

+feedback.

Do not contact contributors directly about support or help with technical issues.

@@ -415,11 +415,13 @@

Contributors

Maintainers

This module is maintained by the OCA.

-Odoo Community Association + +Odoo Community Association +

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/manufacture project on GitHub.

+

This module is part of the OCA/repair project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

diff --git a/repair_discount/tests/test_mrp_repair_discount.py b/repair_discount/tests/test_mrp_repair_discount.py index 1042ac56..088975e5 100644 --- a/repair_discount/tests/test_mrp_repair_discount.py +++ b/repair_discount/tests/test_mrp_repair_discount.py @@ -1,13 +1,19 @@ # Copyright 2016 Pedro M. Baeza # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from odoo.tests import common +import logging +from odoo.tests.common import TransactionCase -class TestMrpRepairDiscount(common.SavepointCase): +_logger = logging.getLogger(__name__) + + +class TestMrpRepairDiscount(TransactionCase): @classmethod def setUpClass(cls): - super(TestMrpRepairDiscount, cls).setUpClass() + super().setUpClass() + + # Create product and service cls.product = cls.env["product.product"].create( { "name": "Test product", @@ -22,12 +28,16 @@ def setUpClass(cls): "list_price": 20, } ) + + # Create partner and location cls.partner = cls.env.ref("base.res_partner_address_1") cls.location = cls.env["stock.location"].create( { "name": "Test location", } ) + + # Create repair order cls.repair = cls.env["repair.order"].create( { "product_id": cls.product.id, @@ -38,8 +48,12 @@ def setUpClass(cls): "invoice_method": "b4repair", } ) + + # Find stock location domain_location = [("usage", "=", "production")] stock_location_id = cls.env["stock.location"].search(domain_location, limit=1) + + # Create repair line cls.repair_line = cls.env["repair.line"].create( { "repair_id": cls.repair.id, @@ -54,7 +68,9 @@ def setUpClass(cls): "discount": 50, } ) + _logger.debug("Created repair line with discount: %s", cls.repair_line.discount) + # Create repair fee cls.repair_fee = cls.env["repair.fee"].create( { "repair_id": cls.repair.id, @@ -66,6 +82,7 @@ def setUpClass(cls): "discount": 50, } ) + _logger.debug("Created repair fee with discount: %s", cls.repair_fee.discount) def test_discount(self): self.assertAlmostEqual(self.repair_line.price_subtotal, 10) diff --git a/setup/repair_discount/odoo/addons/repair_discount b/setup/repair_discount/odoo/addons/repair_discount new file mode 120000 index 00000000..8f94b414 --- /dev/null +++ b/setup/repair_discount/odoo/addons/repair_discount @@ -0,0 +1 @@ +../../../../repair_discount \ No newline at end of file diff --git a/setup/repair_discount/setup.py b/setup/repair_discount/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/repair_discount/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)