mirror of
https://github.com/bringout/oca-ocb-l10n_americas.git
synced 2026-04-26 22:11:59 +02:00
19.0 vanilla
This commit is contained in:
parent
89c6e82fe7
commit
1b82c20a58
572 changed files with 43570 additions and 53303 deletions
|
|
@ -1,6 +1,6 @@
|
|||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
from odoo import fields
|
||||
from odoo.tests.common import Form, tagged
|
||||
from odoo.tests import Form
|
||||
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
|
||||
import random
|
||||
import logging
|
||||
|
|
@ -9,16 +9,15 @@ import time
|
|||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class TestAr(AccountTestInvoicingCommon):
|
||||
class TestArCommon(AccountTestInvoicingCommon):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls, chart_template_ref='l10n_ar.l10nar_ri_chart_template'):
|
||||
super(TestAr, cls).setUpClass(chart_template_ref=chart_template_ref)
|
||||
@AccountTestInvoicingCommon.setup_chart_template('ar_ri')
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
|
||||
# ==== Company ====
|
||||
cls.company_data['company'].write({
|
||||
'parent_id': cls.env.ref('base.main_company').id,
|
||||
'currency_id': cls.env.ref('base.ARS').id,
|
||||
'name': '(AR) Responsable Inscripto (Unit Tests)',
|
||||
"l10n_ar_afip_start_date": time.strftime('%Y-01-01'),
|
||||
'l10n_ar_gross_income_type': 'local',
|
||||
|
|
@ -43,14 +42,12 @@ class TestAr(AccountTestInvoicingCommon):
|
|||
cls.partner_ri = cls.company_ri.partner_id
|
||||
|
||||
# ==== Company MONO ====
|
||||
cls.company_mono = cls.setup_company_data('(AR) Monotributista (Unit Tests)', chart_template=cls.env.ref('l10n_ar.l10nar_base_chart_template'))['company']
|
||||
cls.company_mono.write({
|
||||
'parent_id': cls.env.ref('base.main_company').id,
|
||||
'currency_id': cls.env.ref('base.ARS').id,
|
||||
'name': '(AR) Monotributista (Unit Tests)',
|
||||
"l10n_ar_afip_start_date": time.strftime('%Y-01-01'),
|
||||
'l10n_ar_gross_income_type': 'exempt',
|
||||
})
|
||||
cls.company_mono = cls._create_company(
|
||||
name='(AR) Monotributista (Unit Tests)',
|
||||
currency_id=cls.env.ref('base.ARS').id,
|
||||
l10n_ar_afip_start_date=time.strftime('%Y-01-01'),
|
||||
l10n_ar_gross_income_type='exempt',
|
||||
)
|
||||
cls.company_mono.partner_id.write({
|
||||
'name': '(AR) Monotributista (Unit Tests)',
|
||||
'l10n_ar_afip_responsibility_type_id': cls.env.ref("l10n_ar.res_RM").id,
|
||||
|
|
@ -72,6 +69,7 @@ class TestAr(AccountTestInvoicingCommon):
|
|||
'acc_number': '7982898111100056688080',
|
||||
'partner_id': cls.company_ri.partner_id.id,
|
||||
'company_id': cls.company_ri.id,
|
||||
'allow_out_payment': True,
|
||||
})
|
||||
|
||||
# ==== Partners / Customers ====
|
||||
|
|
@ -188,7 +186,7 @@ class TestAr(AccountTestInvoicingCommon):
|
|||
"type_tax_use": "sale",
|
||||
"country_id": cls.env.ref("base.ar").id,
|
||||
"company_id": cls.company_ri.id,
|
||||
"tax_group_id": cls.env.ref("l10n_ar.tax_group_national_taxes").id,
|
||||
"tax_group_id": cls.env.ref(f"account.{cls.company_ri.id}_tax_group_national_taxes").id,
|
||||
})
|
||||
cls.tax_internal = cls.env['account.tax'].create({
|
||||
"name": "Internal Tax",
|
||||
|
|
@ -198,7 +196,7 @@ class TestAr(AccountTestInvoicingCommon):
|
|||
"type_tax_use": "sale",
|
||||
"country_id": cls.env.ref("base.ar").id,
|
||||
"company_id": cls.company_ri.id,
|
||||
"tax_group_id": cls.env.ref("l10n_ar.tax_impuestos_internos").id,
|
||||
"tax_group_id": cls.env.ref(f"account.{cls.company_ri.id}_tax_impuestos_internos").id,
|
||||
})
|
||||
cls.tax_other = cls.env['account.tax'].create({
|
||||
"name": "Other Tax",
|
||||
|
|
@ -208,7 +206,7 @@ class TestAr(AccountTestInvoicingCommon):
|
|||
"type_tax_use": "sale",
|
||||
"country_id": cls.env.ref("base.ar").id,
|
||||
"company_id": cls.company_ri.id,
|
||||
"tax_group_id": cls.env.ref("l10n_ar.tax_group_otros_impuestos").id,
|
||||
"tax_group_id": cls.env.ref(f"account.{cls.company_ri.id}_tax_group_otros_impuestos").id,
|
||||
})
|
||||
|
||||
cls.tax_21_purchase = cls._search_tax(cls, 'iva_21', type_tax_use='purchase')
|
||||
|
|
@ -221,7 +219,6 @@ class TestAr(AccountTestInvoicingCommon):
|
|||
cls.product_iva_21 = cls.env['product.product'].create({
|
||||
'name': 'Large Cabinet (VAT 21)',
|
||||
'uom_id': uom_unit.id,
|
||||
'uom_po_id': uom_unit.id,
|
||||
'lst_price': 320.0,
|
||||
'standard_price': 800.0,
|
||||
'type': "consu",
|
||||
|
|
@ -231,7 +228,6 @@ class TestAr(AccountTestInvoicingCommon):
|
|||
# demo 'product_product_telefonia'
|
||||
'name': 'Telephone service (VAT 27)',
|
||||
'uom_id': uom_unit.id,
|
||||
'uom_po_id': uom_unit.id,
|
||||
'lst_price': 130.0,
|
||||
'standard_price': 250.0,
|
||||
'type': 'service',
|
||||
|
|
@ -242,7 +238,6 @@ class TestAr(AccountTestInvoicingCommon):
|
|||
# demo 'product_product_cero'
|
||||
'name': 'Non-industrialized animals and vegetables (VAT Zero)',
|
||||
'uom_id': uom_unit.id,
|
||||
'uom_po_id': uom_unit.id,
|
||||
'list_price': 160.0,
|
||||
'standard_price': 200.0,
|
||||
'type': 'consu',
|
||||
|
|
@ -253,7 +248,6 @@ class TestAr(AccountTestInvoicingCommon):
|
|||
# demo 'product.product_product_27'
|
||||
'name': 'Laptop Customized (VAT 10,5)',
|
||||
'uom_id': uom_unit.id,
|
||||
'uom_po_id': uom_unit.id,
|
||||
'standard_price': 4500.0,
|
||||
'type': 'consu',
|
||||
'default_code': '10,5',
|
||||
|
|
@ -263,7 +257,6 @@ class TestAr(AccountTestInvoicingCommon):
|
|||
# demo data product.product_product_2
|
||||
'name': 'Virtual Home Staging (VAT 21)',
|
||||
'uom_id': uom_hour.id,
|
||||
'uom_po_id': uom_hour.id,
|
||||
'list_price': 38.25,
|
||||
'standard_price': 45.5,
|
||||
'type': 'service',
|
||||
|
|
@ -274,17 +267,19 @@ class TestAr(AccountTestInvoicingCommon):
|
|||
# demo data product_product_no_gravado
|
||||
'name': 'Untaxed concepts (VAT NT)',
|
||||
'uom_id': uom_unit.id,
|
||||
'uom_po_id': uom_unit.id,
|
||||
'list_price': 40.00,
|
||||
'standard_price': 50.0,
|
||||
'type': 'consu',
|
||||
'default_code': 'NOGRAVADO',
|
||||
'taxes_id': [(6, 0, cls.tax_no_gravado.ids)],
|
||||
})
|
||||
cls.product_iva_105_perc = cls.product_iva_105.copy({
|
||||
cls.product_iva_105_perc = cls.env['product.product'].create({
|
||||
# product.product_product_25
|
||||
"name": "Laptop E5023 (VAT 10,5)",
|
||||
'uom_id': uom_unit.id,
|
||||
"standard_price": 3280.0,
|
||||
'type': 'consu',
|
||||
'default_code': '10,5',
|
||||
# agregamos percecipn aplicada y sufrida tambien
|
||||
'taxes_id': [(6, 0, [cls.tax_10_5.id, cls.tax_perc_iibb.id])],
|
||||
})
|
||||
|
|
@ -292,7 +287,6 @@ class TestAr(AccountTestInvoicingCommon):
|
|||
# demo product_product_exento
|
||||
'name': 'Book: Development in Odoo (VAT Exempt)',
|
||||
'uom_id': uom_unit.id,
|
||||
'uom_po_id': uom_unit.id,
|
||||
'standard_price': 100.0,
|
||||
"list_price": 80.0,
|
||||
'type': 'consu',
|
||||
|
|
@ -304,16 +298,14 @@ class TestAr(AccountTestInvoicingCommon):
|
|||
'name': 'Service WO TAX',
|
||||
'type': 'service',
|
||||
'uom_id': uom_unit.id,
|
||||
'uom_po_id': uom_unit.id,
|
||||
'default_code': 'AFIP_DESPACHO',
|
||||
'default_code': 'ARCA_DESPACHO',
|
||||
})
|
||||
cls.service_iva_no_gravado = cls.env['product.product'].create({
|
||||
# demo product_product_arancel
|
||||
'name': 'Server VAT Untaxed',
|
||||
'type': 'service',
|
||||
'uom_id': uom_unit.id,
|
||||
'uom_po_id': uom_unit.id,
|
||||
'default_code': 'AFIP_ARANCEL',
|
||||
'default_code': 'ARCA_ARANCEL',
|
||||
"supplier_taxes_id": [(6, 0, (cls.tax_no_gravado_purchase).ids)],
|
||||
})
|
||||
|
||||
|
|
@ -346,311 +338,290 @@ class TestAr(AccountTestInvoicingCommon):
|
|||
cls.demo_credit_notes = {}
|
||||
cls.demo_bills = {}
|
||||
|
||||
def _create_test_invoices_like_demo(self, use_current_date=True):
|
||||
""" Create in the unit tests the same invoices created in demo data """
|
||||
payment_term_id = self.env.ref("account.account_payment_term_end_following_month")
|
||||
invoice_user_id = self.env.user
|
||||
incoterm = self.env.ref("account.incoterm_EXW")
|
||||
@classmethod
|
||||
def _get_ar_multi_invoice_line_ids(cls):
|
||||
return [
|
||||
cls._prepare_invoice_line(product_id=cls.product_iva_105, price_unit=642.0, quantity=5),
|
||||
cls._prepare_invoice_line(product_id=cls.service_iva_27, price_unit=250.0, quantity=1),
|
||||
cls._prepare_invoice_line(product_id=cls.product_iva_105_perc, price_unit=3245.0, quantity=2),
|
||||
cls._prepare_invoice_line(product_id=cls.product_no_gravado, price_unit=50.0, quantity=10),
|
||||
cls._prepare_invoice_line(product_id=cls.product_iva_cero, price_unit=200.0, quantity=1),
|
||||
cls._prepare_invoice_line(product_id=cls.product_iva_exento, price_unit=100.0, quantity=1),
|
||||
]
|
||||
|
||||
decimal_price = self.env.ref('product.decimal_price')
|
||||
@classmethod
|
||||
def _create_test_invoices_like_demo(cls, use_current_date=True):
|
||||
""" Create in the unit tests the same invoices created in demo data """
|
||||
payment_term = cls.env.ref("account.account_payment_term_end_following_month")
|
||||
incoterm = cls.env.ref("account.incoterm_EXW")
|
||||
|
||||
decimal_price = cls.env.ref('product.decimal_price')
|
||||
decimal_price.digits = 4
|
||||
|
||||
invoices_to_create = {
|
||||
test_invoices_map = {
|
||||
'test_invoice_1': {
|
||||
"ref": "test_invoice_1: Invoice to gritti support service, vat 21",
|
||||
"partner_id": self.res_partner_gritti_mono,
|
||||
"invoice_payment_term_id": payment_term_id,
|
||||
"partner_id": cls.res_partner_gritti_mono,
|
||||
"invoice_payment_term_id": payment_term,
|
||||
"move_type": "out_invoice",
|
||||
"invoice_date": "2021-03-01",
|
||||
"company_id": self.company_ri,
|
||||
"company_id": cls.company_ri,
|
||||
"invoice_line_ids": [
|
||||
{'product_id': self.service_iva_21}
|
||||
cls._prepare_invoice_line(product_id=cls.service_iva_21),
|
||||
],
|
||||
},
|
||||
'test_invoice_2': {
|
||||
"ref": "test_invoice_2: Invoice to Servicios Globales with vat 21, 27 and 10,5",
|
||||
"partner_id": self.res_partner_servicios_globales,
|
||||
"invoice_payment_term_id": payment_term_id,
|
||||
"partner_id": cls.res_partner_servicios_globales,
|
||||
"invoice_payment_term_id": payment_term,
|
||||
"move_type": "out_invoice",
|
||||
"invoice_date": "2021-03-05",
|
||||
"company_id": self.company_ri,
|
||||
"company_id": cls.company_ri,
|
||||
"invoice_line_ids": [
|
||||
{'product_id': self.product_iva_105, 'price_unit': 642.0, 'quantity': 5},
|
||||
{'product_id': self.service_iva_27, 'price_unit': 250.0, 'quantity': 1},
|
||||
{'product_id': self.product_iva_105_perc, 'price_unit': 3245.0, 'quantity': 2}
|
||||
cls._prepare_invoice_line(product_id=cls.product_iva_105, price_unit=642.0, quantity=5),
|
||||
cls._prepare_invoice_line(product_id=cls.service_iva_27, price_unit=250.0, quantity=1),
|
||||
cls._prepare_invoice_line(product_id=cls.product_iva_105_perc, price_unit=3245.0, quantity=2),
|
||||
],
|
||||
},
|
||||
'test_invoice_3': {
|
||||
"ref": "test_invoice_3: Invoice to ADHOC with vat cero and 21",
|
||||
"partner_id": self.res_partner_adhoc,
|
||||
"invoice_payment_term_id": payment_term_id,
|
||||
"partner_id": cls.res_partner_adhoc,
|
||||
"invoice_payment_term_id": payment_term,
|
||||
"move_type": 'out_invoice',
|
||||
"invoice_date": "2021-03-01",
|
||||
"company_id": self.company_ri,
|
||||
"company_id": cls.company_ri,
|
||||
"invoice_line_ids": [
|
||||
{'product_id': self.product_iva_105, 'price_unit': 642.0, 'quantity': 5},
|
||||
{'product_id': self.product_iva_cero, 'price_unit': 200.0, 'quantity': 1}
|
||||
cls._prepare_invoice_line(product_id=cls.product_iva_105, price_unit=642.0, quantity=5),
|
||||
cls._prepare_invoice_line(product_id=cls.product_iva_cero, price_unit=200.0, quantity=1),
|
||||
],
|
||||
},
|
||||
'test_invoice_4': {
|
||||
'ref': 'test_invoice_4: Invoice to ADHOC with vat exempt and 21',
|
||||
"partner_id": self.res_partner_adhoc,
|
||||
"invoice_payment_term_id": payment_term_id,
|
||||
"partner_id": cls.res_partner_adhoc,
|
||||
"invoice_payment_term_id": payment_term,
|
||||
"move_type": 'out_invoice',
|
||||
"invoice_date": "2021-03-01",
|
||||
"company_id": self.company_ri,
|
||||
"company_id": cls.company_ri,
|
||||
"invoice_line_ids": [
|
||||
{'product_id': self.product_iva_105, 'price_unit': 642.1234, 'quantity': 5},
|
||||
{'product_id': self.product_iva_exento, 'price_unit': 100.5678, 'quantity': 1},
|
||||
cls._prepare_invoice_line(product_id=cls.product_iva_105, price_unit=642.1234, quantity=5),
|
||||
cls._prepare_invoice_line(product_id=cls.product_iva_exento, price_unit=100.5678, quantity=1),
|
||||
],
|
||||
},
|
||||
'test_invoice_5': {
|
||||
'ref': 'test_invoice_5: Invoice to ADHOC with all type of taxes',
|
||||
"partner_id": self.res_partner_adhoc,
|
||||
"invoice_payment_term_id": payment_term_id,
|
||||
"partner_id": cls.res_partner_adhoc,
|
||||
"invoice_payment_term_id": payment_term,
|
||||
"move_type": 'out_invoice',
|
||||
"invoice_date": "2021-03-13",
|
||||
"company_id": self.company_ri,
|
||||
"invoice_line_ids": [
|
||||
{'product_id': self.product_iva_105, 'price_unit': 642.0, 'quantity': 5},
|
||||
{'product_id': self.service_iva_27, 'price_unit': 250.0, 'quantity': 1},
|
||||
{'product_id': self.product_iva_105_perc, 'price_unit': 3245.0, 'quantity': 2},
|
||||
{'product_id': self.product_no_gravado, 'price_unit': 50.0, 'quantity': 10},
|
||||
{'product_id': self.product_iva_cero, 'price_unit': 200.0, 'quantity': 1},
|
||||
{'product_id': self.product_iva_exento, 'price_unit': 100.0, 'quantity': 1}
|
||||
],
|
||||
"company_id": cls.company_ri,
|
||||
"invoice_line_ids": cls._get_ar_multi_invoice_line_ids(),
|
||||
},
|
||||
'test_invoice_6': {
|
||||
'ref': 'test_invoice_6: Invoice to Montana Sur, fiscal position changes taxes to exempt',
|
||||
"partner_id": self.res_partner_montana_sur,
|
||||
"journal_id": self.sale_expo_journal_ri,
|
||||
"invoice_payment_term_id": payment_term_id,
|
||||
"partner_id": cls.res_partner_montana_sur,
|
||||
"journal_id": cls.sale_expo_journal_ri,
|
||||
"invoice_payment_term_id": payment_term,
|
||||
"move_type": 'out_invoice',
|
||||
"invoice_date": "2021-03-03",
|
||||
"company_id": self.company_ri,
|
||||
"company_id": cls.company_ri,
|
||||
"invoice_incoterm_id": incoterm,
|
||||
"invoice_line_ids": [
|
||||
{'product_id': self.product_iva_105, 'price_unit': 642.0, 'quantity': 5},
|
||||
{'product_id': self.service_iva_27, 'price_unit': 250.0, 'quantity': 1},
|
||||
{'product_id': self.product_iva_105_perc, 'price_unit': 3245.0, 'quantity': 2},
|
||||
{'product_id': self.product_no_gravado, 'price_unit': 50.0, 'quantity': 10},
|
||||
{'product_id': self.product_iva_cero, 'price_unit': 200.0, 'quantity': 1},
|
||||
{'product_id': self.product_iva_exento, 'price_unit': 100.0, 'quantity': 1},
|
||||
],
|
||||
"invoice_line_ids": cls._get_ar_multi_invoice_line_ids(),
|
||||
},
|
||||
'test_invoice_7': {
|
||||
'ref': 'test_invoice_7: Export invoice to Barcelona food, fiscal position changes tax to exempt (type 4 because it have services)',
|
||||
"partner_id": self.res_partner_barcelona_food,
|
||||
"journal_id": self.sale_expo_journal_ri,
|
||||
"invoice_payment_term_id": payment_term_id,
|
||||
"partner_id": cls.res_partner_barcelona_food,
|
||||
"journal_id": cls.sale_expo_journal_ri,
|
||||
"invoice_payment_term_id": payment_term,
|
||||
"move_type": 'out_invoice',
|
||||
"invoice_date": "2021-03-03",
|
||||
"company_id": self.company_ri,
|
||||
"company_id": cls.company_ri,
|
||||
"invoice_incoterm_id": incoterm,
|
||||
"invoice_line_ids": [
|
||||
{'product_id': self.product_iva_105, 'price_unit': 642.0, 'quantity': 5},
|
||||
{'product_id': self.service_iva_27, 'price_unit': 250.0, 'quantity': 1},
|
||||
{'product_id': self.product_iva_105_perc, 'price_unit': 3245.0, 'quantity': 2},
|
||||
{'product_id': self.product_no_gravado, 'price_unit': 50.0, 'quantity': 10},
|
||||
{'product_id': self.product_iva_cero, 'price_unit': 200.0, 'quantity': 1},
|
||||
{'product_id': self.product_iva_exento, 'price_unit': 100.0, 'quantity': 1},
|
||||
],
|
||||
"invoice_line_ids": cls._get_ar_multi_invoice_line_ids(),
|
||||
},
|
||||
'test_invoice_8': {
|
||||
'ref': 'test_invoice_8: Invoice to consumidor final',
|
||||
"partner_id": self.partner_cf,
|
||||
"invoice_payment_term_id": payment_term_id,
|
||||
"partner_id": cls.partner_cf,
|
||||
"invoice_payment_term_id": payment_term,
|
||||
"move_type": 'out_invoice',
|
||||
"invoice_date": "2021-03-13",
|
||||
"company_id": self.company_ri,
|
||||
"company_id": cls.company_ri,
|
||||
"invoice_line_ids": [
|
||||
{'product_id': self.service_iva_21, 'price_unit': 642.0, 'quantity': 1},
|
||||
cls._prepare_invoice_line(product_id=cls.service_iva_21, price_unit=642.0, quantity=1),
|
||||
],
|
||||
},
|
||||
'test_invoice_10': {
|
||||
'ref': 'test_invoice_10; Invoice to ADHOC in USD and vat 21',
|
||||
"partner_id": self.res_partner_adhoc,
|
||||
"invoice_payment_term_id": payment_term_id,
|
||||
"partner_id": cls.res_partner_adhoc,
|
||||
"invoice_payment_term_id": payment_term,
|
||||
"move_type": 'out_invoice',
|
||||
"invoice_date": "2021-03-13",
|
||||
"company_id": self.company_ri,
|
||||
"company_id": cls.company_ri,
|
||||
"invoice_line_ids": [
|
||||
{'product_id': self.product_iva_105, 'price_unit': 1000.0, 'quantity': 5},
|
||||
cls._prepare_invoice_line(product_id=cls.product_iva_105, price_unit=1000.0, quantity=5),
|
||||
],
|
||||
"currency_id": self.env.ref("base.USD"),
|
||||
"currency_id": cls.env.ref("base.USD"),
|
||||
},
|
||||
'test_invoice_11': {
|
||||
'ref': 'test_invoice_11: Invoice to ADHOC with many lines in order to prove rounding error, with 4 decimals of precision for the currency and 2 decimals for the product the error apperar',
|
||||
"partner_id": self.res_partner_adhoc,
|
||||
"invoice_payment_term_id": payment_term_id,
|
||||
"partner_id": cls.res_partner_adhoc,
|
||||
"invoice_payment_term_id": payment_term,
|
||||
"move_type": 'out_invoice',
|
||||
"invoice_date": "2021-03-13",
|
||||
"company_id": self.company_ri,
|
||||
"company_id": cls.company_ri,
|
||||
"invoice_line_ids": [
|
||||
{'product_id': self.service_iva_21, 'price_unit': 1.12, 'quantity': 1, 'name': 'Support Services 1'},
|
||||
{'product_id': self.service_iva_21, 'price_unit': 1.12, 'quantity': 1, 'name': 'Support Services 2'},
|
||||
{'product_id': self.service_iva_21, 'price_unit': 1.12, 'quantity': 1, 'name': 'Support Services 3'},
|
||||
{'product_id': self.service_iva_21, 'price_unit': 1.12, 'quantity': 1, 'name': 'Support Services 4'},
|
||||
cls._prepare_invoice_line(product_id=cls.service_iva_21, price_unit=1.12, quantity=1, name='Support Services 1'),
|
||||
cls._prepare_invoice_line(product_id=cls.service_iva_21, price_unit=1.12, quantity=1, name='Support Services 2'),
|
||||
cls._prepare_invoice_line(product_id=cls.service_iva_21, price_unit=1.12, quantity=1, name='Support Services 3'),
|
||||
cls._prepare_invoice_line(product_id=cls.service_iva_21, price_unit=1.12, quantity=1, name='Support Services 4'),
|
||||
],
|
||||
},
|
||||
'test_invoice_12': {
|
||||
'ref': 'test_invoice_12: Invoice to ADHOC with many lines in order to test rounding error, it is required to use a 4 decimal precision in prodct in order to the error occur',
|
||||
"partner_id": self.res_partner_adhoc,
|
||||
"invoice_payment_term_id": payment_term_id,
|
||||
"partner_id": cls.res_partner_adhoc,
|
||||
"invoice_payment_term_id": payment_term,
|
||||
"move_type": 'out_invoice',
|
||||
"invoice_date": "2021-03-13",
|
||||
"company_id": self.company_ri,
|
||||
"company_id": cls.company_ri,
|
||||
"invoice_line_ids": [
|
||||
{'product_id': self.service_iva_21, 'price_unit': 15.7076, 'quantity': 1, 'name': 'Support Services 1'},
|
||||
{'product_id': self.service_iva_21, 'price_unit': 5.3076, 'quantity': 2, 'name': 'Support Services 2'},
|
||||
{'product_id': self.service_iva_21, 'price_unit': 3.5384, 'quantity': 2, 'name': 'Support Services 3'},
|
||||
{'product_id': self.service_iva_21, 'price_unit': 1.6376, 'quantity': 2, 'name': 'Support Services 4'},
|
||||
cls._prepare_invoice_line(product_id=cls.service_iva_21, price_unit=15.7076, quantity=1, name='Support Services 1'),
|
||||
cls._prepare_invoice_line(product_id=cls.service_iva_21, price_unit=5.3076, quantity=2, name='Support Services 2'),
|
||||
cls._prepare_invoice_line(product_id=cls.service_iva_21, price_unit=3.5384, quantity=2, name='Support Services 3'),
|
||||
cls._prepare_invoice_line(product_id=cls.service_iva_21, price_unit=1.6376, quantity=2, name='Support Services 4'),
|
||||
],
|
||||
},
|
||||
'test_invoice_13': {
|
||||
'ref': 'test_invoice_13: Invoice to ADHOC with many lines in order to test zero amount invoices y rounding error. it is required to set the product decimal precision to 4 and change 260.59 for 260.60 in order to reproduce the error',
|
||||
"partner_id": self.res_partner_adhoc,
|
||||
"invoice_payment_term_id": payment_term_id,
|
||||
"partner_id": cls.res_partner_adhoc,
|
||||
"invoice_payment_term_id": payment_term,
|
||||
"move_type": 'out_invoice',
|
||||
"invoice_date": "2021-03-13",
|
||||
"company_id": self.company_ri,
|
||||
"company_id": cls.company_ri,
|
||||
"invoice_line_ids": [
|
||||
{'product_id': self.service_iva_21, 'price_unit': 24.3, 'quantity': 3, 'name': 'Support Services 1'},
|
||||
{'product_id': self.service_iva_21, 'price_unit': 260.59, 'quantity': 1, 'name': 'Support Services 2'},
|
||||
{'product_id': self.service_iva_21, 'price_unit': 48.72, 'quantity': 1, 'name': 'Support Services 3'},
|
||||
{'product_id': self.service_iva_21, 'price_unit': 13.666, 'quantity': 1, 'name': 'Support Services 4'},
|
||||
{'product_id': self.service_iva_21, 'price_unit': 11.329, 'quantity': 2, 'name': 'Support Services 5'},
|
||||
{'product_id': self.service_iva_21, 'price_unit': 68.9408, 'quantity': 1, 'name': 'Support Services 6'},
|
||||
{'product_id': self.service_iva_21, 'price_unit': 4.7881, 'quantity': 2, 'name': 'Support Services 7'},
|
||||
{'product_id': self.service_iva_21, 'price_unit': 12.0625, 'quantity': 2, 'name': 'Support Services 8'},
|
||||
cls._prepare_invoice_line(product_id=cls.service_iva_21, price_unit=24.3, quantity=3, name='Support Services 1'),
|
||||
cls._prepare_invoice_line(product_id=cls.service_iva_21, price_unit=260.59, quantity=1, name='Support Services 2'),
|
||||
cls._prepare_invoice_line(product_id=cls.service_iva_21, price_unit=48.72, quantity=1, name='Support Services 3'),
|
||||
cls._prepare_invoice_line(product_id=cls.service_iva_21, price_unit=13.666, quantity=1, name='Support Services 4'),
|
||||
cls._prepare_invoice_line(product_id=cls.service_iva_21, price_unit=11.329, quantity=2, name='Support Services 5'),
|
||||
cls._prepare_invoice_line(product_id=cls.service_iva_21, price_unit=68.9408, quantity=1, name='Support Services 6'),
|
||||
cls._prepare_invoice_line(product_id=cls.service_iva_21, price_unit=4.7881, quantity=2, name='Support Services 7'),
|
||||
cls._prepare_invoice_line(product_id=cls.service_iva_21, price_unit=12.0625, quantity=2, name='Support Services 8'),
|
||||
],
|
||||
},
|
||||
'test_invoice_14': {
|
||||
'ref': 'test_invoice_14: Export invoice to Barcelona food, fiscal position changes tax to exempt (type 1 because only products)',
|
||||
"partner_id": self.res_partner_barcelona_food,
|
||||
"journal_id": self.sale_expo_journal_ri,
|
||||
"invoice_payment_term_id": payment_term_id,
|
||||
"partner_id": cls.res_partner_barcelona_food,
|
||||
"journal_id": cls.sale_expo_journal_ri,
|
||||
"invoice_payment_term_id": payment_term,
|
||||
"move_type": 'out_invoice',
|
||||
"invoice_date": "2021-03-20",
|
||||
"company_id": self.company_ri,
|
||||
"company_id": cls.company_ri,
|
||||
"invoice_incoterm_id": incoterm,
|
||||
"invoice_line_ids": [
|
||||
{'product_id': self.product_iva_105, 'price_unit': 642.0, 'quantity': 5},
|
||||
cls._prepare_invoice_line(product_id=cls.product_iva_105, price_unit=642.0, quantity=5),
|
||||
],
|
||||
},
|
||||
'test_invoice_15': {
|
||||
'ref': 'test_invoice_15: Export invoice to Barcelona food, fiscal position changes tax to exempt (type 2 because only service)',
|
||||
"partner_id": self.res_partner_barcelona_food,
|
||||
"journal_id": self.sale_expo_journal_ri,
|
||||
"invoice_payment_term_id": payment_term_id,
|
||||
"partner_id": cls.res_partner_barcelona_food,
|
||||
"journal_id": cls.sale_expo_journal_ri,
|
||||
"invoice_payment_term_id": payment_term,
|
||||
"move_type": 'out_invoice',
|
||||
"invoice_date": "2021-03-20",
|
||||
"company_id": self.company_ri,
|
||||
"company_id": cls.company_ri,
|
||||
"invoice_incoterm_id": incoterm,
|
||||
"invoice_line_ids": [
|
||||
{'product_id': self.service_iva_27, 'price_unit': 250.0, 'quantity': 1},
|
||||
cls._prepare_invoice_line(product_id=cls.service_iva_27, price_unit=250.0, quantity=1),
|
||||
],
|
||||
},
|
||||
'test_invoice_16': {
|
||||
'ref': 'test_invoice_16: Export invoice to Barcelona food, fiscal position changes tax to exempt (type 1 because it have products only, used to test refund of expo)',
|
||||
"partner_id": self.res_partner_barcelona_food,
|
||||
"journal_id": self.sale_expo_journal_ri,
|
||||
"invoice_payment_term_id": payment_term_id,
|
||||
"partner_id": cls.res_partner_barcelona_food,
|
||||
"journal_id": cls.sale_expo_journal_ri,
|
||||
"invoice_payment_term_id": payment_term,
|
||||
"move_type": 'out_invoice',
|
||||
"invoice_date": "2021-03-22",
|
||||
"company_id": self.company_ri,
|
||||
"company_id": cls.company_ri,
|
||||
"invoice_incoterm_id": incoterm,
|
||||
"invoice_line_ids": [
|
||||
{'product_id': self.product_iva_105, 'price_unit': 642.0, 'quantity': 5},
|
||||
cls._prepare_invoice_line(product_id=cls.product_iva_105, price_unit=642.0, quantity=5),
|
||||
],
|
||||
},
|
||||
'test_invoice_17': {
|
||||
'ref': 'test_invoice_17: Invoice to ADHOC with 100%% of discount',
|
||||
"partner_id": self.res_partner_adhoc,
|
||||
"invoice_payment_term_id": payment_term_id,
|
||||
"partner_id": cls.res_partner_adhoc,
|
||||
"invoice_payment_term_id": payment_term,
|
||||
"move_type": 'out_invoice',
|
||||
"invoice_date": "2021-03-13",
|
||||
"company_id": self.company_ri,
|
||||
"company_id": cls.company_ri,
|
||||
"invoice_line_ids": [
|
||||
{'product_id': self.service_iva_21, 'price_unit': 24.3, 'quantity': 3, 'name': 'Support Services 8', 'discount': 100},
|
||||
cls._prepare_invoice_line(product_id=cls.service_iva_21, price_unit=24.3, quantity=3, name='Support Services 8', discount=100),
|
||||
],
|
||||
},
|
||||
'test_invoice_18': {
|
||||
'ref': 'test_invoice_18: Invoice to ADHOC with 100%% of discount and with different VAT aliquots',
|
||||
"partner_id": self.res_partner_adhoc,
|
||||
"invoice_payment_term_id": payment_term_id,
|
||||
"partner_id": cls.res_partner_adhoc,
|
||||
"invoice_payment_term_id": payment_term,
|
||||
"move_type": 'out_invoice',
|
||||
"invoice_date": "2021-03-13",
|
||||
"company_id": self.company_ri,
|
||||
"company_id": cls.company_ri,
|
||||
"invoice_line_ids": [
|
||||
{'product_id': self.service_iva_21, 'price_unit': 24.3, 'quantity': 3, 'name': 'Support Services 8', 'discount': 100},
|
||||
{'product_id': self.service_iva_27, 'price_unit': 250.0, 'quantity': 1, 'discount': 100},
|
||||
{'product_id': self.product_iva_105_perc, 'price_unit': 3245.0, 'quantity': 1},
|
||||
cls._prepare_invoice_line(product_id=cls.service_iva_21, price_unit=24.3, quantity=3, name='Support Services 8', discount=100),
|
||||
cls._prepare_invoice_line(product_id=cls.service_iva_27, price_unit=250.0, quantity=1, discount=100),
|
||||
cls._prepare_invoice_line(product_id=cls.product_iva_105_perc, price_unit=3245.0, quantity=1),
|
||||
],
|
||||
},
|
||||
'test_invoice_19': {
|
||||
'ref': 'test_invoice_19: Invoice to ADHOC with multiple taxes and perceptions',
|
||||
"partner_id": self.res_partner_adhoc,
|
||||
"invoice_payment_term_id": payment_term_id,
|
||||
"partner_id": cls.res_partner_adhoc,
|
||||
"invoice_payment_term_id": payment_term,
|
||||
"move_type": 'out_invoice',
|
||||
"invoice_date": "2021-03-13",
|
||||
"company_id": self.company_ri,
|
||||
"company_id": cls.company_ri,
|
||||
"invoice_line_ids": [
|
||||
{'product_id': self.service_iva_21, 'price_unit': 24.3, 'quantity': 3, 'name': 'Support Services 8'},
|
||||
{'product_id': self.service_iva_27, 'price_unit': 250.0, 'quantity': 1},
|
||||
{'product_id': self.product_iva_105_perc, 'price_unit': 3245.0, 'quantity': 1},
|
||||
cls._prepare_invoice_line(product_id=cls.service_iva_21, price_unit=24.3, quantity=3, name='Support Services 8'),
|
||||
cls._prepare_invoice_line(product_id=cls.service_iva_27, price_unit=250.0, quantity=1),
|
||||
cls._prepare_invoice_line(product_id=cls.product_iva_105_perc, price_unit=3245.0, quantity=1),
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
for key, values in invoices_to_create.items():
|
||||
with Form(self.env['account.move'].with_context(default_move_type=values['move_type'])) as invoice_form:
|
||||
invoice_form.ref = values['ref']
|
||||
invoice_form.partner_id = values['partner_id']
|
||||
invoice_form.invoice_payment_term_id = values['invoice_payment_term_id']
|
||||
if not use_current_date:
|
||||
invoice_form.invoice_date = values['invoice_date']
|
||||
if values.get('invoice_incoterm_id'):
|
||||
invoice_form.invoice_incoterm_id = values['invoice_incoterm_id']
|
||||
for line in values['invoice_line_ids']:
|
||||
with invoice_form.invoice_line_ids.new() as line_form:
|
||||
line_form.product_id = line.get('product_id')
|
||||
line_form.price_unit = line.get('price_unit')
|
||||
line_form.quantity = line.get('quantity')
|
||||
if line.get('tax_ids'):
|
||||
line_form.tax_ids = line.get('tax_ids')
|
||||
line_form.name = 'xxxx'
|
||||
line_form.account_id = self.company_data['default_account_revenue']
|
||||
invoice = invoice_form.save()
|
||||
self.demo_invoices[key] = invoice
|
||||
|
||||
def _create_invoice_from_dict(self, values, use_current_date=True):
|
||||
if not values.get('invoice_payment_term_id'):
|
||||
values['invoice_payment_term_id'] = self.env.ref("account.account_payment_term_end_following_month")
|
||||
if use_current_date:
|
||||
values.pop('invoice_date', False)
|
||||
|
||||
for key, value in values.items():
|
||||
if key.endswith("_id"):
|
||||
values[key] = value.id
|
||||
|
||||
for line in values['invoice_line_ids']:
|
||||
for key, value in line.items():
|
||||
if key.endswith("_id"):
|
||||
line[key] = value.id
|
||||
|
||||
values['invoice_line_ids'] = [(0, 0, line_data) for line_data in values['invoice_line_ids']]
|
||||
return self.env['account.move'].with_context(default_move_type=values['move_type']).create(values)
|
||||
for invoice_key, invoice_values in test_invoices_map.items():
|
||||
invoice_values.pop('invoice_date')
|
||||
cls.demo_invoices[invoice_key] = cls._create_invoice_ar(**invoice_values)
|
||||
else:
|
||||
for key, values in test_invoices_map.items():
|
||||
values['invoice_line_ids'] = [line_data for _, _, line_data in values['invoice_line_ids']]
|
||||
with Form(cls.env['account.move'].with_context(default_move_type=values['move_type'])) as invoice_form:
|
||||
invoice_form.ref = values['ref']
|
||||
invoice_form.partner_id = values['partner_id']
|
||||
invoice_form.invoice_payment_term_id = values['invoice_payment_term_id']
|
||||
invoice_form.invoice_date = values['invoice_date']
|
||||
if values.get('invoice_incoterm_id'):
|
||||
invoice_form.invoice_incoterm_id = values['invoice_incoterm_id']
|
||||
for line in values['invoice_line_ids']:
|
||||
with invoice_form.invoice_line_ids.new() as line_form:
|
||||
line_form.product_id = cls.env['product.product'].browse(line.get('product_id'))
|
||||
line_form.price_unit = line.get('price_unit')
|
||||
line_form.quantity = line.get('quantity')
|
||||
if line.get('tax_ids'):
|
||||
line_form.tax_ids = cls.env['account.tax'].browse(line.get('tax_ids'))
|
||||
line_form.name = 'xxxx'
|
||||
line_form.account_id = cls.company_data['default_account_revenue']
|
||||
cls.demo_invoices[key] = invoice_form.save()
|
||||
|
||||
# -------------------------------------------------------------------------
|
||||
# Helpers
|
||||
# -------------------------------------------------------------------------
|
||||
|
||||
@classmethod
|
||||
def _get_afip_pos_system_real_name(cls):
|
||||
return {'PREPRINTED': 'II_IM'}
|
||||
|
||||
def _create_journal(self, afip_ws, data=None):
|
||||
""" Create a journal of a given AFIP ws type.
|
||||
If there is a problem because we are using a AFIP certificate that is already been in use then change the certificate and try again """
|
||||
@classmethod
|
||||
def _create_journal(cls, afip_ws, data=None):
|
||||
""" Create a journal of a given ARCA ws type.
|
||||
If there is a problem because we are using a ARCA certificate that is already been in use then change the certificate and try again """
|
||||
data = data or {}
|
||||
afip_ws = afip_ws.upper()
|
||||
pos_number = str(random.randint(0, 99999))
|
||||
|
|
@ -659,97 +630,29 @@ class TestAr(AccountTestInvoicingCommon):
|
|||
values = {'name': '%s %s' % (afip_ws.replace('WS', ''), pos_number),
|
||||
'type': 'sale',
|
||||
'code': pos_number,
|
||||
'l10n_ar_afip_pos_system': self._get_afip_pos_system_real_name().get(afip_ws),
|
||||
'l10n_ar_afip_pos_system': cls._get_afip_pos_system_real_name().get(afip_ws),
|
||||
'l10n_ar_afip_pos_number': pos_number,
|
||||
'l10n_latam_use_documents': True,
|
||||
'company_id': self.env.company.id,
|
||||
'l10n_ar_afip_pos_partner_id': self.partner_ri.id,
|
||||
'company_id': cls.env.company.id,
|
||||
'l10n_ar_afip_pos_partner_id': cls.partner_ri.id,
|
||||
'sequence': 1}
|
||||
values.update(data)
|
||||
|
||||
journal = self.env['account.journal'].create(values)
|
||||
_logger.info('Created journal %s for company %s', journal.name, self.env.company.name)
|
||||
journal = cls.env['account.journal'].create(values)
|
||||
_logger.info('Created journal %s for company %s', journal.name, cls.env.company.name)
|
||||
return journal
|
||||
|
||||
def _create_invoice(self, data=None, invoice_type='out_invoice'):
|
||||
data = data or {}
|
||||
with Form(self.env['account.move'].with_context(default_move_type=invoice_type)) as invoice_form:
|
||||
invoice_form.partner_id = data.get('partner', self.partner)
|
||||
if 'in_' not in invoice_type:
|
||||
invoice_form.journal_id = data.get('journal', self.journal)
|
||||
|
||||
if data.get('document_type'):
|
||||
invoice_form.l10n_latam_document_type_id = data.get('document_type')
|
||||
if data.get('document_number'):
|
||||
invoice_form.l10n_latam_document_number = data.get('document_number')
|
||||
if data.get('incoterm'):
|
||||
invoice_form.invoice_incoterm_id = data.get('incoterm')
|
||||
if data.get('currency'):
|
||||
invoice_form.currency_id = data.get('currency')
|
||||
for line in data.get('lines', [{}]):
|
||||
with invoice_form.invoice_line_ids.new() as invoice_line_form:
|
||||
invoice_line_form.display_type = line.get('display_type', 'product')
|
||||
if line.get('display_type') in ('line_note', 'line_section'):
|
||||
invoice_line_form.name = line.get('name', 'not invoice line')
|
||||
else:
|
||||
invoice_line_form.product_id = line.get('product', self.product_iva_21)
|
||||
invoice_line_form.quantity = line.get('quantity', 1)
|
||||
invoice_line_form.price_unit = line.get('price_unit', 100)
|
||||
invoice_form.invoice_date = invoice_form.date
|
||||
invoice = invoice_form.save()
|
||||
return invoice
|
||||
|
||||
def _create_invoice_product(self, data=None):
|
||||
data = data or {}
|
||||
return self._create_invoice(data)
|
||||
|
||||
def _create_invoice_service(self, data=None):
|
||||
data = data or {}
|
||||
newlines = []
|
||||
for line in data.get('lines', [{}]):
|
||||
line.update({'product': self.service_iva_27})
|
||||
newlines.append(line)
|
||||
data.update({'lines': newlines})
|
||||
return self._create_invoice(data)
|
||||
|
||||
def _create_invoice_product_service(self, data=None):
|
||||
data = data or {}
|
||||
newlines = []
|
||||
for line in data.get('lines', [{}]):
|
||||
line.update({'product': self.product_iva_21})
|
||||
newlines.append(line)
|
||||
data.update({'lines': newlines + [{'product': self.service_iva_27}]})
|
||||
return self._create_invoice(data)
|
||||
|
||||
def _create_credit_note(self, invoice, data=None):
|
||||
data = data or {}
|
||||
refund_wizard = self.env['account.move.reversal'].with_context({'active_ids': [invoice.id], 'active_model': 'account.move'}).create({
|
||||
'reason': data.get('reason', 'Mercadería defectuosa'),
|
||||
'refund_method': data.get('refund_method', 'refund'),
|
||||
'journal_id': invoice.journal_id.id})
|
||||
|
||||
forced_document_type = data.get('document_type')
|
||||
if forced_document_type:
|
||||
refund_wizard.l10n_latam_document_type_id = forced_document_type.id
|
||||
|
||||
res = refund_wizard.reverse_moves()
|
||||
refund = self.env['account.move'].browse(res['res_id'])
|
||||
return refund
|
||||
|
||||
def _create_debit_note(self, invoice, data=None):
|
||||
data = data or {}
|
||||
debit_note_wizard = self.env['account.debit.note'].with_context(
|
||||
{'active_ids': [invoice.id], 'active_model': 'account.move', 'default_copy_lines': True}).create({
|
||||
'reason': data.get('reason', 'Mercadería defectuosa')})
|
||||
res = debit_note_wizard.create_debit()
|
||||
debit_note = self.env['account.move'].browse(res['res_id'])
|
||||
return debit_note
|
||||
@classmethod
|
||||
def _create_invoice_ar(cls, **invoice_args):
|
||||
invoice_args.setdefault('partner_id', cls.partner)
|
||||
invoice_args.setdefault('invoice_line_ids', [cls._prepare_invoice_line(price_unit=100, product_id=cls.product_iva_21)])
|
||||
return cls._create_invoice(**invoice_args)
|
||||
|
||||
def _search_tax(self, tax_type, type_tax_use='sale'):
|
||||
res = self.env['account.tax'].with_context(active_test=False).search([
|
||||
('type_tax_use', '=', type_tax_use),
|
||||
('company_id', '=', self.env.company.id),
|
||||
('tax_group_id', '=', self.env.ref('l10n_ar.tax_group_' + tax_type).id)], limit=1)
|
||||
('tax_group_id', '=', self.env.ref(f'account.{self.env.company.id}_tax_group_{tax_type}').id)], limit=1)
|
||||
self.assertTrue(res, '%s Tax was not found' % (tax_type))
|
||||
return res
|
||||
|
||||
|
|
@ -762,7 +665,7 @@ class TestAr(AccountTestInvoicingCommon):
|
|||
|
||||
def _prepare_multicurrency_values(self):
|
||||
# Enable multi currency
|
||||
self.env.user.write({'groups_id': [(4, self.env.ref('base.group_multi_currency').id)]})
|
||||
self.env.user.write({'group_ids': [(4, self.env.ref('base.group_multi_currency').id)]})
|
||||
# Set ARS as main currency
|
||||
self._set_today_rate(self.env.ref('base.ARS'), 1.0)
|
||||
# Set Rates for USD currency
|
||||
|
|
|
|||
|
|
@ -1,18 +1,22 @@
|
|||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
from unittest import skip
|
||||
|
||||
from . import common
|
||||
from odoo.tests import tagged
|
||||
from odoo import Command
|
||||
from odoo.tests import Form, tagged
|
||||
from odoo.tools.float_utils import float_split_str
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
@tagged('post_install_l10n', '-at_install', 'post_install')
|
||||
class TestManual(common.TestAr):
|
||||
class TestArManual(common.TestArCommon):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(TestManual, cls).setUpClass()
|
||||
cls.journal = cls._create_journal(cls, 'preprinted')
|
||||
super().setUpClass()
|
||||
cls.journal = cls._create_journal('preprinted')
|
||||
cls.partner = cls.res_partner_adhoc
|
||||
cls._create_test_invoices_like_demo(cls)
|
||||
cls._create_test_invoices_like_demo()
|
||||
|
||||
def test_01_create_invoice(self):
|
||||
""" Create and validate an invoice for a Responsable Inscripto
|
||||
|
|
@ -21,31 +25,33 @@ class TestManual(common.TestAr):
|
|||
* Properly set the tax amount of the product / partner
|
||||
* Proper fiscal position (this case not fiscal position is selected)
|
||||
"""
|
||||
invoice = self._create_invoice()
|
||||
invoice = self._create_invoice_ar()
|
||||
self.assertEqual(invoice.company_id, self.company_ri, 'created with wrong company')
|
||||
self.assertEqual(invoice.amount_tax, 21, 'invoice taxes are not properly set')
|
||||
self.assertEqual(invoice.amount_total, 121.0, 'invoice taxes has not been applied to the total')
|
||||
self.assertEqual(invoice.l10n_latam_document_type_id, self.document_type['invoice_a'], 'selected document type should be Factura A')
|
||||
self._post(invoice)
|
||||
self.assertEqual(invoice.state, 'posted', 'invoice has not been validate in Odoo')
|
||||
self.assertEqual(invoice.name, 'FA-A %05d-00000002' % self.journal.l10n_ar_afip_pos_number, 'Invoice number is wrong')
|
||||
self.assertEqual(invoice.name, 'FA-A %05d-00000001' % self.journal.l10n_ar_afip_pos_number, 'Invoice number is wrong')
|
||||
self.assertEqual(invoice.sequence_prefix, 'FA-A %05d-' % self.journal.l10n_ar_afip_pos_number)
|
||||
self.assertEqual(invoice.sequence_number, 1)
|
||||
|
||||
def test_02_fiscal_position(self):
|
||||
# ADHOC SA > IVA Responsable Inscripto > Without Fiscal Positon
|
||||
invoice = self._create_invoice({'partner': self.partner})
|
||||
invoice = self._create_invoice_ar(partner_id=self.partner)
|
||||
self.assertFalse(invoice.fiscal_position_id, 'Fiscal position should be set to empty')
|
||||
|
||||
# Consumidor Final > IVA Responsable Inscripto > Without Fiscal Positon
|
||||
invoice = self._create_invoice({'partner': self.partner_cf})
|
||||
invoice = self._create_invoice_ar(partner_id=self.partner_cf)
|
||||
self.assertFalse(invoice.fiscal_position_id, 'Fiscal position should be set to empty')
|
||||
|
||||
# Montana Sur > IVA Liberado - Ley Nº 19.640 > Compras / Ventas Zona Franca > IVA Exento
|
||||
invoice = self._create_invoice({'partner': self.res_partner_montana_sur})
|
||||
self.assertEqual(invoice.fiscal_position_id, self._search_fp('Compras / Ventas Zona Franca'))
|
||||
invoice = self._create_invoice_ar(partner_id=self.res_partner_montana_sur)
|
||||
self.assertEqual(invoice.fiscal_position_id, self._search_fp('Purchases / Sales Free Trade Zone'))
|
||||
|
||||
# Barcelona food > Cliente / Proveedor del Exterior > > IVA Exento
|
||||
invoice = self._create_invoice({'partner': self.res_partner_barcelona_food})
|
||||
self.assertEqual(invoice.fiscal_position_id, self._search_fp('Compras / Ventas al exterior'))
|
||||
invoice = self._create_invoice_ar(partner_id=self.res_partner_barcelona_food)
|
||||
self.assertEqual(invoice.fiscal_position_id, self._search_fp('Purchases / Sales abroad'))
|
||||
|
||||
def test_03_corner_cases(self):
|
||||
""" Mono partner of type Service and VAT 21 """
|
||||
|
|
@ -99,7 +105,83 @@ class TestManual(common.TestAr):
|
|||
self._prepare_multicurrency_values()
|
||||
self._post(self.demo_invoices['test_invoice_10'])
|
||||
|
||||
def test_15_corner_cases(self):
|
||||
def test_15_liquido_producto_sales(self):
|
||||
""" Manual Numbering: Sales and not POS (Liquido Producto) """
|
||||
|
||||
# Verify that the default sales journals ara created as is ARCA POS
|
||||
self.assertTrue(self.journal.l10n_ar_is_pos)
|
||||
|
||||
# If we create an invoice it will not use manual numbering
|
||||
invoice = self._create_invoice_ar()
|
||||
self.assertFalse(invoice.l10n_latam_manual_document_number)
|
||||
|
||||
# Create a new sale journal that is not ARCA POS
|
||||
self.journal = self._create_journal('preprinted', data={'l10n_ar_is_pos': False})
|
||||
self.assertFalse(self.journal.l10n_ar_is_pos)
|
||||
|
||||
doc_27_lu_a = self.env.ref('l10n_ar.dc_liq_uci_a')
|
||||
payment_term_id = self.env.ref("account.account_payment_term_end_following_month")
|
||||
|
||||
# 60, 61, 27, 28, 45, 46
|
||||
# In this case manual numbering should be True and the latam document numer should be required
|
||||
with self.assertRaisesRegex(AssertionError, 'l10n_latam_document_number is a required field'):
|
||||
with Form(self.env['account.move'].with_context(default_move_type='out_invoice')) as invoice_form:
|
||||
invoice_form.ref = "demo_liquido_producto_1: Vendor bill liquido producto (DOC 186)"
|
||||
invoice_form.partner_id = self.res_partner_adhoc
|
||||
invoice_form.invoice_payment_term_id = payment_term_id
|
||||
invoice_form.journal_id = self.journal
|
||||
invoice_form.l10n_latam_document_type_id = doc_27_lu_a
|
||||
invoice = invoice_form.save()
|
||||
|
||||
# Adding the document number will let us to save and validate the number without any problems
|
||||
with Form(self.env['account.move'].with_context(default_move_type='out_invoice')) as invoice_form:
|
||||
invoice_form.ref = "demo_liquido_producto_1: Vendor bill liquido producto (DOC 186)"
|
||||
invoice_form.partner_id = self.res_partner_adhoc
|
||||
invoice_form.invoice_payment_term_id = payment_term_id
|
||||
invoice_form.journal_id = self.journal
|
||||
invoice_form.l10n_latam_document_type_id = doc_27_lu_a
|
||||
invoice_form.l10n_latam_document_number = "00077-00000077"
|
||||
invoice = invoice_form.save()
|
||||
|
||||
def test_16_liquido_producto_purchase(self):
|
||||
""" Manual Numbering: Purchase POS/ NOT POS (Liquido Producto) """
|
||||
|
||||
# By default purchase journals ar not ARCA POS journal
|
||||
purchase_not_pos_journal = self.env["account.journal"].search([
|
||||
('type', '=', 'purchase'), ('company_id', '=', self.env.company.id), ('l10n_latam_use_documents', '=', True)])
|
||||
self.assertFalse(purchase_not_pos_journal.l10n_ar_is_pos)
|
||||
|
||||
doc_60_lp_a = self.env.ref('l10n_ar.dc_a_cvl')
|
||||
payment_term_id = self.env.ref("account.account_payment_term_end_following_month")
|
||||
|
||||
with self.assertRaisesRegex(AssertionError, 'l10n_latam_document_number is a required field'):
|
||||
with Form(self.env['account.move'].with_context(default_move_type='in_invoice')) as bill_form:
|
||||
bill_form.ref = "demo_liquido_producto_1: Vendor bill liquido producto (DOC 186)"
|
||||
bill_form.partner_id = self.res_partner_adhoc
|
||||
bill_form.invoice_payment_term_id = payment_term_id
|
||||
bill_form.invoice_date = '2023-02-09'
|
||||
bill_form.l10n_latam_document_type_id = doc_60_lp_a
|
||||
bill = bill_form.save()
|
||||
|
||||
self.assertEqual(bill.journal_id, purchase_not_pos_journal)
|
||||
|
||||
# Create a new journal that is an ARCA POS
|
||||
purchase_pos_journal = self._create_journal('preprinted', data={'type': 'purchase', 'l10n_ar_is_pos': True})
|
||||
|
||||
with Form(self.env['account.move'].with_context(default_move_type='in_invoice')) as bill_form:
|
||||
bill_form.ref = "demo_liquido_producto_1: Vendor bill liquido producto (DOC 186)"
|
||||
bill_form.partner_id = self.res_partner_adhoc
|
||||
bill_form.invoice_payment_term_id = payment_term_id
|
||||
bill_form.invoice_date = '2023-02-09'
|
||||
bill_form.journal_id = purchase_pos_journal
|
||||
bill_form.l10n_latam_document_type_id = doc_60_lp_a
|
||||
bill_form.l10n_latam_document_number = "00077-00000077"
|
||||
bill = bill_form.save()
|
||||
|
||||
# If we create an invoice it will not use manual numbering
|
||||
self.assertFalse(bill.l10n_latam_manual_document_number)
|
||||
|
||||
def test_17_corner_cases(self):
|
||||
""" RI partner with VAT exempt and 21. Test price unit digits """
|
||||
self._post(self.demo_invoices['test_invoice_4'])
|
||||
decimal_price_digits_setting = self.env.ref('product.decimal_price').digits
|
||||
|
|
@ -113,61 +195,217 @@ class TestManual(common.TestAr):
|
|||
if len_l10n_ar_price_unit_digits == len_line_price_unit_digits == decimal_price_digits_setting:
|
||||
self.assertEqual(l10n_ar_price_unit_decimal_part, line_price_unit_decimal_part)
|
||||
|
||||
def _get_simple_detail_ar_tax(self, invoice):
|
||||
""" Get the simple detail_ar_tax list of tuples with the vat group name and the amount
|
||||
[("vat_taxes", float), ("other_taxes", float)] """
|
||||
return [
|
||||
(item.get('group'), item.get('tax_amount'))
|
||||
for item in invoice._l10n_ar_get_invoice_totals_for_report().get('detail_ar_tax')
|
||||
]
|
||||
|
||||
def test_16_invoice_b_tax_breakdown_1(self):
|
||||
def test_18_invoice_b_tax_breakdown_1(self):
|
||||
""" Display Both VAT and Other Taxes """
|
||||
invoice1 = self._create_invoice_from_dict({
|
||||
'ref': 'test_invoice_20: Final Consumer Invoice B with multiple vat/perceptions/internal/other/national taxes',
|
||||
"move_type": 'out_invoice',
|
||||
"partner_id": self.partner_cf,
|
||||
"company_id": self.company_ri,
|
||||
"invoice_date": "2021-03-20",
|
||||
"invoice_line_ids": [
|
||||
{'product_id': self.service_iva_21, 'price_unit': 124.3, 'quantity': 3, 'name': 'Support Services 8',
|
||||
'tax_ids': [(6, 0, [self.tax_21.id, self.tax_perc_iibb.id])]},
|
||||
{'product_id': self.service_iva_27, 'price_unit': 2250.0, 'quantity': 1,
|
||||
'tax_ids': [(6, 0, [self.tax_27.id, self.tax_national.id])]},
|
||||
{'product_id': self.product_iva_105_perc, 'price_unit': 1740.0, 'quantity': 1,
|
||||
'tax_ids': [(6, 0, [self.tax_10_5.id, self.tax_internal.id])]},
|
||||
{'product_id': self.product_iva_105_perc, 'price_unit': 10000.0, 'quantity': 1,
|
||||
'tax_ids': [(6, 0, [self.tax_0.id, self.tax_other.id])]},
|
||||
invoice = self._create_invoice_ar(
|
||||
ref='test_invoice_20: Final Consumer Invoice B with multiple vat/perceptions/internal/other/national taxes',
|
||||
partner_id=self.partner_cf,
|
||||
company_id=self.company_ri,
|
||||
invoice_date="2021-03-20",
|
||||
invoice_line_ids=[
|
||||
self._prepare_invoice_line(product_id=self.service_iva_21, price_unit=124.3, quantity=3, name='Support Services 8', tax_ids=self.tax_21 + self.tax_perc_iibb),
|
||||
self._prepare_invoice_line(product_id=self.service_iva_27, price_unit=2250.0, tax_ids=self.tax_27 + self.tax_national),
|
||||
self._prepare_invoice_line(product_id=self.product_iva_105_perc, price_unit=1740.0, tax_ids=self.tax_10_5 + self.tax_internal),
|
||||
self._prepare_invoice_line(product_id=self.product_iva_105_perc, price_unit=10000.0, tax_ids=self.tax_0 + self.tax_other),
|
||||
],
|
||||
)
|
||||
results = invoice._l10n_ar_get_invoice_custom_tax_summary_for_report()
|
||||
self.assertEqual(results, [
|
||||
{
|
||||
'tax_amount_currency': 868.51,
|
||||
'formatted_tax_amount_currency': '868.51',
|
||||
'name': 'VAT Content $',
|
||||
},
|
||||
{
|
||||
'tax_amount_currency': 142.20,
|
||||
'formatted_tax_amount_currency': '142.20',
|
||||
'name': 'Other National Ind. Taxes $',
|
||||
},
|
||||
])
|
||||
self._assert_tax_totals_summary(invoice._l10n_ar_get_invoice_totals_for_report(), {
|
||||
'same_tax_base': False,
|
||||
'currency_id': self.currency.id,
|
||||
'base_amount_currency': 15373.61,
|
||||
'tax_amount_currency': 100.0,
|
||||
'total_amount_currency': 15473.61,
|
||||
'subtotals': [
|
||||
{
|
||||
'name': "Untaxed Amount",
|
||||
'base_amount_currency': 15373.61,
|
||||
'tax_amount_currency': 100.0,
|
||||
'tax_groups': [
|
||||
{
|
||||
'id': self.tax_perc_iibb.tax_group_id.id,
|
||||
'base_amount_currency': 372.9,
|
||||
'tax_amount_currency': 0.0,
|
||||
'display_base_amount_currency': 372.9,
|
||||
},
|
||||
{
|
||||
'id': self.tax_other.tax_group_id.id,
|
||||
'base_amount_currency': 10000.0,
|
||||
'tax_amount_currency': 100.0,
|
||||
'display_base_amount_currency': False,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
})
|
||||
self.assertEqual(self._get_simple_detail_ar_tax(invoice1), [("vat", 868.51), ("other", 142.20)])
|
||||
|
||||
def test_17_invoice_b_tax_breakdown_2(self):
|
||||
def test_19_invoice_b_tax_breakdown_2(self):
|
||||
""" Display only Other Taxes (VAT taxes are 0) """
|
||||
invoice2 = self._create_invoice_from_dict({
|
||||
'ref': 'test_invoice_21: inal Consumer Invoice B with 0 tax and internal tax',
|
||||
"move_type": 'out_invoice',
|
||||
"partner_id": self.partner_cf,
|
||||
"company_id": self.company_ri,
|
||||
"invoice_date": "2021-03-20",
|
||||
"invoice_line_ids": [
|
||||
{'product_id': self.product_iva_105_perc, 'price_unit': 10000.0, 'quantity': 1,
|
||||
'tax_ids': [(6, 0, [self.tax_no_gravado.id, self.tax_internal.id])]},
|
||||
],
|
||||
})
|
||||
self.assertEqual(self._get_simple_detail_ar_tax(invoice2), [("vat", 0.0), ("other", 300.0)])
|
||||
invoice = self._create_invoice_ar(
|
||||
ref='test_invoice_21: Final Consumer Invoice B with 0 tax and internal tax',
|
||||
partner_id=self.partner_cf,
|
||||
company_id=self.company_ri,
|
||||
invoice_date="2021-03-20",
|
||||
invoice_line_ids=[self._prepare_invoice_line(product_id=self.product_iva_105_perc, price_unit=10000.0, tax_ids=self.tax_no_gravado + self.tax_internal)],
|
||||
)
|
||||
results = invoice._l10n_ar_get_invoice_custom_tax_summary_for_report()
|
||||
self.assertEqual(results, [
|
||||
{
|
||||
'tax_amount_currency': 300.00,
|
||||
'formatted_tax_amount_currency': '300.00',
|
||||
'name': 'Other National Ind. Taxes $'
|
||||
},
|
||||
{
|
||||
'formatted_tax_amount_currency': '0.00',
|
||||
'name': 'VAT Content $',
|
||||
'tax_amount_currency': 0.0
|
||||
}
|
||||
|
||||
def test_18_invoice_b_tax_breakdown_3(self):
|
||||
])
|
||||
self._assert_tax_totals_summary(invoice._l10n_ar_get_invoice_totals_for_report(), {
|
||||
'same_tax_base': True,
|
||||
'currency_id': self.currency.id,
|
||||
'base_amount_currency': 10300.0,
|
||||
'tax_amount_currency': 0.0,
|
||||
'total_amount_currency': 10300.0,
|
||||
'subtotals': [],
|
||||
})
|
||||
|
||||
def test_20_invoice_b_tax_breakdown_3(self):
|
||||
""" Display only Other Taxes (VAT taxes are 0 and non other taxes) """
|
||||
invoice3 = self._create_invoice_from_dict({
|
||||
'ref': 'test_invoice_22: Final Consumer Invoice B with 0 only',
|
||||
invoice = self._create_invoice_ar(
|
||||
ref='test_invoice_22: Final Consumer Invoice B with only 0 tax',
|
||||
partner_id=self.partner_cf,
|
||||
company_id=self.company_ri,
|
||||
invoice_date="2021-03-20",
|
||||
invoice_line_ids=[self._prepare_invoice_line(product_id=self.product_iva_105_perc, price_unit=10000.0, tax_ids=self.tax_no_gravado)],
|
||||
)
|
||||
results = invoice._l10n_ar_get_invoice_custom_tax_summary_for_report()
|
||||
self.assertEqual(results, [
|
||||
{
|
||||
'tax_amount_currency': 0.0,
|
||||
'formatted_tax_amount_currency': '0.00',
|
||||
'name': 'VAT Content $'
|
||||
},
|
||||
])
|
||||
self._assert_tax_totals_summary(invoice._l10n_ar_get_invoice_totals_for_report(), {
|
||||
'same_tax_base': True,
|
||||
'currency_id': self.currency.id,
|
||||
'base_amount_currency': 10000.0,
|
||||
'tax_amount_currency': 0.0,
|
||||
'total_amount_currency': 10000.0,
|
||||
'subtotals': [],
|
||||
})
|
||||
|
||||
def test_l10n_ar_prices_and_taxes(self):
|
||||
invoice = self.env['account.move'].create({
|
||||
"move_type": 'out_invoice',
|
||||
"partner_id": self.partner_cf,
|
||||
"company_id": self.company_ri,
|
||||
"invoice_date": "2021-03-20",
|
||||
"partner_id": self.partner_cf.id,
|
||||
"invoice_date": "2020-01-21",
|
||||
"invoice_line_ids": [
|
||||
{'product_id': self.product_iva_105_perc, 'price_unit': 10000.0, 'quantity': 1,
|
||||
'tax_ids': [(6, 0, [self.tax_no_gravado.id])]},
|
||||
Command.create({
|
||||
'product_id': self.product_iva_105_perc.id,
|
||||
'quantity': 24.0,
|
||||
'price_unit': 5470.0,
|
||||
'discount': 5.0,
|
||||
'tax_ids': [Command.set(self.tax_21.ids)],
|
||||
}),
|
||||
],
|
||||
})
|
||||
self.assertEqual(self._get_simple_detail_ar_tax(invoice3), [("vat", 0.0)])
|
||||
invoice_line = invoice.invoice_line_ids
|
||||
|
||||
# Included in VAT
|
||||
l10n_ar_values = invoice_line._l10n_ar_prices_and_taxes()
|
||||
self.assertAlmostEqual(l10n_ar_values['price_unit'], 6618.7)
|
||||
self.assertAlmostEqual(l10n_ar_values['price_subtotal'], 150906.36)
|
||||
self.assertAlmostEqual(l10n_ar_values['price_net'], 6287.765)
|
||||
|
||||
# Not include in VAT
|
||||
doc_27_lu_a = self.env.ref('l10n_ar.dc_liq_uci_a')
|
||||
invoice.l10n_latam_document_type_id = doc_27_lu_a
|
||||
l10n_ar_values = invoice_line._l10n_ar_prices_and_taxes()
|
||||
self.assertAlmostEqual(l10n_ar_values['price_unit'], 5470.0)
|
||||
self.assertAlmostEqual(l10n_ar_values['price_subtotal'], 124716.0)
|
||||
self.assertAlmostEqual(l10n_ar_values['price_net'], 5196.5)
|
||||
|
||||
def test_l10n_ar_vat_with_non_numeric_value(self):
|
||||
with self.assertRaises(ValidationError) as e:
|
||||
with Form(self.partner) as partner_form:
|
||||
partner_form.l10n_latam_identification_type_id = self.env.ref("l10n_ar.it_dni")
|
||||
partner_form.vat = "test"
|
||||
self.assertIn('Only numbers allowed for "DNI"', str(e.exception))
|
||||
|
||||
def test_create_debit_note_for_credit_note(self):
|
||||
"""
|
||||
Test that it is possible to create a debit note from a credit note
|
||||
"""
|
||||
|
||||
invoice = self.init_invoice('out_invoice', partner=self.partner_afip, products=[self.product_a], post=True)
|
||||
|
||||
credit_note_wizard = self.env['account.move.reversal'].with_context({
|
||||
'active_ids': invoice.ids,
|
||||
'active_model': 'account.move',
|
||||
}).create({
|
||||
'reason': 'credit note',
|
||||
'journal_id': invoice.journal_id.id,
|
||||
})
|
||||
credit_note_wizard.refund_moves()
|
||||
invoice.reversal_move_ids.action_post()
|
||||
|
||||
debit_note_wizard = self.env['account.debit.note'].with_context({
|
||||
'active_ids': invoice.reversal_move_ids.ids,
|
||||
'active_model': 'account.move',
|
||||
}).create({
|
||||
'reason': 'debit_note',
|
||||
})
|
||||
debit_note_wizard.create_debit()
|
||||
self.assertTrue(invoice.reversal_move_ids.debit_note_ids)
|
||||
|
||||
@skip("TODO: failing test. 'Fix' the rounding error")
|
||||
def test_l10n_ar_rounding_01(self):
|
||||
self.env.company.tax_calculation_rounding_method = 'round_globally'
|
||||
currency_usd = self.env.ref('base.USD')
|
||||
currency_usd.active = True
|
||||
|
||||
self.env['res.currency.rate'].create([{
|
||||
'name': '2025-04-01',
|
||||
'inverse_company_rate': 1066.50,
|
||||
'currency_id': currency_usd.id,
|
||||
'company_id': self.env.company.id,
|
||||
}])
|
||||
tax_02 = self.percent_tax(0.2)
|
||||
invoice_a = self._create_invoice_ar(
|
||||
invoice_date='2025-04-02',
|
||||
currency_id=currency_usd,
|
||||
invoice_line_ids=[self._prepare_invoice_line(price_unit=124, tax_ids=tax_02)],
|
||||
)
|
||||
self.assertEqual(invoice_a.amount_total, invoice_a.invoice_line_ids.price_total, 'The invoice total should match the line total since there is only one line.')
|
||||
|
||||
tax_lines_a = invoice_a.line_ids \
|
||||
.filtered(lambda x: x.tax_line_id) \
|
||||
.sorted(lambda x: (x.move_id.id, x.tax_line_id.id, x.tax_ids.ids, x.tax_repartition_line_id.id))
|
||||
self.env.company.tax_calculation_rounding_method = 'round_per_line'
|
||||
invoice_b = self._create_invoice_ar(
|
||||
invoice_date='2025-04-02',
|
||||
currency_id=currency_usd,
|
||||
invoice_line_ids=[self._prepare_invoice_line(price_unit=124, tax_ids=tax_02)],
|
||||
)
|
||||
self.assertEqual(invoice_b.amount_total, invoice_b.invoice_line_ids.price_total, 'The invoice total should match the line total since there is only one line.')
|
||||
|
||||
tax_lines_b = invoice_b.line_ids \
|
||||
.filtered(lambda x: x.tax_line_id) \
|
||||
.sorted(lambda x: (x.move_id.id, x.tax_line_id.id, x.tax_ids.ids, x.tax_repartition_line_id.id))
|
||||
|
||||
self.assertEqual(tax_lines_a.balance, tax_lines_b.balance, 'Tax balances should be equal since both invoices have a single line and the total matches the line amount.')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue