Skip to content

Commit

Permalink
[IMP] sale_commission: Backport improvements from 12.0
Browse files Browse the repository at this point in the history
* Add description to all models
* Adapt commission amount computation courtesy of Simone Rubi
* Adapt views
* Fixed dependencies in constraint
  • Loading branch information
pedrobaeza authored and fredzamoabg committed Jun 4, 2021
1 parent 4fc88a9 commit 8e8a849
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 34 deletions.
2 changes: 1 addition & 1 deletion sale_commission_formula/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{
'name': 'Sale Commission Formula',
'version': '11.0.1.1.0',
'version': '11.0.1.2.0',
'category': 'Sale',
'license': 'AGPL-3',
'summary': 'Sale commissions computed by formulas',
Expand Down
1 change: 0 additions & 1 deletion sale_commission_formula/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# License AGPL-3 - See https://www.gnu.org/licenses/agpl-3.0.html

from . import account_invoice
from . import sale_commission
from . import sale_commission_mixin
21 changes: 0 additions & 21 deletions sale_commission_formula/models/account_invoice.py

This file was deleted.

24 changes: 13 additions & 11 deletions sale_commission_formula/models/sale_commission_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@ def _get_formula_input_dict(self):
'self': self,
}

def _compute_amount(self):
applicable_lines = self.filtered(lambda x: (
not x.source_product_id.commission_free and x.commission
and x.commission.commission_type == 'formula'
))
for line in applicable_lines:
formula = line.commission.formula
results = line._get_formula_input_dict()
def _get_commission_amount(self, commission, subtotal, product, quantity):
"""Get the commission amount for the data given. To be called by
compute methods of children models.
"""
self.ensure_one()
if (not product.commission_free and commission and
commission.commission_type == 'formula'):
formula = commission.formula
results = self._get_formula_input_dict()
safe_eval(formula, results, mode="exec", nocopy=True)
line.amount = float(results['result'])
rest = self - applicable_lines
super(SaleCommissionLineMixin, rest)._compute_amount()
return float(results['result'])
return super()._get_commission_amount(
commission, subtotal, product, quantity,
)

0 comments on commit 8e8a849

Please sign in to comment.