Skip to content

Commit

Permalink
Merge pull request #1892 from VoicuStefan2001/17.0
Browse files Browse the repository at this point in the history
[17.0][FIX] deltatech_sale_commission invoices with 0 value
  • Loading branch information
VoicuStefan2001 authored Jan 29, 2025
2 parents 7136b48 + 909e711 commit 68ed5bf
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion deltatech_sale_commission/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
42 changes: 23 additions & 19 deletions deltatech_sale_commission/wizard/commission_compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 68ed5bf

Please sign in to comment.