Skip to content

Commit

Permalink
Merge pull request #1890 from VoicuStefan2001/17.0
Browse files Browse the repository at this point in the history
[17.0][UPD] deltatech_Sale_commission modify based on percentage rules
  • Loading branch information
VoicuStefan2001 authored Jan 27, 2025
2 parents d62f355 + 1180162 commit 94fc3b4
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 1 deletion.
1 change: 1 addition & 0 deletions deltatech_sale_commission/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 default_get(self, fields):
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")
# if we don't have commission conditions, we will use the default commission
if not commission_conditions:
value = {"commission": line.commission_computed}
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"])[
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:
# value['purchase_price'] = line.product_id.standard_price
invoice_line = self.env["account.move.line"].browse(line.id)
Expand Down

0 comments on commit 94fc3b4

Please sign in to comment.