Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[17.0][UPD] deltatech_Sale_commission modify based on percentage rules #1890

Merged
merged 2 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.1.9 | [![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.0 | [![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
3 changes: 2 additions & 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.1.9",
"version": "17.0.1.2.0",
"category": "Sales",
"author": "Terrabit, Dorin Hongu",
"website": "https://www.terrabit.ro",
Expand All @@ -19,6 +19,7 @@
"wizard/commission_compute_view.xml",
"wizard/update_purchase_price_view.xml",
"views/res_config_settings_views.xml",
"views/commission_condition_view.xml",
],
"images": ["static/description/main_screenshot.png"],
"development_status": "Mature",
Expand Down
1 change: 1 addition & 0 deletions deltatech_sale_commission/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
from . import account_invoice
from . import sale
from . import res_config_settings
from . import commission_condition
11 changes: 11 additions & 0 deletions deltatech_sale_commission/models/commission_condition.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from odoo import fields, models


class SaleMarginReport(models.Model):
_name = "sale.commission.condition"
_description = "Commission condition"

sequence = fields.Integer(string="Sequence", default=10)
percentage = fields.Float(string="Percentage", required=True, default=0.0, digits=(12, 3))
less_than_days = fields.Integer(string="Less Than Days", required=True, default=0)
# maximum_days = fields.Integer(string="Maximum Days", required=True, default=0)
1 change: 1 addition & 0 deletions deltatech_sale_commission/security/ir.model.access.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ access_sale_margin_report_user,Sale margin report,model_sale_margin_report,base.
access_commission_users,access_commission_users,model_commission_users,sales_team.group_sale_manager,1,1,1,1
access_commission_compute,access_commission_compute,model_commission_compute,base.group_user,1,1,1,1
access_commission_update_purchase_price,access_commission_update_purchase_price,model_commission_update_purchase_price,base.group_user,1,1,1,1
access_sale_commission_condition,access_sale_commission_condition,model_sale_commission_condition,base.group_user,1,1,1,1
35 changes: 35 additions & 0 deletions deltatech_sale_commission/views/commission_condition_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>


<record id="view_commission_conditions_tree" model="ir.ui.view">
<field name="name">Commission Conditions</field>
<field name="model">sale.commission.condition</field>
<field name="arch" type="xml">
<tree editable="top">
<field name="sequence" widget="handle" />
<field name="percentage" />
<field name="less_than_days" />
<!-- <field name="maximum_days" />-->
</tree>
</field>
</record>


<record id="action_commission_conditions" model="ir.actions.act_window">
<field name="name">Commission Conditions</field>
<field name="res_model">sale.commission.condition</field>
<field name="view_mode">tree</field>
</record>

<menuitem
name="Commission Conditions"
id="menu_commission_conditions"
action="action_commission_conditions"
parent="sale.menu_sale_config"
groups="sales_team.group_sale_manager"
/>



</odoo>
31 changes: 30 additions & 1 deletion deltatech_sale_commission/wizard/commission_compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,36 @@
def do_compute(self):
res = []
for line in self.invoice_line_ids:
value = {"commission": line.commission_computed}
commission_conditions = self.env["sale.commission.condition"].search([], order="less_than_days")

Check warning on line 37 in deltatech_sale_commission/wizard/commission_compute.py

View check run for this annotation

Codecov / codecov/patch

deltatech_sale_commission/wizard/commission_compute.py#L37

Added line #L37 was not covered by tests
# if we don't have commission conditions, we will use the default commission
if not commission_conditions:
value = {"commission": line.commission_computed}

Check warning on line 40 in deltatech_sale_commission/wizard/commission_compute.py

View check run for this annotation

Codecov / codecov/patch

deltatech_sale_commission/wizard/commission_compute.py#L40

Added line #L40 was not covered by tests
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"])[

Check warning on line 45 in deltatech_sale_commission/wizard/commission_compute.py

View check run for this annotation

Codecov / codecov/patch

deltatech_sale_commission/wizard/commission_compute.py#L45

Added line #L45 was not covered by tests
0
]
days_difference = (

Check warning on line 48 in deltatech_sale_commission/wizard/commission_compute.py

View check run for this annotation

Codecov / codecov/patch

deltatech_sale_commission/wizard/commission_compute.py#L48

Added line #L48 was not covered by tests
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}

Check warning on line 53 in deltatech_sale_commission/wizard/commission_compute.py

View check run for this annotation

Codecov / codecov/patch

deltatech_sale_commission/wizard/commission_compute.py#L53

Added line #L53 was not covered by tests
else:
checked = False

Check warning on line 55 in deltatech_sale_commission/wizard/commission_compute.py

View check run for this annotation

Codecov / codecov/patch

deltatech_sale_commission/wizard/commission_compute.py#L55

Added line #L55 was not covered by tests
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

Check warning on line 62 in deltatech_sale_commission/wizard/commission_compute.py

View check run for this annotation

Codecov / codecov/patch

deltatech_sale_commission/wizard/commission_compute.py#L60-L62

Added lines #L60 - L62 were not covered by tests
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}

Check warning on line 64 in deltatech_sale_commission/wizard/commission_compute.py

View check run for this annotation

Codecov / codecov/patch

deltatech_sale_commission/wizard/commission_compute.py#L64

Added line #L64 was not covered by tests
else:
value = {"commission": 0} # if the invoice is not paid, we will not calculate the commission

Check warning on line 66 in deltatech_sale_commission/wizard/commission_compute.py

View check run for this annotation

Codecov / codecov/patch

deltatech_sale_commission/wizard/commission_compute.py#L66

Added line #L66 was not covered by tests
# if line.purchase_price == 0 and line.product_id:
# value['purchase_price'] = line.product_id.standard_price
invoice_line = self.env["account.move.line"].browse(line.id)
Expand Down
Loading