| 1 |
from freezegun import freeze_time |
| 2 |
|
| 3 |
from odoo import Command |
| 4 |
from odoo.addons.account.tests.common import AccountTestInvoicingCommon |
| 5 |
|
| 6 |
|
| 7 |
class TestUBLTRCommon(AccountTestInvoicingCommon): |
| 8 |
|
| 9 |
@classmethod |
| 10 |
@AccountTestInvoicingCommon.setup_country('tr') |
| 11 |
@freeze_time('2025-03-05') |
| 12 |
def setUpClass(cls): |
| 13 |
super().setUpClass() |
| 14 |
|
| 15 |
cls.company_data['company'].partner_id.write({ |
| 16 |
'vat': '3297552117', |
| 17 |
'street': '3281. Cadde', |
| 18 |
'zip': '06810', |
| 19 |
'city': 'İç Anadolu Bölgesi', |
| 20 |
'state_id': cls.env.ref('base.state_tr_81').id, |
| 21 |
'country_id': cls.env.ref('base.tr').id, |
| 22 |
'email': '[email protected]', |
| 23 |
'phone': '+90 501 234 56 78', |
| 24 |
'ref': 'Ulus', |
| 25 |
'bank_ids': [Command.create({'acc_number': 'TR0123456789'})], |
| 26 |
}) |
| 27 |
|
| 28 |
cls.einvoice_partner = cls.env['res.partner'].create({ |
| 29 |
'name': 'einvoice_partner', |
| 30 |
'vat': '1729171602', |
| 31 |
'street': 'Gökhane Sokak No:1', |
| 32 |
'zip': '06934', |
| 33 |
'city': 'Sincan/Ankara', |
| 34 |
'state_id': cls.env.ref('base.state_tr_06').id, |
| 35 |
'country_id': cls.env.ref('base.tr').id, |
| 36 |
'email': 'info@tr_partner.com', |
| 37 |
'phone': '+90 509 876 54 32', |
| 38 |
'bank_ids': [Command.create({'acc_number': 'TR9876543210'})], |
| 39 |
'invoice_edi_format': 'ubl_tr', |
| 40 |
'ref': 'Ulus', |
| 41 |
'l10n_tr_nilvera_customer_status': 'einvoice', |
| 42 |
}) |
| 43 |
|
| 44 |
cls.earchive_partner = cls.env['res.partner'].create({ |
| 45 |
'name': 'earchive_partner', |
| 46 |
'vat': '17291716060', |
| 47 |
'street': 'Gökhane Sokak No:1', |
| 48 |
'zip': '06934', |
| 49 |
'city': 'Sincan/Ankara', |
| 50 |
'state_id': cls.env.ref('base.state_tr_06').id, |
| 51 |
'country_id': cls.env.ref('base.tr').id, |
| 52 |
'email': 'info@tr_partner.com', |
| 53 |
'phone': '+90 509 876 54 32', |
| 54 |
'bank_ids': [Command.create({'acc_number': 'TR9876543210'})], |
| 55 |
'invoice_edi_format': 'ubl_tr', |
| 56 |
'l10n_tr_nilvera_customer_status': 'earchive', |
| 57 |
}) |
| 58 |
|
| 59 |
cls.tax_20 = cls.env['account.chart.template'].ref('tr_s_wh_20_2_10') |
| 60 |
|
| 61 |
# The rate of 1 USD = 40 TRY is meant to simplify tests |
| 62 |
usd = cls.env.ref('base.USD') |
| 63 |
cls.env['res.currency.rate'].search([ |
| 64 |
('company_id', '=', cls.company_data['company'].id), |
| 65 |
('currency_id', '=', usd.id), |
| 66 |
]).unlink() |
| 67 |
cls.env['res.currency.rate'].create({ |
| 68 |
'name': '2019-01-01', |
| 69 |
'rate': 0.025, |
| 70 |
'currency_id': usd.id, |
| 71 |
'company_id': cls.company_data['company'].id, |
| 72 |
}) |
| 73 |
|
| 74 |
def _generate_invoice_xml(self, partner_id, tax=None, include_invoice=False, **kwargs): |
| 75 |
invoice_tax = (tax and tax.ids) or self.tax_20.ids |
| 76 |
|
| 77 |
invoice = self.env['account.move'].create({ |
| 78 |
'move_type': 'out_invoice', |
| 79 |
'company_id': self.company_data['company'].id, |
| 80 |
'partner_id': partner_id.id, |
| 81 |
'name': 'EIN/2025/1', |
| 82 |
'invoice_date': '2025-03-03', |
| 83 |
'narration': '3 products', |
| 84 |
'invoice_line_ids': [ |
| 85 |
Command.create({ |
| 86 |
'product_id': self.product_a.id, |
| 87 |
'price_unit': 50.00, |
| 88 |
'quantity': 3, |
| 89 |
'discount': 12, |
| 90 |
'tax_ids': [Command.set(invoice_tax)], |
| 91 |
}), |
| 92 |
], |
| 93 |
**kwargs, |
| 94 |
}) |
| 95 |
invoice.action_post() |
| 96 |
|
| 97 |
if include_invoice: |
| 98 |
return self.env['account.edi.xml.ubl.tr']._export_invoice(invoice)[0], invoice |
| 99 |
return self.env['account.edi.xml.ubl.tr']._export_invoice(invoice)[0] |