mirror of
https://github.com/NaN-tic/trytond-commission_manager.git
synced 2023-12-14 04:03:00 +01:00
remove unnecessary code
This commit is contained in:
parent
003b43d0ad
commit
937bdad770
3 changed files with 4 additions and 76 deletions
|
@ -10,6 +10,5 @@ def register():
|
|||
Pool.register(
|
||||
commission.Manager,
|
||||
commission.Agent,
|
||||
commission.Commission,
|
||||
invoice.InvoiceLine,
|
||||
module='commission_manager', type_='model')
|
||||
|
|
|
@ -8,7 +8,7 @@ from trytond.pyson import Eval
|
|||
from trytond.transaction import Transaction
|
||||
from trytond.tools import decistmt
|
||||
|
||||
__all__ = ['Manager', 'Agent', 'Commission']
|
||||
__all__ = ['Manager', 'Agent']
|
||||
|
||||
|
||||
class Manager(ModelSQL, ModelView):
|
||||
|
@ -21,9 +21,6 @@ class Manager(ModelSQL, ModelView):
|
|||
('id', '!=', Eval('agent')),
|
||||
], depends=['agent'])
|
||||
company = fields.Many2One('company.company', 'Company', required=True)
|
||||
formula = fields.Char('Formula', required=True,
|
||||
help=('Python expression that will be evaluated with:\n'
|
||||
'- amount: the original amount'))
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
|
@ -38,81 +35,13 @@ class Manager(ModelSQL, ModelView):
|
|||
def default_company():
|
||||
return Transaction().context.get('company')
|
||||
|
||||
@staticmethod
|
||||
def default_formula():
|
||||
return 'amount'
|
||||
|
||||
def get_rec_name(self, name):
|
||||
return self.agent.rec_name
|
||||
|
||||
@classmethod
|
||||
def validate(cls, lines):
|
||||
super(Manager, cls).validate(lines)
|
||||
for line in lines:
|
||||
line.check_formula()
|
||||
|
||||
def get_context_formula(self, amount, product):
|
||||
return {
|
||||
'names': {
|
||||
'amount': amount,
|
||||
},
|
||||
}
|
||||
|
||||
def check_formula(self):
|
||||
context = self.get_context_formula(Decimal(0), None)
|
||||
|
||||
try:
|
||||
if not isinstance(self.get_amount(**context), Decimal):
|
||||
raise ValueError
|
||||
except ValueError as exception:
|
||||
self.raise_user_error('invalid_formula', {
|
||||
'formula': self.formula,
|
||||
'line': self.rec_name,
|
||||
'exception': exception,
|
||||
})
|
||||
|
||||
def get_amount(self, **context):
|
||||
'Return amount (as Decimal)'
|
||||
context.setdefault('functions', {})['Decimal'] = Decimal
|
||||
return simple_eval(decistmt(self.formula), **context)
|
||||
|
||||
|
||||
class Agent(metaclass=PoolMeta):
|
||||
class Agent:
|
||||
__metaclass__ = PoolMeta
|
||||
__name__ = 'commission.agent'
|
||||
manager = fields.Many2One('commission.manager', 'Manager',
|
||||
ondelete='CASCADE', select=True)
|
||||
|
||||
|
||||
class Commission(metaclass=PoolMeta):
|
||||
__name__ = 'commission'
|
||||
|
||||
@classmethod
|
||||
def _get_origin(cls):
|
||||
origins = super(Commission, cls)._get_origin()
|
||||
if not 'commission' in origins:
|
||||
origins += ['commission']
|
||||
return origins
|
||||
|
||||
def get_commission_manager(self):
|
||||
Commission = Pool().get('commission')
|
||||
|
||||
if not self.agent.manager.agent:
|
||||
return
|
||||
|
||||
manager = self.agent.manager
|
||||
context = manager.get_context_formula(self.amount, self.product)
|
||||
amount = manager.get_amount(**context)
|
||||
if amount:
|
||||
digits = Commission.amount.digits
|
||||
amount = amount.quantize(Decimal(str(10.0 ** -digits[1])))
|
||||
if not amount:
|
||||
return
|
||||
|
||||
commission = Commission()
|
||||
commission.origin = self
|
||||
if hasattr(self, 'date'):
|
||||
commission.date = self.date
|
||||
commission.agent = manager.agent
|
||||
commission.product = self.product
|
||||
commission.amount = amount
|
||||
return commission
|
||||
|
|
|
@ -29,5 +29,5 @@ class InvoiceLine(metaclass=PoolMeta):
|
|||
self.raise_user_error('manager_without_plan', {
|
||||
'manager': manager.rec_name,
|
||||
})
|
||||
used += [(manager.agent, manager.agent.plan)]
|
||||
used.append((manager.agent, manager.agent.plan))
|
||||
return used
|
||||
|
|
Loading…
Reference in a new issue