From 909e71173ad6ebe16bd15cc5b72fd6b03237b554 Mon Sep 17 00:00:00 2001 From: VoicuStefan2001 Date: Wed, 29 Jan 2025 09:30:30 +0200 Subject: [PATCH] [17.0][FIX] deltatech_sale_commission invoices with 0 value --- README.md | 2 +- deltatech_sale_commission/__manifest__.py | 2 +- .../wizard/commission_compute.py | 42 ++++++++++--------- 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 0f8a3f342..100d13ee6 100644 --- a/README.md +++ b/README.md @@ -132,7 +132,7 @@ addon | version | maintainers | summary | price [deltatech_sale](deltatech_sale/) | 17.0.1.0.1 | [![dhongu](https://github.com/dhongu.png?size=30px)](https://github.com/dhongu) | Sale Extension Obsolete | Free [deltatech_sale_activity_search](deltatech_sale_activity_search/) | 17.0.0.0.0 | [![VoicuStefan2001](https://github.com/VoicuStefan2001.png?size=30px)](https://github.com/VoicuStefan2001) | Adds a field with the active activity types on that sale order | Free [deltatech_sale_add_extra_line](deltatech_sale_add_extra_line/) | 17.0.1.0.9 | [![dhongu](https://github.com/dhongu.png?size=30px)](https://github.com/dhongu) | Sale Add Extra Line | Free -[deltatech_sale_commission](deltatech_sale_commission/) | 17.0.1.2.1 | [![dhongu](https://github.com/dhongu.png?size=30px)](https://github.com/dhongu) | Compute sale commission | Free +[deltatech_sale_commission](deltatech_sale_commission/) | 17.0.1.2.2 | [![dhongu](https://github.com/dhongu.png?size=30px)](https://github.com/dhongu) | Compute sale commission | Free [deltatech_sale_contact](deltatech_sale_contact/) | 17.0.1.0.21 | [![dhongu](https://github.com/dhongu.png?size=30px)](https://github.com/dhongu) | Limit contacts insale order | Free [deltatech_sale_cost_product](deltatech_sale_cost_product/) | 17.0.0.0.2 | [![dhongu](https://github.com/dhongu.png?size=30px)](https://github.com/dhongu) | Sale Cost on Order | Free [deltatech_sale_feedback](deltatech_sale_feedback/) | 17.0.1.0.5 | [![dhongu](https://github.com/dhongu.png?size=30px)](https://github.com/dhongu) | Sale Feedback | Free diff --git a/deltatech_sale_commission/__manifest__.py b/deltatech_sale_commission/__manifest__.py index 0adda3703..00e6beca2 100644 --- a/deltatech_sale_commission/__manifest__.py +++ b/deltatech_sale_commission/__manifest__.py @@ -4,7 +4,7 @@ { "name": "Sale Commission", "summary": "Compute sale commission", - "version": "17.0.1.2.1", + "version": "17.0.1.2.2", "category": "Sales", "author": "Terrabit, Dorin Hongu", "website": "https://www.terrabit.ro", diff --git a/deltatech_sale_commission/wizard/commission_compute.py b/deltatech_sale_commission/wizard/commission_compute.py index 4d62ca651..ef55fbb38 100644 --- a/deltatech_sale_commission/wizard/commission_compute.py +++ b/deltatech_sale_commission/wizard/commission_compute.py @@ -41,27 +41,31 @@ def do_compute(self): else: # if the invoice is paid, we will calculate the commission based on the payment date if line.invoice_id.payment_state == "paid": - # take the latest payment date - last_payment = sorted( - line.invoice_id.invoice_payments_widget["content"], key=lambda d: d["date"], reverse=True - )[0] - days_difference = ( - fields.Date.to_date(last_payment["date"]) - line.invoice_id.invoice_date - ).days # calculate the days difference between the invoice date and the payment date - - if days_difference <= 0: + # second condition for the case where an invoice has 0 value because of a down payment + if not line.invoice_id.invoice_payments_widget: value = {"commission": line.commission_computed} else: - checked = False - for condition in commission_conditions: - if ( - days_difference <= condition.less_than_days - ): # they are ordered by less_than_days so we will get the first condition that is less than the days difference - checked = True - value = {"commission": line.commission_computed * condition.percentage / 100} - break - if not checked: # if we didn't find a condition that is less than the days difference, we will use the default commission - value = {"commission": 0} + # take the latest payment date + last_payment = sorted( + line.invoice_id.invoice_payments_widget["content"], key=lambda d: d["date"], reverse=True + )[0] + days_difference = ( + fields.Date.to_date(last_payment["date"]) - line.invoice_id.invoice_date + ).days # calculate the days difference between the invoice date and the payment date + + if days_difference <= 0: + value = {"commission": line.commission_computed} + else: + checked = False + for condition in commission_conditions: + if ( + days_difference <= condition.less_than_days + ): # they are ordered by less_than_days so we will get the first condition that is less than the days difference + checked = True + value = {"commission": line.commission_computed * condition.percentage / 100} + break + if not checked: # if we didn't find a condition that is less than the days difference, we will use the default commission + value = {"commission": 0} else: value = {"commission": 0} # if the invoice is not paid, we will not calculate the commission # if line.purchase_price == 0 and line.product_id: