File: test_module.py

package info (click to toggle)
tryton-modules-edocument-uncefact 7.0.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 924 kB
  • sloc: python: 495; xml: 136; makefile: 11; sh: 3
file content (137 lines) | stat: -rw-r--r-- 4,408 bytes parent folder | download
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# 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 datetime
import os
from decimal import Decimal
from unittest.mock import MagicMock, Mock

from lxml import etree

from trytond.pool import Pool
from trytond.tests.test_tryton import (
    ModuleTestCase, activate_module, with_transaction)


def get_invoice():
    pool = Pool()
    Address = pool.get('party.address')
    Company = pool.get('company.company')
    Country = pool.get('country.country')
    Currency = pool.get('currency.currency')
    Invoice = pool.get('account.invoice')
    InvoiceLine = pool.get('account.invoice.line')
    InvoiceTax = pool.get('account.invoice.tax')
    MoveLine = pool.get('account.move.line')
    Party = pool.get('party.party')
    PaymentTerm = pool.get('account.invoice.payment_term')
    Product = pool.get('product.product')
    Tax = pool.get('account.tax')
    Uom = pool.get('product.uom')

    address = Mock(spec=Address,
        street="St sample, 15",
        city="Scranton",
        postal_code="1000",
        subdivision=None,
        country=Mock(spec=Country,
            code='US'),
        )
    address.name = "Building A"
    address.country.name = "United States"
    party = Mock(spec=Party, addresses=[address])
    party.name = "Michael Scott"
    company = Mock(spec=Company,
        party=Mock(spec=Party,
        addresses=[Mock(spec=Address,
                    street="Main street, 42",
                    country=Mock(spec=Country,
                        code='US'))]))
    company.party.name = "Dunder Mifflin"
    company.party.address_get = Mock(return_value=company.party.addresses[0])
    taxes = [Mock(spec=InvoiceTax,
            tax=Mock(spec=Tax,
                unece_code='VAT',
                unece_category_code='S',
                legal_notice="Legal Notice",
                ),
            base=Decimal('100.00'),
            amount=Decimal('10.00'),
            legal_notice="Legal Notice",
            )]
    product = Mock(spec=Product,
        code="12345",
        type='service',
        )
    product.name = "Product"
    lines = [Mock(spec=InvoiceLine,
            type='line',
            product=product,
            unit=Mock(spec=Uom,
                unece_code='C62',
                ),
            quantity=1,
            unit_price=Decimal('100.0000'),
            amount=Decimal('100.00'),
            description="Description",
            invoice_taxes=taxes,
            )]
    invoice = MagicMock(spec=Invoice,
        id=-1,
        __int__=Mock(return_value=-1),
        type='out',
        number="001",
        party=party,
        party_lang='fr',
        invoice_address=party.addresses[0],
        company=company,
        currency=Mock(spec=Currency,
            code='USD',
            round=lambda a: a),
        invoice_date=datetime.date.today(),
        payment_term=Mock(spec=PaymentTerm, description="Direct"),
        lines=lines,
        taxes=taxes,
        untaxed_amount=Decimal('100.00'),
        tax_amount=Decimal('10.00'),
        total_amount=Decimal('110.00'),
        amount_to_pay=Decimal('110.00'),
        lines_to_pay=[Mock(spec=MoveLine,
                maturity_date=datetime.date.today(),
                amount_second_currency=None,
                debit=Decimal('110.00'),
                credit=0,
                )],
        sales=[],
        state='posted',
        )
    return invoice


class EDocumentUNCEFACTTestCase(ModuleTestCase):
    'Test EDocument UN/CEFACT module'
    module = 'edocument_uncefact'

    @classmethod
    def setUpClass(cls):
        super(EDocumentUNCEFACTTestCase, cls).setUpClass()
        activate_module('account_invoice')

    @with_transaction()
    def test_16B_CII_CrossIndustryInvoice(self):
        "Test 16B-CII CrossIndustryInvoice"
        pool = Pool()
        Template = pool.get('edocument.uncefact.invoice')
        invoice = get_invoice()
        template = Template(invoice)

        invoice_string = template.render('16B-CII')
        invoice_xml = etree.fromstring(invoice_string)
        schema_file = os.path.join(
            os.path.dirname(__file__),
            '16B-CII', 'data', 'standard', 'CrossIndustryInvoice_100pD16B.xsd')
        schema = etree.XMLSchema(etree.parse(schema_file))
        schema.assertValid(invoice_xml)


del ModuleTestCase