-
Notifications
You must be signed in to change notification settings - Fork 1
/
account_invoice.py
47 lines (39 loc) · 1.54 KB
/
account_invoice.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# For copyright and license terms, see COPYRIGHT.rst (top level of repository)
# Repository: https://github.com/C3S/collecting_society
from trytond.pool import PoolMeta
from trytond.model import fields, Workflow
__all__ = ['Invoice', 'InvoiceLine']
class Invoice(metaclass=PoolMeta):
__name__ = 'account.invoice'
allocation = fields.One2One(
'allocation-account.invoice', 'invoice', 'allocation',
'Invoice Allocation',
help='The allocation of the invoice')
distribution = fields.Many2One(
'distribution', 'Distribution',
help='The allocation of the invoice')
@classmethod
@Workflow.transition('paid')
def paid(cls, invoices):
# TODO: atomic transaction context
super(Invoice, cls).paid(invoices)
for invoice in invoices:
# licenser invoice
if not invoice.allocation:
continue
# licensee invoice
invoice.allocation.state = 'collected'
invoice.allocation.save()
# finish declarations
for utilisation in invoice.allocation.utilisations:
declaration = utilisation.declaration
if declaration.period == 'onetime':
declaration.state = 'finished'
declaration.save()
class InvoiceLine(metaclass=PoolMeta):
__name__ = 'account.invoice.line'
@classmethod
def _get_origin(cls):
models = super(InvoiceLine, cls)._get_origin()
models += ['utilisation', 'distribution']
return models