Use the invoice date or payment date for commission date
issue9643 review294601002
This commit is contained in:
1 parent
5578b1c86b
commit
1f4ce54caa
3 files changed
+48
-9
No files matched your search
@@ -1,3 +1,5 @@
|
||||
* Use the invoice date or payment date for commission date
|
||||
|
||||
Version 5.8.0 - 2020-11-02
|
||||
* Bug fixes (see mercurial logs for details)
|
||||
* Remove support for Python 3.5
|
||||
|
||||
+17
-8
@@ -1,5 +1,6 @@
|
||||
# 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 collections import defaultdict
|
||||
from trytond.pool import PoolMeta, Pool
|
||||
from trytond.model import ModelView, Workflow, fields
|
||||
from trytond.pyson import Eval, If, Bool
|
||||
@@ -62,15 +63,23 @@ class Invoice(metaclass=PoolMeta):
|
||||
|
||||
super(Invoice, cls).paid(invoices)
|
||||
|
||||
date2commissions = defaultdict(list)
|
||||
for sub_invoices in grouped_slice(invoices):
|
||||
ids = [i.id for i in sub_invoices]
|
||||
commissions = Commission.search([
|
||||
('date', '=', None),
|
||||
('origin.invoice', 'in', ids, 'account.invoice.line'),
|
||||
])
|
||||
Commission.write(commissions, {
|
||||
'date': today,
|
||||
})
|
||||
for commission in Commission.search([
|
||||
('date', '=', None),
|
||||
('origin.invoice', 'in', ids, 'account.invoice.line'),
|
||||
]):
|
||||
date = commission.origin.invoice.reconciled or today
|
||||
date2commissions[date].append(commission)
|
||||
to_write = []
|
||||
for date, commissions in date2commissions.items():
|
||||
to_write.append(commissions)
|
||||
to_write.append({
|
||||
'date': date,
|
||||
})
|
||||
if to_write:
|
||||
Commission.write(*to_write)
|
||||
|
||||
@classmethod
|
||||
@ModelView.button
|
||||
@@ -166,7 +175,7 @@ class InvoiceLine(metaclass=PoolMeta):
|
||||
commission = Commission()
|
||||
commission.origin = self
|
||||
if plan.commission_method == 'posting':
|
||||
commission.date = today
|
||||
commission.date = self.invoice.invoice_date or today
|
||||
commission.agent = agent
|
||||
commission.product = plan.commission_product
|
||||
commission.amount = amount
|
||||
|
||||
@@ -16,6 +16,7 @@ Imports::
|
||||
>>> from trytond.modules.account_invoice.tests.tools import \
|
||||
... set_fiscalyear_invoice_sequences, create_payment_term
|
||||
>>> today = datetime.date.today()
|
||||
>>> tomorrow = today + relativedelta(days=1)
|
||||
|
||||
Activate modules::
|
||||
|
||||
@@ -81,6 +82,19 @@ Create payment term::
|
||||
>>> payment_term = create_payment_term()
|
||||
>>> payment_term.save()
|
||||
|
||||
Create payment method::
|
||||
|
||||
>>> Journal = Model.get('account.journal')
|
||||
>>> PaymentMethod = Model.get('account.invoice.payment.method')
|
||||
>>> Sequence = Model.get('ir.sequence')
|
||||
>>> journal_cash, = Journal.find([('type', '=', 'cash')])
|
||||
>>> payment_method = PaymentMethod()
|
||||
>>> payment_method.name = 'Cash'
|
||||
>>> payment_method.journal = journal_cash
|
||||
>>> payment_method.credit_account = accounts['cash']
|
||||
>>> payment_method.debit_account = accounts['cash']
|
||||
>>> payment_method.save()
|
||||
|
||||
Create agent::
|
||||
|
||||
>>> Agent = Model.get('commission.agent')
|
||||
@@ -124,6 +138,7 @@ Create invoice::
|
||||
>>> invoice.party = customer
|
||||
>>> invoice.payment_term = payment_term
|
||||
>>> invoice.agent = agent
|
||||
>>> invoice.invoice_date
|
||||
>>> line = invoice.lines.new()
|
||||
>>> line.product = product
|
||||
>>> line.quantity = 1
|
||||
@@ -140,6 +155,8 @@ Post invoice::
|
||||
[Decimal('10.0000'), Decimal('10.0000')]
|
||||
>>> [c.invoice_state for c in line.commissions]
|
||||
['', '']
|
||||
>>> [c.date for c in line.commissions]
|
||||
[None, None]
|
||||
|
||||
Pending amount for agent::
|
||||
|
||||
@@ -153,6 +170,18 @@ Pending amount for principal::
|
||||
>>> principal.pending_amount
|
||||
Decimal('10.0000')
|
||||
|
||||
Pay invoice::
|
||||
|
||||
>>> pay = Wizard('account.invoice.pay', [invoice])
|
||||
>>> pay.form.payment_method = payment_method
|
||||
>>> pay.form.date = tomorrow
|
||||
>>> pay.execute('choice')
|
||||
>>> pay.state
|
||||
'end'
|
||||
>>> Commission = Model.get('commission')
|
||||
>>> [c.date == tomorrow for c in Commission.find([])]
|
||||
[True, True]
|
||||
|
||||
Create commission invoices::
|
||||
|
||||
>>> create_invoice = Wizard('commission.create_invoice')
|
||||
@@ -178,7 +207,6 @@ Create commission invoices::
|
||||
>>> invoice.total_amount
|
||||
Decimal('10.00')
|
||||
|
||||
>>> Commission = Model.get('commission')
|
||||
>>> commissions = Commission.find([])
|
||||
>>> [c.invoice_state for c in commissions]
|
||||
['invoiced', 'invoiced']
|
||||
|
||||
Reference in new issue
Block a user