File: payment.py

package info (click to toggle)
tryton-modules-account-payment-sepa-cfonb 5.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 236 kB
  • sloc: python: 185; xml: 182; makefile: 6; sh: 3
file content (50 lines) | stat: -rw-r--r-- 1,741 bytes parent folder | download | duplicates (2)
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
48
49
50
# This file is part of Tryton.  The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
import os

import genshi
import genshi.template

from trytond.pool import PoolMeta
from trytond.modules.account_payment_sepa import payment as sepa_payment


__all__ = ['Journal', 'Group']


class Journal(metaclass=PoolMeta):
    __name__ = 'account.payment.journal'

    @classmethod
    def __setup__(cls):
        super(Journal, cls).__setup__()
        payable_flavor_cfonb = ('pain.001.001.03-cfonb',
            'pain.001.001.03 CFONB')
        receivable_flavor_cfonb = ('pain.008.001.02-cfonb',
            'pain.008.001.02 CFONB')
        for flavor, field in [
                (payable_flavor_cfonb, cls.sepa_payable_flavor),
                (receivable_flavor_cfonb, cls.sepa_receivable_flavor),
                ]:
            if flavor not in field.selection:
                field.selection.append(flavor)

loader = genshi.template.TemplateLoader([
        os.path.join(os.path.dirname(__file__), 'template'),
        os.path.join(
            os.path.dirname(
                sepa_payment.__file__), 'template'),
        ], auto_reload=True)


class Group(metaclass=PoolMeta):
    __name__ = 'account.payment.group'

    def get_sepa_template(self):
        if (self.kind == 'payable'
                and self.journal.sepa_payable_flavor.endswith('-cfonb')):
            return loader.load('%s.xml' % self.journal.sepa_payable_flavor)
        if (self.kind == 'receivable'
                and self.journal.sepa_receivable_flavor.endswith('-cfonb')):
            return loader.load('%s.xml' % self.journal.sepa_receivable_flavor)
        return super(Group, self).get_sepa_template()