From 629a8d9b9b8562d4b0221940d4b65c7a15e19b2d Mon Sep 17 00:00:00 2001 From: Balaji Kannan Date: Mon, 14 Oct 2024 10:28:09 -0700 Subject: [PATCH 1/2] [ADD] Moved generic tax fix to osi_addons repository. --- osi_downpayment_taxes/__init__.py | 1 + osi_downpayment_taxes/__manifest__.py | 16 ++++++ osi_downpayment_taxes/wizards/__init__.py | 1 + .../wizards/sale_make_invoice_advance.py | 51 +++++++++++++++++++ 4 files changed, 69 insertions(+) create mode 100644 osi_downpayment_taxes/__init__.py create mode 100644 osi_downpayment_taxes/__manifest__.py create mode 100644 osi_downpayment_taxes/wizards/__init__.py create mode 100644 osi_downpayment_taxes/wizards/sale_make_invoice_advance.py diff --git a/osi_downpayment_taxes/__init__.py b/osi_downpayment_taxes/__init__.py new file mode 100644 index 000000000..5cb1c4914 --- /dev/null +++ b/osi_downpayment_taxes/__init__.py @@ -0,0 +1 @@ +from . import wizards diff --git a/osi_downpayment_taxes/__manifest__.py b/osi_downpayment_taxes/__manifest__.py new file mode 100644 index 000000000..2604c4362 --- /dev/null +++ b/osi_downpayment_taxes/__manifest__.py @@ -0,0 +1,16 @@ +{ + "name": "Sales Downpayment Tax Fixes", + "summary": "Extends Sales Downpayments to fix sales lines made for multiple tax rates", + "version": "17.0.1.0.0", + "author": "Open Source Integrators", + "category": "Accounting", + "depends": [ + 'account_accountant', + 'sale', + ], + "data": [ + ], + "application": False, + "installable": True, + "auto_install": False +} diff --git a/osi_downpayment_taxes/wizards/__init__.py b/osi_downpayment_taxes/wizards/__init__.py new file mode 100644 index 000000000..fca48c3d0 --- /dev/null +++ b/osi_downpayment_taxes/wizards/__init__.py @@ -0,0 +1 @@ +from . import sale_make_invoice_advance diff --git a/osi_downpayment_taxes/wizards/sale_make_invoice_advance.py b/osi_downpayment_taxes/wizards/sale_make_invoice_advance.py new file mode 100644 index 000000000..f1798ea45 --- /dev/null +++ b/osi_downpayment_taxes/wizards/sale_make_invoice_advance.py @@ -0,0 +1,51 @@ +from odoo import models, api, fields, _ +from odoo.tools import frozendict + +class SaleAdvancePaymentInv(models.TransientModel): + _inherit = 'sale.advance.payment.inv' + + + + def _prepare_down_payment_lines_values(self, order): + """ Modify the original method to remove tax based down payment lines values + this means we always create only one DownPayment SO Line. + """ + self.ensure_one() + + if self.advance_payment_method == 'percentage': + percentage = self.amount / 100 + else: + percentage = self.fixed_amount / order.amount_total if order.amount_total else 1 + + # Remove SO Lines that aare already linked with previous DownPayment Lines, and DP lines too. + base_downpayment_lines_values = self._prepare_base_downpayment_line_values(order) + + order_lines = order.order_line.filtered(lambda sol: not sol.display_type and not sol.is_downpayment) + + # We are skiping The tax calculation for the order_lines and splitting DP lines by Tax + # We are also ignoring any tax present on the DP Product itself, maybe revisit this if needed. + # This ensures the amount in DP is correctly reflected from the SO Lines for which DP is created. + # Using price_total which includes price+tax-disc + order_amount_incl_tax = 0.0 + for order_line in order_lines: + # The Delivery Product somehow has taxed amount in its price_total even when there is no tax applied. + if order_line.is_delivery and not order_line.tax_id: + order_amount_incl_tax += order_line.price_subtotal + else: + order_amount_incl_tax += order_line.price_total + # order_amount_incl_tax = sum(order_lines.mapped('price_total')) + + + analytic_distribution_order_lines = {} + for sol in order_lines.filtered(lambda ol: ol.analytic_distribution): + analytic_distribution_order_lines.update(sol.analytic_distribution) + base_downpayment_lines_values.update({ + 'price_unit': order.currency_id.round(order_amount_incl_tax * percentage), + 'product_uom_qty': 0.0, + 'discount': 0.0, + 'analytic_distribution': analytic_distribution_order_lines, + }) + + # We skip the logic to split the lines based on taxes present on SO lines. + + return [base_downpayment_lines_values] From 34fcd0929b786e50f61cf12ed4f415a3b67d1022 Mon Sep 17 00:00:00 2001 From: RLeeOSI <51208020+RLeeOSI@users.noreply.github.com> Date: Thu, 7 Nov 2024 14:46:37 -0800 Subject: [PATCH 2/2] [REF] pre-commit --- osi_downpayment_taxes/README.rst | 23 +++++++ osi_downpayment_taxes/__manifest__.py | 14 +++-- .../wizards/sale_make_invoice_advance.py | 60 +++++++++++-------- 3 files changed, 66 insertions(+), 31 deletions(-) create mode 100644 osi_downpayment_taxes/README.rst diff --git a/osi_downpayment_taxes/README.rst b/osi_downpayment_taxes/README.rst new file mode 100644 index 000000000..aed1aa977 --- /dev/null +++ b/osi_downpayment_taxes/README.rst @@ -0,0 +1,23 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +======== +Overview +======== + +* Correct rounding issues on taxes calculated on down payments + + +======= +Credits +======= + +* Open Source Integrators + + +Contributors +------------ + +* Tirth Patel +* Raphael Lee diff --git a/osi_downpayment_taxes/__manifest__.py b/osi_downpayment_taxes/__manifest__.py index 2604c4362..34f9c39e4 100644 --- a/osi_downpayment_taxes/__manifest__.py +++ b/osi_downpayment_taxes/__manifest__.py @@ -1,16 +1,18 @@ -{ +{ "name": "Sales Downpayment Tax Fixes", "summary": "Extends Sales Downpayments to fix sales lines made for multiple tax rates", "version": "17.0.1.0.0", + "license": "LGPL-3", "author": "Open Source Integrators", + "maintainer": "Open Source Integrators", + "website": "https://github.com/ursais/osi-addons", "category": "Accounting", "depends": [ - 'account_accountant', - 'sale', - ], - "data": [ + "account_accountant", + "sale", ], + "data": [], "application": False, "installable": True, - "auto_install": False + "auto_install": False, } diff --git a/osi_downpayment_taxes/wizards/sale_make_invoice_advance.py b/osi_downpayment_taxes/wizards/sale_make_invoice_advance.py index f1798ea45..329cd15e3 100644 --- a/osi_downpayment_taxes/wizards/sale_make_invoice_advance.py +++ b/osi_downpayment_taxes/wizards/sale_make_invoice_advance.py @@ -1,50 +1,60 @@ -from odoo import models, api, fields, _ -from odoo.tools import frozendict - -class SaleAdvancePaymentInv(models.TransientModel): - _inherit = 'sale.advance.payment.inv' +from odoo import models +class SaleAdvancePaymentInv(models.TransientModel): + _inherit = "sale.advance.payment.inv" def _prepare_down_payment_lines_values(self, order): - """ Modify the original method to remove tax based down payment lines values + """Modify the original method to remove tax based down payment lines values this means we always create only one DownPayment SO Line. """ self.ensure_one() - if self.advance_payment_method == 'percentage': + if self.advance_payment_method == "percentage": percentage = self.amount / 100 else: - percentage = self.fixed_amount / order.amount_total if order.amount_total else 1 - - # Remove SO Lines that aare already linked with previous DownPayment Lines, and DP lines too. - base_downpayment_lines_values = self._prepare_base_downpayment_line_values(order) - - order_lines = order.order_line.filtered(lambda sol: not sol.display_type and not sol.is_downpayment) - - # We are skiping The tax calculation for the order_lines and splitting DP lines by Tax - # We are also ignoring any tax present on the DP Product itself, maybe revisit this if needed. - # This ensures the amount in DP is correctly reflected from the SO Lines for which DP is created. + percentage = ( + self.fixed_amount / order.amount_total if order.amount_total else 1 + ) + + # Remove SO Lines that aare already linked with previous DownPayment Lines, + # and DP lines too. + base_downpayment_lines_values = self._prepare_base_downpayment_line_values( + order + ) + + order_lines = order.order_line.filtered( + lambda sol: not sol.display_type and not sol.is_downpayment + ) + + # We are skipping the tax calculation for the order_lines and splitting DP lines + # by Tax. We are also ignoring any tax present on the DP Product itself, + # maybe revisit this if needed. This ensures the amount in DP is correctly + # reflected from the SO Lines for which DP is created. # Using price_total which includes price+tax-disc order_amount_incl_tax = 0.0 for order_line in order_lines: - # The Delivery Product somehow has taxed amount in its price_total even when there is no tax applied. + # The Delivery Product somehow has taxed amount in its price_total + # even when there is no tax applied. if order_line.is_delivery and not order_line.tax_id: order_amount_incl_tax += order_line.price_subtotal else: order_amount_incl_tax += order_line.price_total # order_amount_incl_tax = sum(order_lines.mapped('price_total')) - analytic_distribution_order_lines = {} for sol in order_lines.filtered(lambda ol: ol.analytic_distribution): analytic_distribution_order_lines.update(sol.analytic_distribution) - base_downpayment_lines_values.update({ - 'price_unit': order.currency_id.round(order_amount_incl_tax * percentage), - 'product_uom_qty': 0.0, - 'discount': 0.0, - 'analytic_distribution': analytic_distribution_order_lines, - }) + base_downpayment_lines_values.update( + { + "price_unit": order.currency_id.round( + order_amount_incl_tax * percentage + ), + "product_uom_qty": 0.0, + "discount": 0.0, + "analytic_distribution": analytic_distribution_order_lines, + } + ) # We skip the logic to split the lines based on taxes present on SO lines.