Files
enterprise-addons/l10n_mx_reports/tests/test_diot.py
T

314 lines
23 KiB
Python

# -*- coding: utf-8 -*-
# pylint: disable=bad-whitespace
from odoo import fields, Command
from odoo.tests import tagged
from odoo.exceptions import UserError
from odoo.addons.account_reports.tests.common import TestAccountReportsCommon
@tagged('post_install', 'post_install_l10n', '-at_install')
class TestDiot(TestAccountReportsCommon):
@classmethod
@TestAccountReportsCommon.setup_country('mx')
def setUpClass(cls):
super().setUpClass()
cls.env.companies.tax_exigibility = True
cls.env.companies.totals_below_sections = True # TODO should be automatic
cls.purchase_taxes = cls._get_purchase_taxes()
cls.partner_a.write({'country_id': cls.env.ref('base.mx').id, 'l10n_mx_type_of_operation': '85', 'vat': 'OTE2003102G1'})
cls.partner_b.write({'country_id': cls.env.ref('base.us').id, 'l10n_mx_type_of_operation': '85', 'vat': '12-3456789'})
@classmethod
def _get_purchase_taxes(cls):
taxes = cls.env['account.tax']
for i in [1, 2, 7, 8, 13, 14, 16, 18, 19, 20, 21, 22, 23]:
taxes += cls.env.ref(f'account.{cls.env.company.id}_tax{i}')
return taxes
def test_diot_report(self):
date_invoice = '2022-07-01'
moves_vals = []
for i, tax in enumerate(self.purchase_taxes):
for partner in (self.partner_a, self.partner_b):
moves_vals += [
{
'move_type': 'in_invoice',
'partner_id': partner.id,
'invoice_payment_term_id': False,
'invoice_date': date_invoice,
'date': date_invoice,
'invoice_line_ids': [Command.create({
'name': f'test {tax.amount}',
'quantity': 1,
'price_unit': 10 + 1 * i,
'tax_ids': [Command.set(tax.ids)],
})],
},
{
'move_type': 'in_refund',
'partner_id': partner.id,
'invoice_payment_term_id': False,
'invoice_date': date_invoice,
'date': date_invoice,
'invoice_line_ids': [Command.create({
'name': f'test {tax.amount}',
'quantity': 1,
'price_unit': 10 + 2 * i,
'tax_ids': [Command.set(tax.ids)],
})],
},
]
moves = self.env['account.move'].create(moves_vals)
moves.action_post()
for move in moves:
self.env['account.payment.register'].with_context(active_model='account.move', active_ids=move.ids).create({
'payment_date': date_invoice,
'journal_id': self.company_data['default_journal_bank'].id,
'amount': move.amount_total,
})._create_payments()
self.assertTrue(all(m.payment_state in ('paid', 'in_payment') for m in moves))
diot_report = self.env.ref('l10n_mx.diot_report')
options = self._generate_options(diot_report, fields.Date.from_string('2022-01-01'), fields.Date.from_string('2022-12-31'))
options['unfold_all'] = True
self.assertLinesValues(
diot_report._get_lines(options),
# 1-4: partner information
# 5-6: 8% N./refund, 7-8: 8% N./refund, 9-10: 16%/refund, 11-12: 16% imp/refund, 13-14: 16% int_imp/refund
# 15-19: creditable in same order, 20-24: non-creditable in same order
# 25: withheld, 26: exempt, 27: exempt imports, 28: 0%, 29: no tax object
[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],
[
('', '', '', '', 32.00, 3.52, 44.00, 5.44, 64.00, 14.08, 40.00, 9.60, 42.00, 10.24, 2.56, 3.52, 4.80, 6.40, 6.72, 0.00, 0.00, 5.44, 0.00, 0.00, -1.26, 0.00, -18.00, 28.00, 0.00),
('04', '85', 'OTE2003102G1', 'MEX', 16.00, 1.76, 22.00, 2.72, 32.00, 7.04, 20.00, 4.80, 21.00, 5.12, 1.28, 1.76, 2.40, 3.20, 3.36, 0.00, 0.00, 2.72, 0.00, 0.00, -0.63, 0.00, -9.00, 14.00, 0.00),
('', '', '', '', 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, -28.00, 0.00, 0.00),
('', '', '', '', 0.00, 0.00, 0.00, 2.72, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00),
('', '', '', '', 0.00, 0.00, 22.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00),
('', '', '', '', 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 1.76, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00),
('', '', '', '', 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 5.12, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00),
('', '', '', '', 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 21.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00),
('', '', '', '', 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 3.36, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00),
('', '', '', '', 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 4.80, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00),
('', '', '', '', 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 20.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00),
('', '', '', '', 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 3.20, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00),
('', '', '', '', 0.00, 0.00, 0.00, 0.00, 0.00, 3.84, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00),
('', '', '', '', 0.00, 0.00, 0.00, 0.00, 17.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00),
('', '', '', '', 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 2.72, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00),
('', '', '', '', 0.00, 1.76, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00),
('', '', '', '', 16.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00),
('', '', '', '', 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 1.28, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00),
('', '', '', '', 0.00, 0.00, 0.00, 0.00, 0.00, 3.20, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00),
('', '', '', '', 0.00, 0.00, 0.00, 0.00, 15.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00),
('', '', '', '', 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 2.40, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00),
('', '', '', '', 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 14.00, 0.00),
('', '', '', '', 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, -1.71, 0.00, 0.00, 0.00, 0.00),
('', '', '', '', 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 1.39, 0.00, 0.00, 0.00, 0.00),
('', '', '', '', 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, -1.49, 0.00, 0.00, 0.00, 0.00),
('', '', '', '', 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 1.28, 0.00, 0.00, 0.00, 0.00),
('', '', '', '', 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, -1.20, 0.00, 0.00, 0.00, 0.00),
('', '', '', '', 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 1.10, 0.00, 0.00, 0.00, 0.00),
('', '', '', '', 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, -0.40, 0.00, 0.00, 0.00, 0.00),
('', '', '', '', 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.40, 0.00, 0.00, 0.00, 0.00),
('', '', '', '', 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 19.00, 0.00, 0.00),
('04', '85', 'OTE2003102G1', 'MEX', 16.00, 1.76, 22.00, 2.72, 32.00, 7.04, 20.00, 4.80, 21.00, 5.12, 1.28, 1.76, 2.40, 3.20, 3.36, 0.00, 0.00, 2.72, 0.00, 0.00, -0.63, 0.00, -9.00, 14.00, 0.00),
('05', '85', '12-3456789', 'USA', 16.00, 1.76, 22.00, 2.72, 32.00, 7.04, 20.00, 4.80, 21.00, 5.12, 1.28, 1.76, 2.40, 3.20, 3.36, 0.00, 0.00, 2.72, 0.00, 0.00, -0.63, 0.00, -9.00, 14.00, 0.00),
('', '', '', '', 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, -28.00, 0.00, 0.00),
('', '', '', '', 0.00, 0.00, 0.00, 2.72, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00),
('', '', '', '', 0.00, 0.00, 22.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00),
('', '', '', '', 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 1.76, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00),
('', '', '', '', 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 5.12, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00),
('', '', '', '', 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 21.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00),
('', '', '', '', 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 3.36, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00),
('', '', '', '', 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 4.80, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00),
('', '', '', '', 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 20.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00),
('', '', '', '', 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 3.20, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00),
('', '', '', '', 0.00, 0.00, 0.00, 0.00, 0.00, 3.84, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00),
('', '', '', '', 0.00, 0.00, 0.00, 0.00, 17.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00),
('', '', '', '', 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 2.72, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00),
('', '', '', '', 0.00, 1.76, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00),
('', '', '', '', 16.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00),
('', '', '', '', 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 1.28, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00),
('', '', '', '', 0.00, 0.00, 0.00, 0.00, 0.00, 3.20, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00),
('', '', '', '', 0.00, 0.00, 0.00, 0.00, 15.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00),
('', '', '', '', 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 2.40, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00),
('', '', '', '', 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 14.00, 0.00),
('', '', '', '', 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, -1.71, 0.00, 0.00, 0.00, 0.00),
('', '', '', '', 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 1.39, 0.00, 0.00, 0.00, 0.00),
('', '', '', '', 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, -1.49, 0.00, 0.00, 0.00, 0.00),
('', '', '', '', 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 1.28, 0.00, 0.00, 0.00, 0.00),
('', '', '', '', 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, -1.20, 0.00, 0.00, 0.00, 0.00),
('', '', '', '', 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 1.10, 0.00, 0.00, 0.00, 0.00),
('', '', '', '', 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, -0.40, 0.00, 0.00, 0.00, 0.00),
('', '', '', '', 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.40, 0.00, 0.00, 0.00, 0.00),
('', '', '', '', 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 19.00, 0.00, 0.00),
('05', '85', '12-3456789', 'USA', 16.00, 1.76, 22.00, 2.72, 32.00, 7.04, 20.00, 4.80, 21.00, 5.12, 1.28, 1.76, 2.40, 3.20, 3.36, 0.00, 0.00, 2.72, 0.00, 0.00, -0.63, 0.00, -9.00, 14.00, 0.00),
('', '', '', '', 32.00, 3.52, 44.00, 5.44, 64.00, 14.08, 40.00, 9.60, 42.00, 10.24, 2.56, 3.52, 4.80, 6.40, 6.72, 0.00, 0.00, 5.44, 0.00, 0.00, -1.26, 0.00, -18.00, 28.00, 0.00),
],
options,
)
self.maxDiff = None
self.assertEqual(
self.env[diot_report.custom_handler_model_name].action_get_diot_txt(options)['file_content'].decode(),
"04|85|OTE2003102G1|||||16|2|22|3|32|7|20|5|21|5|1||2||2||3||3||||||||||3||||||||||||-1||-9|14|||01\n"
"05|85||12-3456789|partnerb|USA||16|2|22|3|32|7|20|5|21|5|1||2||2||3||3||||||||||3||||||||||||-1||-9|14|||01"
)
self.assertEqual(
self.env[diot_report.custom_handler_model_name].action_get_dpiva_txt(options)['file_content'].decode(),
"|1.0|2022|MES|Enero|1|1|||29|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|04|85|OTE2003102G1|||||2|||1|||3|||||14|-9|-1|14|\n"
"|1.0|2022|MES|Enero|1|1|||29|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|05|85||12-3456789|partnerb|USA|American|2|||1|||3|||||14|-9|-1|14|"
)
# Testing a Bill with 2+ taxes on the same line
multi_taxes = self.env['account.tax']
multi_taxes += self.env.ref(f'account.{self.env.company.id}_tax14') # IVA(16%) COMPRAS
multi_taxes += self.env.ref(f'account.{self.env.company.id}_tax1') # RET IVA FLETES 4%
multi_taxes += self.env.ref(f'account.{self.env.company.id}_tax2') # RET IVA ARRENDAMIENTO 10%
multi_tax_line_move = self.env['account.move'].create({
'move_type': 'in_invoice',
'partner_id': self.partner_a.id,
'invoice_payment_term_id': False,
'invoice_date': date_invoice,
'date': date_invoice,
'invoice_line_ids': [Command.create({
'name': 'test multi tax',
'quantity': 1,
'price_unit': 100,
'tax_ids': [Command.set(multi_taxes.ids)],
})]
})
multi_tax_line_move.action_post()
self.env['account.payment.register'].with_context(active_model='account.move', active_ids=multi_tax_line_move.ids).create({
'payment_date': date_invoice,
'journal_id': self.company_data['default_journal_bank'].id,
'amount': multi_tax_line_move.amount_total,
})._create_payments()
options = self._generate_options(diot_report, fields.Date.from_string('2022-01-01'), fields.Date.from_string('2022-12-31'))
self.assertLinesValues(
diot_report._get_lines(options),
# 1-4: partner information
# 5-6: 8% N./refund, 7-8: 8% N./refund, 9-10: 16%/refund, 11-12: 16% imp/refund, 13-14: 16% int_imp/refund
# 15-19: creditable in same order, 20-24: non-creditable in same order
# 25: withheld, 26: exempt, 27: exempt imports, 28: 0%, 29: no tax object
[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],
[
('', '', '', '', 32.00, 3.52, 44.00, 5.44, 164.00, 14.08, 40.00, 9.60, 42.00, 10.24, 2.56, 3.52, 20.80, 6.40, 6.72, 0.00, 0.00, 5.44, 0.00, 0.00, 12.74, 0.00, -18.00, 28.00, 0.00),
('04', '85', 'OTE2003102G1', 'MEX', 16.00, 1.76, 22.00, 2.72, 132.00, 7.04, 20.00, 4.80, 21.00, 5.12, 1.28, 1.76, 18.40, 3.20, 3.36, 0.00, 0.00, 2.72, 0.00, 0.00, 13.37, 0.00, -9.00, 14.00, 0.00),
('05', '85', '12-3456789', 'USA', 16.00, 1.76, 22.00, 2.72, 32.00, 7.04, 20.00, 4.80, 21.00, 5.12, 1.28, 1.76, 2.40, 3.20, 3.36, 0.00, 0.00, 2.72, 0.00, 0.00, -0.63, 0.00, -9.00, 14.00, 0.00),
('', '', '', '', 32.00, 3.52, 44.00, 5.44, 164.00, 14.08, 40.00, 9.60, 42.00, 10.24, 2.56, 3.52, 20.80, 6.40, 6.72, 0.00, 0.00, 5.44, 0.00, 0.00, 12.74, 0.00, -18.00, 28.00, 0.00),
],
options,
)
self.assertEqual(
self.env[diot_report.custom_handler_model_name].action_get_diot_txt(options)['file_content'].decode(),
"04|85|OTE2003102G1|||||16|2|22|3|132|7|20|5|21|5|1||2||18||3||3||||||||||3||||||||||||13||-9|14|||01\n"
"05|85||12-3456789|partnerb|USA||16|2|22|3|32|7|20|5|21|5|1||2||2||3||3||||||||||3||||||||||||-1||-9|14|||01"
)
def test_diot_report_with_refund(self):
date_invoice = '2022-07-01'
tax = self.env.ref(f'account.{self.env.company.id}_tax14')
move = self.env['account.move'].create({
'move_type': 'in_refund',
'partner_id': self.partner_a.id,
'invoice_date': date_invoice,
'date': date_invoice,
'invoice_line_ids': [Command.create({
'name': f'test {tax.amount}',
'quantity': 1,
'price_unit': 100,
'tax_ids': [Command.set(tax.ids)],
})]
})
move.action_post()
self.env['account.payment.register'].with_context(active_model='account.move', active_ids=move.ids).create({
'payment_date': date_invoice,
'journal_id': self.company_data['default_journal_bank'].id,
'amount': move.amount_total,
})._create_payments()
self.assertTrue(move.payment_state in ('paid', 'in_payment'))
diot_report = self.env.ref('l10n_mx.diot_report')
options = self._generate_options(diot_report, fields.Date.from_string('2022-01-01'), fields.Date.from_string('2022-12-31'))
self.assertLinesValues(
diot_report._get_lines(options),
# 1-4: partner information, 9: 16% total, 10: 16% refunds
[1, 2, 3, 4, 9, 10],
[
('', '', '', '', 0.00, 16.00),
('04', '85', 'OTE2003102G1', 'MEX', 0.00, 16.00),
('', '', '', '', 0.00, 16.00),
],
options,
)
self.assertEqual(
self.env[diot_report.custom_handler_model_name].action_get_diot_txt(options)['file_content'].decode(),
"04|85|OTE2003102G1||||||||||16|||||||||||||||||||||||||||||||||||||||||01")
self.assertEqual(
self.env[diot_report.custom_handler_model_name].action_get_dpiva_txt(options)['file_content'].decode(),
"|1.0|2022|MES|Enero|1|1|||1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|04|85|OTE2003102G1|||||||||||||||||||16|")
def test_diot_report_without_partner(self):
date_entry = '2022-07-01'
tax = self.env.ref(f'account.{self.env.company.id}_tax14')
diot_tag = tax.invoice_repartition_line_ids.tag_ids.filtered(lambda t: 'DIOT' in t.name)
line_vals = [
{
'account_id': self.company_data['default_account_expense'].id,
'debit': 100,
},
{
'account_id': self.company_data['default_account_tax_purchase'].id,
'debit': 16,
'tax_tag_ids': [Command.set(diot_tag.ids)],
},
{
'account_id': self.company_data['default_account_payable'].id,
'credit': 116,
},
]
moves = self.env['account.move'].create([
{
'move_type': 'entry',
'date': date_entry,
'line_ids': [
Command.create({**line, 'partner_id': self.partner_a.id if i == 0 else False})
for line in line_vals
]
} for i in range(2)
])
moves.action_post()
diot_report = self.env.ref('l10n_mx.diot_report')
options = self._generate_options(diot_report, fields.Date.from_string('2022-01-01'), fields.Date.from_string('2022-12-31'))
diot_report._init_currency_table(options)
with self.assertRaises(UserError, msg="The report cannot be generated because there are entries with tax amounts but no partner assigned."):
self.env[diot_report.custom_handler_model_name].action_get_diot_txt(options)