From 5cfe750282fe33a9bba7b5ba8195cac85c8391d8 Mon Sep 17 00:00:00 2001 From: VoicuStefan2001 Date: Mon, 27 Jan 2025 10:05:21 +0200 Subject: [PATCH 1/4] [17.0][UPD] deltatech_record_type --- README.md | 2 +- deltatech_record_type/__manifest__.py | 2 +- deltatech_record_type/models/sale.py | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d9a70cfe8..2c4d1992f 100644 --- a/README.md +++ b/README.md @@ -124,7 +124,7 @@ addon | version | maintainers | summary | price [deltatech_queue_job](deltatech_queue_job/) | 17.0.1.0.2 | [![dhongu](https://github.com/dhongu.png?size=30px)](https://github.com/dhongu) | Deltatech Queue Job | Free [deltatech_ral](deltatech_ral/) | 17.0.1.0.3 | | RAL | Free [deltatech_reception_note](deltatech_reception_note/) | 17.0.0.1.0 | [![dhongu](https://github.com/dhongu.png?size=30px)](https://github.com/dhongu) | Batch reception note | Free -[deltatech_record_type](deltatech_record_type/) | 17.0.1.1.3 | [![VoicuStefan2001](https://github.com/VoicuStefan2001.png?size=30px)](https://github.com/VoicuStefan2001) | Manage multiple record types | Free +[deltatech_record_type](deltatech_record_type/) | 17.0.1.1.4 | [![VoicuStefan2001](https://github.com/VoicuStefan2001.png?size=30px)](https://github.com/VoicuStefan2001) | Manage multiple record types | Free [deltatech_replenish](deltatech_replenish/) | 17.0.1.0.0 | [![dhongu](https://github.com/dhongu.png?size=30px)](https://github.com/dhongu) | Deltatech Replenish | Free [deltatech_report_packaging](deltatech_report_packaging/) | 17.0.1.0.2 | [![cojocariudaniel1](https://github.com/cojocariudaniel1.png?size=30px)](https://github.com/cojocariudaniel1) [![dhongu](https://github.com/dhongu.png?size=30px)](https://github.com/dhongu) | Report Packaging | Free [deltatech_report_prn](deltatech_report_prn/) | 17.0.1.0.4 | [![dhongu](https://github.com/dhongu.png?size=30px)](https://github.com/dhongu) | Raport PRN | Free diff --git a/deltatech_record_type/__manifest__.py b/deltatech_record_type/__manifest__.py index 68ece66ca..88860afcc 100644 --- a/deltatech_record_type/__manifest__.py +++ b/deltatech_record_type/__manifest__.py @@ -6,7 +6,7 @@ { "name": "Terrabit - Record Type", "summary": "Manage multiple record types", - "version": "17.0.1.1.3", + "version": "17.0.1.1.4", "author": "Terrabit, Voicu Stefan", "website": "https://www.terrabit.ro", "category": "Generic Modules/Other", diff --git a/deltatech_record_type/models/sale.py b/deltatech_record_type/models/sale.py index f7964a537..03a2559cf 100644 --- a/deltatech_record_type/models/sale.py +++ b/deltatech_record_type/models/sale.py @@ -9,6 +9,8 @@ class SaleOrder(models.Model): def action_confirm(self): for order in self: + if hasattr(order, "website_id") and order.website_id: + continue if not self.env.user.has_group("deltatech_record_type.group_confirm_order_without_record_type"): if not order.so_type: raise exceptions.UserError( From a7627990aed835ef97cc1421b29a22edddfc06ef Mon Sep 17 00:00:00 2001 From: VoicuStefan2001 Date: Mon, 27 Jan 2025 14:13:06 +0200 Subject: [PATCH 2/4] [17.0][UPD] deltatech_Sale_commission modify based on percentage rules --- README.md | 2 +- deltatech_sale_commission/__manifest__.py | 3 +- deltatech_sale_commission/models/__init__.py | 1 + .../models/commission_condition.py | 11 ++++++ .../security/ir.model.access.csv | 1 + .../views/commission_condition_view.xml | 35 +++++++++++++++++++ .../wizard/commission_compute.py | 29 ++++++++++++++- 7 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 deltatech_sale_commission/models/commission_condition.py create mode 100644 deltatech_sale_commission/views/commission_condition_view.xml diff --git a/README.md b/README.md index 2c4d1992f..423450ba8 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.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 diff --git a/deltatech_sale_commission/__manifest__.py b/deltatech_sale_commission/__manifest__.py index ac3a26a27..2a0b3fc75 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.1.9", + "version": "17.0.1.2.0", "category": "Sales", "author": "Terrabit, Dorin Hongu", "website": "https://www.terrabit.ro", @@ -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", diff --git a/deltatech_sale_commission/models/__init__.py b/deltatech_sale_commission/models/__init__.py index 612b94270..cf01e1df9 100644 --- a/deltatech_sale_commission/models/__init__.py +++ b/deltatech_sale_commission/models/__init__.py @@ -5,3 +5,4 @@ from . import account_invoice from . import sale from . import res_config_settings +from . import commission_condition diff --git a/deltatech_sale_commission/models/commission_condition.py b/deltatech_sale_commission/models/commission_condition.py new file mode 100644 index 000000000..2c2c911bb --- /dev/null +++ b/deltatech_sale_commission/models/commission_condition.py @@ -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) diff --git a/deltatech_sale_commission/security/ir.model.access.csv b/deltatech_sale_commission/security/ir.model.access.csv index c19c124ff..5a6fc4446 100644 --- a/deltatech_sale_commission/security/ir.model.access.csv +++ b/deltatech_sale_commission/security/ir.model.access.csv @@ -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 diff --git a/deltatech_sale_commission/views/commission_condition_view.xml b/deltatech_sale_commission/views/commission_condition_view.xml new file mode 100644 index 000000000..1e9879b5f --- /dev/null +++ b/deltatech_sale_commission/views/commission_condition_view.xml @@ -0,0 +1,35 @@ + + + + + + Commission Conditions + sale.commission.condition + + + + + + + + + + + + + Commission Conditions + sale.commission.condition + tree + + + + + + + diff --git a/deltatech_sale_commission/wizard/commission_compute.py b/deltatech_sale_commission/wizard/commission_compute.py index 89f465fa3..dd9e08da9 100644 --- a/deltatech_sale_commission/wizard/commission_compute.py +++ b/deltatech_sale_commission/wizard/commission_compute.py @@ -34,7 +34,34 @@ 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": + full_payment_date = fields.Date.to_date("1999-01-01") # took a date from the past + for payment in line.invoice_id.invoice_payments_widget[ + "content" + ]: # sometimes the payments don't reach invoice_payments_ids so we use the widget + if fields.Date.to_date(payment["date"]) > full_payment_date: + full_payment_date = fields.Date.to_date(payment["date"]) # get the latest payment date + days_difference = ( + full_payment_date - line.invoice_id.invoice_date + ).days # calculate the days difference between the invoice date and the payment date + 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) From 118016205711eef3bdbaf9531eef251028c50bf6 Mon Sep 17 00:00:00 2001 From: VoicuStefan2001 Date: Mon, 27 Jan 2025 15:36:05 +0200 Subject: [PATCH 3/4] upd logic --- .../wizard/commission_compute.py | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/deltatech_sale_commission/wizard/commission_compute.py b/deltatech_sale_commission/wizard/commission_compute.py index dd9e08da9..3547d66cb 100644 --- a/deltatech_sale_commission/wizard/commission_compute.py +++ b/deltatech_sale_commission/wizard/commission_compute.py @@ -41,25 +41,27 @@ 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": - full_payment_date = fields.Date.to_date("1999-01-01") # took a date from the past - for payment in line.invoice_id.invoice_payments_widget[ - "content" - ]: # sometimes the payments don't reach invoice_payments_ids so we use the widget - if fields.Date.to_date(payment["date"]) > full_payment_date: - full_payment_date = fields.Date.to_date(payment["date"]) # get the latest payment date + # take the latest payment date + last_payment = sorted(line.invoice_id.invoice_payments_widget["content"], key=lambda d: d["date"])[ + 0 + ] days_difference = ( - full_payment_date - line.invoice_id.invoice_date + 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 - 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} + + 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: From 46fd5ca005b8040141379d500abb575d758f0259 Mon Sep 17 00:00:00 2001 From: VoicuStefan2001 Date: Mon, 27 Jan 2025 16:33:17 +0200 Subject: [PATCH 4/4] [17.0][FIX] sale_commission --- README.md | 2 +- deltatech_sale_commission/__manifest__.py | 2 +- deltatech_sale_commission/models/commission_condition.py | 2 +- deltatech_sale_commission/wizard/commission_compute.py | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 423450ba8..0f8a3f342 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.0 | [![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.1 | [![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 2a0b3fc75..0adda3703 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.0", + "version": "17.0.1.2.1", "category": "Sales", "author": "Terrabit, Dorin Hongu", "website": "https://www.terrabit.ro", diff --git a/deltatech_sale_commission/models/commission_condition.py b/deltatech_sale_commission/models/commission_condition.py index 2c2c911bb..f22e50990 100644 --- a/deltatech_sale_commission/models/commission_condition.py +++ b/deltatech_sale_commission/models/commission_condition.py @@ -1,7 +1,7 @@ from odoo import fields, models -class SaleMarginReport(models.Model): +class SaleCommissionCondition(models.Model): _name = "sale.commission.condition" _description = "Commission condition" diff --git a/deltatech_sale_commission/wizard/commission_compute.py b/deltatech_sale_commission/wizard/commission_compute.py index 3547d66cb..4d62ca651 100644 --- a/deltatech_sale_commission/wizard/commission_compute.py +++ b/deltatech_sale_commission/wizard/commission_compute.py @@ -42,9 +42,9 @@ def do_compute(self): # 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 - ] + 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