| 1 |
from odoo import Command |
| 2 |
from odoo.addons.account.tests.common import AccountTestInvoicingCommon |
| 3 |
from odoo.tests.common import tagged |
| 4 |
|
| 5 |
@tagged('post_install_l10n', 'post_install', '-at_install') |
| 6 |
class TestFECExport(AccountTestInvoicingCommon): |
| 7 |
def test_fec_export(self): |
| 8 |
self.init_invoice("out_invoice", self.partner_a, "2019-01-01", amounts=[1000, 2000], post=True) |
| 9 |
inv = self.init_invoice("out_invoice", self.partner_a, "2020-01-01", amounts=[1000, 2000]) |
| 10 |
inv.write({ |
| 11 |
"line_ids": [ |
| 12 |
Command.create({ |
| 13 |
"name": "Note", |
| 14 |
"display_type": "line_note", |
| 15 |
}) |
| 16 |
] |
| 17 |
}) |
| 18 |
inv.action_post() |
| 19 |
# Create a new FEC export |
| 20 |
fec_export = self.env['l10n_fr.fec.export.wizard'].create({ |
| 21 |
'date_from': '2020-01-01', |
| 22 |
'date_to': '2020-12-31', |
| 23 |
}) |
| 24 |
result = fec_export.generate_fec() |
| 25 |
self.assertEqual( |
| 26 |
result['file_content'].decode(), |
| 27 |
'JournalCode|JournalLib|EcritureNum|EcritureDate|CompteNum|CompteLib|CompAuxNum|CompAuxLib|PieceRef|PieceDate|EcritureLib|Debit|Credit|EcritureLet|DateLet|ValidDate|Montantdevise|Idevise\r\n' |
| 28 |
'OUV|Balance initiale|OUVERTURE/2020|20200101|999999|Undistributed Profits/Losses|||-|20200101|/|0,00| 000000000003000,00|||20200101||\r\n' |
| 29 |
f'OUV|Balance initiale|OUVERTURE/2020|20200101|121000|Account Receivable|{self.partner_a.id}|partner_a|-|20200101|/| 000000000003000,00|0,00|||20200101||\r\n' |
| 30 |
'INV|Sales|INV/2020/00001|20200101|400000|Product Sales|||-|20200101|test line|0,00| 000000000001000,00|||20200101|-000000000001000,00|USD\r\n' |
| 31 |
'INV|Sales|INV/2020/00001|20200101|400000|Product Sales|||-|20200101|test line|0,00| 000000000002000,00|||20200101|-000000000002000,00|USD\r\n' |
| 32 |
f'INV|Sales|INV/2020/00001|20200101|121000|Account Receivable|{self.partner_a.id}|partner_a|-|20200101|INV/2020/00001| 000000000003000,00|0,00|||20200101| 000000000003000,00|USD' |
| 33 |
) |
| 34 |
|
| 35 |
def test_fec_sub_companies(self): |
| 36 |
"""When exporting FEC, data from child companies should be included""" |
| 37 |
main_company = self.env.company |
| 38 |
branch_a, branch_b = self.env['res.company'].create([ |
| 39 |
{ |
| 40 |
'name': 'Branch A', |
| 41 |
'country_id': main_company.country_id.id, |
| 42 |
'parent_id': main_company.id, |
| 43 |
}, { |
| 44 |
'name': 'Branch B', |
| 45 |
'country_id': main_company.country_id.id, |
| 46 |
'parent_id': main_company.id |
| 47 |
} |
| 48 |
]) |
| 49 |
branch_a1 = self.env['res.company'].create({ |
| 50 |
'name': 'Branch A1', |
| 51 |
'country_id': main_company.country_id.id, |
| 52 |
'parent_id': branch_a.id, |
| 53 |
}) |
| 54 |
|
| 55 |
self.cr.precommit.run() # load the COA |
| 56 |
all_companies = (main_company + branch_a + branch_a1 + branch_b) |
| 57 |
|
| 58 |
for i, company in enumerate(all_companies, start=1): |
| 59 |
self.init_invoice('out_invoice', invoice_date="2021-01-01", post=True, amounts=[i * 100], company=company) |
| 60 |
|
| 61 |
fec_export = self.env['l10n_fr.fec.export.wizard'].create({ |
| 62 |
'date_from': '2021-01-01', |
| 63 |
'date_to': '2021-12-31', |
| 64 |
}) |
| 65 |
result = fec_export.generate_fec() |
| 66 |
self.assertEqual( |
| 67 |
result['file_content'].decode(), |
| 68 |
"JournalCode|JournalLib|EcritureNum|EcritureDate|CompteNum|CompteLib|CompAuxNum|CompAuxLib|PieceRef|PieceDate|EcritureLib|Debit|Credit|EcritureLet|DateLet|ValidDate|Montantdevise|Idevise\r\n" |
| 69 |
"INV|Sales|INV/2021/00001|20210101|400000|Product Sales|||-|20210101|test line|0,00| 000000000000100,00|||20210101|-000000000000100,00|USD\r\n" |
| 70 |
f"INV|Sales|INV/2021/00001|20210101|121000|Account Receivable|{self.partner_a.id}|partner_a|-|20210101|INV/2021/00001| 000000000000100,00|0,00|||20210101| 000000000000100,00|USD\r\n" |
| 71 |
"INV|Sales|INV/2021/00002|20210101|400000|Product Sales|||-|20210101|test line|0,00| 000000000000200,00|||20210101|-000000000000200,00|USD\r\n" |
| 72 |
f"INV|Sales|INV/2021/00002|20210101|121000|Account Receivable|{self.partner_a.id}|partner_a|-|20210101|INV/2021/00002| 000000000000200,00|0,00|||20210101| 000000000000200,00|USD\r\n" |
| 73 |
"INV|Sales|INV/2021/00003|20210101|400000|Product Sales|||-|20210101|test line|0,00| 000000000000300,00|||20210101|-000000000000300,00|USD\r\n" |
| 74 |
f"INV|Sales|INV/2021/00003|20210101|121000|Account Receivable|{self.partner_a.id}|partner_a|-|20210101|INV/2021/00003| 000000000000300,00|0,00|||20210101| 000000000000300,00|USD\r\n" |
| 75 |
"INV|Sales|INV/2021/00004|20210101|400000|Product Sales|||-|20210101|test line|0,00| 000000000000400,00|||20210101|-000000000000400,00|USD\r\n" |
| 76 |
f"INV|Sales|INV/2021/00004|20210101|121000|Account Receivable|{self.partner_a.id}|partner_a|-|20210101|INV/2021/00004| 000000000000400,00|0,00|||20210101| 000000000000400,00|USD" |
| 77 |
) |
| 78 |
|
| 79 |
# Select only parent company |
| 80 |
self.env.user.write({ |
| 81 |
'company_ids': [Command.set(main_company.ids)], |
| 82 |
'company_id': main_company.id, |
| 83 |
}) |
| 84 |
|
| 85 |
fec_export = self.env['l10n_fr.fec.export.wizard'].create({ |
| 86 |
'date_from': '2021-01-01', |
| 87 |
'date_to': '2021-12-31', |
| 88 |
}) |
| 89 |
result = fec_export.generate_fec() |
| 90 |
self.assertEqual( |
| 91 |
result['file_content'].decode(), |
| 92 |
"JournalCode|JournalLib|EcritureNum|EcritureDate|CompteNum|CompteLib|CompAuxNum|CompAuxLib|PieceRef|PieceDate|EcritureLib|Debit|Credit|EcritureLet|DateLet|ValidDate|Montantdevise|Idevise\r\n" |
| 93 |
"INV|Sales|INV/2021/00001|20210101|400000|Product Sales|||-|20210101|test line|0,00| 000000000000100,00|||20210101|-000000000000100,00|USD\r\n" |
| 94 |
f"INV|Sales|INV/2021/00001|20210101|121000|Account Receivable|{self.partner_a.id}|partner_a|-|20210101|INV/2021/00001| 000000000000100,00|0,00|||20210101| 000000000000100,00|USD" |
| 95 |
) |