mirror of
https://github.com/NaN-tic/trytond-commission_manager.git
synced 2023-12-14 04:03:00 +01:00
apply plan from agent assigned to manager to calculate commission manager
This commit is contained in:
parent
998248c763
commit
003b43d0ad
4 changed files with 30 additions and 31 deletions
|
@ -11,5 +11,5 @@ def register():
|
|||
commission.Manager,
|
||||
commission.Agent,
|
||||
commission.Commission,
|
||||
invoice.Invoice,
|
||||
invoice.InvoiceLine,
|
||||
module='commission_manager', type_='model')
|
||||
|
|
39
invoice.py
39
invoice.py
|
@ -1,28 +1,33 @@
|
|||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
from trytond.pool import PoolMeta, Pool
|
||||
from trytond.pool import PoolMeta
|
||||
|
||||
__all__ = ['Invoice']
|
||||
__all__ = ['InvoiceLine']
|
||||
|
||||
|
||||
class Invoice(metaclass=PoolMeta):
|
||||
__name__ = 'account.invoice'
|
||||
class InvoiceLine(metaclass=PoolMeta):
|
||||
__name__ = 'account.invoice.line'
|
||||
__metaclass__ = PoolMeta
|
||||
|
||||
@classmethod
|
||||
def create_commissions(cls, invoices):
|
||||
Commission = Pool().get('commission')
|
||||
def __setup__(cls):
|
||||
super(InvoiceLine, cls).__setup__()
|
||||
|
||||
all_commissions = super(Invoice, cls).create_commissions(invoices)
|
||||
cls._error_messages.update({
|
||||
'manager_without_plan': ('No commission plan assigned '
|
||||
'for manager "%s"'),
|
||||
})
|
||||
|
||||
commissions_manager = []
|
||||
for commission in all_commissions:
|
||||
if commission.agent.manager:
|
||||
commission_manager = commission.get_commission_manager()
|
||||
if commission_manager:
|
||||
commissions_manager.append(commission_manager)
|
||||
def agent_plans_used(self):
|
||||
used = super(InvoiceLine, self).agent_plans_used()
|
||||
if not (self.invoice.agent and self.invoice.agent.manager):
|
||||
return used
|
||||
|
||||
if commissions_manager:
|
||||
Commission.save(commissions_manager)
|
||||
all_commissions += commissions_manager
|
||||
manager = self.invoice.agent.manager
|
||||
|
||||
return all_commissions
|
||||
if not manager.agent.plan:
|
||||
self.raise_user_error('manager_without_plan', {
|
||||
'manager': manager.rec_name,
|
||||
})
|
||||
used += [(manager.agent, manager.agent.plan)]
|
||||
return used
|
||||
|
|
|
@ -105,7 +105,6 @@ Create manager::
|
|||
|
||||
>>> manager = Manager()
|
||||
>>> manager.agent = agent_manager
|
||||
>>> manager.formula = 'amount*1.50'
|
||||
>>> manager.save()
|
||||
|
||||
Create some agents::
|
||||
|
@ -202,12 +201,11 @@ Create agent invoice::
|
|||
>>> invoice.save()
|
||||
>>> invoice.click('post')
|
||||
>>> line, = invoice.lines
|
||||
>>> len(line.commissions) == 2
|
||||
>>> len(line.commissions) == 3
|
||||
True
|
||||
>>> com1, com2 = line.commissions
|
||||
>>> origin = 'commission,%s' % com1.id
|
||||
>>> com_manager, = Commission.find([('agent', '=', agent_manager.id), ('origin', '=', origin)])
|
||||
>>> com_manager.amount == Decimal(15.00)
|
||||
>>> com1, com2, com3 = line.commissions
|
||||
>>> com_manager, = Commission.find([('agent', '=', agent_manager.id)])
|
||||
>>> com_manager.amount == Decimal(10.00)
|
||||
True
|
||||
>>> com1.amount == Decimal(10.00)
|
||||
True
|
||||
|
@ -223,12 +221,10 @@ Create agent invoice::
|
|||
>>> invoice.save()
|
||||
>>> invoice.click('post')
|
||||
>>> line, = invoice.lines
|
||||
>>> len(line.commissions) == 2
|
||||
>>> len(line.commissions) == 3
|
||||
True
|
||||
>>> com1, com2 = line.commissions
|
||||
>>> origin = 'commission,%s' % com1.id
|
||||
>>> com_manager, = Commission.find([('agent', '=', agent_manager.id), ('origin', '=', origin)])
|
||||
>>> com_manager.amount == Decimal(-15.00)
|
||||
>>> com1, com2, com3 = line.commissions
|
||||
>>> com3.amount == Decimal(-10.00)
|
||||
True
|
||||
>>> com1.amount == Decimal(-10.00)
|
||||
True
|
||||
|
|
|
@ -6,8 +6,6 @@ this repository contains the full copyright notices and license terms. -->
|
|||
<field name="agent"/>
|
||||
<label name="company"/>
|
||||
<field name="company"/>
|
||||
<label name="formula"/>
|
||||
<field name="formula"/>
|
||||
<separator name="agents" colspan="4"/>
|
||||
<field name="agents" colspan="4"/>
|
||||
</form>
|
||||
|
|
Loading…
Reference in a new issue