Debian Codegraph @

addons/l10n_jo_edi/tests/jo_edi_common.py

raw
1 from odoo import Command
2 from odoo.tools import misc
3 from odoo.addons.account.tests.common import AccountTestInvoicingCommon
4
5
6 class JoEdiCommon(AccountTestInvoicingCommon):
7 @classmethod
8 @AccountTestInvoicingCommon.setup_country('jo')
9 def setUpClass(cls):
10 super().setUpClass()
11 cls.company_data['company'].write({
12 'name': 'Jordan Company',
13 'vat': '8000514',
14 })
15
16 def _get_general_tax(amount):
17 return cls.env['account.tax'].search([
18 ('amount', '=', amount),
19 ('amount_type', '=', 'percent'),
20 ('type_tax_use', '=', 'sale'),
21 ('company_id', '=', cls.company_data['company'].id)
22 ], limit=1)
23
24 def _create_special_tax(amount):
25 return cls.env['account.tax'].create(
26 {
27 'name': f'Fixed {amount}',
28 'amount_type': 'fixed',
29 'amount': amount,
30 'company_id': cls.company_data['company'].id,
31 'include_base_amount': True,
32 'is_base_affected': False,
33 'sequence': 0,
34 })
35
36 cls.jo_general_tax_10 = _get_general_tax(10)
37 cls.jo_special_tax_10 = _create_special_tax(10)
38 cls.jo_special_tax_5 = _create_special_tax(5)
39 cls.jo_general_tax_16 = _get_general_tax(16)
40 cls.jo_general_tax_16_included = cls.jo_general_tax_16.copy({'name': 'Tax 16% included'})
41 cls.jo_general_tax_16_included.price_include_override = 'tax_included'
42
43 cls.partner_jo = cls.env['res.partner'].create({
44 'name': 'Ahmad',
45 'ref': 'Jordan Partner',
46 'city': 'Amman',
47 'vat': '54321',
48 'zip': '94538',
49 'country_id': cls.env.ref('base.jo').id,
50 'state_id': cls.env.ref('base.state_jo_az').id,
51 'phone': '+962 795-5585-949',
52 'company_type': 'company',
53 })
54
55 # The rate of 1 USD = 2 JOD is meant to simplify tests
56 cls.usd = cls.env.ref('base.USD')
57 cls.setup_currency_rate(cls.usd, 0.5)
58
59 @classmethod
60 def setup_currency_rate(cls, currency, rate):
61 currency.sudo().update({
62 'rate_ids': [Command.clear()],
63 'active': True,
64 })
65 return cls.env['res.currency.rate'].create({
66 'name': '2019-01-01',
67 'rate': rate,
68 'currency_id': currency.id,
69 'company_id': cls.company_data['company'].id,
70 })
71
72 def _l10n_jo_create_invoice(self, invoice_vals):
73 invoice_vals.update({
74 'move_type': 'out_invoice',
75 'company_id': self.company.id,
76 'partner_id': self.partner_jo.id,
77 'invoice_date': invoice_vals.get('invoice_date', '2019-01-01'),
78 })
79 move = self.env['account.move'].create(invoice_vals)
80 move.action_post()
81 return move
82
83 def _l10n_jo_create_refund(self, invoice, return_reason, refund_vals):
84 invoice = self._l10n_jo_create_invoice(invoice) if isinstance(invoice, dict) else invoice
85 reversal = self.env['account.move.reversal'].with_context(active_model="account.move", active_ids=invoice.ids).create({
86 'reason': return_reason,
87 'journal_id': invoice.journal_id.id,
88 }).refund_moves()
89 reverse_move = self.env['account.move'].browse(reversal['res_id'])
90 if 'invoice_line_ids' in refund_vals:
91 # because they will be set by refund_vals
92 reverse_move.invoice_line_ids = [Command.clear()]
93 reverse_move.update(refund_vals)
94 reverse_move.action_post()
95 return reverse_move
96
97 def _read_xml_test_file(self, file_name):
98 with misc.file_open(f'l10n_jo_edi/tests/test_files/{file_name}.xml', 'rb') as file:
99 result_file = file.read()
100 return result_file