Skip to content
Snippets Groups Projects
Commit 61249a43 authored by Brice bib Bartoletti's avatar Brice bib Bartoletti
Browse files

[IMP] l10n_eu_services: makes code more readable

Improves l10n_eu_services code readability

Part-of: odoo/odoo#86295
parent fb6b683e
No related branches found
No related tags found
No related merge requests found
......@@ -28,19 +28,19 @@ class Company(models.Model):
taxes = self.env['account.tax'].search([
('type_tax_use', '=', 'sale'),
('amount_type', '=', 'percent'),
('company_id','=', company.id),
('company_id', '=', company.id),
('tax_group_id', 'not in', oss_tax_groups.mapped('res_id'))])
for country in eu_countries - company.account_tax_fiscal_country_id:
for destination_country in eu_countries - company.account_tax_fiscal_country_id:
mapping = []
fpos = self.env['account.fiscal.position'].search([
('country_id', '=', country.id),
('country_id', '=', destination_country.id),
('company_id', '=', company.id),
('auto_apply', '=', True),
('vat_required', '=', False)], limit=1)
if not fpos:
fpos = self.env['account.fiscal.position'].create({
'name': 'OSS B2C %s' % country.name,
'country_id': country.id,
'name': f'OSS B2C {destination_country.name}',
'country_id': destination_country.id,
'company_id': company.id,
'auto_apply': True,
})
......@@ -48,25 +48,26 @@ class Company(models.Model):
foreign_taxes = {tax.amount: tax for tax in fpos.tax_ids.tax_dest_id if tax.amount_type == 'percent'}
for domestic_tax in taxes:
tax_amount = EU_TAX_MAP.get((company.account_tax_fiscal_country_id.code, domestic_tax.amount, country.code), False)
tax_amount = EU_TAX_MAP.get((company.account_tax_fiscal_country_id.code, domestic_tax.amount, destination_country.code), False)
if tax_amount and domestic_tax not in fpos.tax_ids.tax_src_id:
if not foreign_taxes.get(tax_amount, False):
if not self.env['ir.model.data'].xmlid_to_object('l10n_eu_service.oss_tax_group_%s' % str(tax_amount).replace('.','_')):
oss_tax_group_local_xml_id = f"oss_tax_group_{str(tax_amount).replace('.', '_')}"
if not self.env['ir.model.data'].xmlid_to_object(f"l10n_eu_service.{oss_tax_group_local_xml_id}"):
self.env['ir.model.data'].create({
'name': 'oss_tax_group_%s' % str(tax_amount).replace('.','_'),
'name': oss_tax_group_local_xml_id,
'module': 'l10n_eu_service',
'model': 'account.tax.group',
'res_id': self.env['account.tax.group'].create({'name': 'OSS %s%%' % tax_amount}).id,
'res_id': self.env['account.tax.group'].create({'name': f'OSS {tax_amount}%'}).id,
'noupdate': True,
})
})
foreign_taxes[tax_amount] = self.env['account.tax'].create({
'name': '%(rate)s%% %(country)s %(label)s' % {'rate': tax_amount, 'country': country.code, 'label': country.vat_label},
'name': f'{tax_amount}% {destination_country.code} {destination_country.vat_label}',
'amount': tax_amount,
'invoice_repartition_line_ids': invoice_repartition_lines,
'refund_repartition_line_ids': refund_repartition_lines,
'type_tax_use': 'sale',
'description': "%s%%" % tax_amount,
'tax_group_id': self.env.ref('l10n_eu_service.oss_tax_group_%s' % str(tax_amount).replace('.','_')).id,
'description': f"{tax_amount}%",
'tax_group_id': self.env.ref(f'l10n_eu_service.{oss_tax_group_local_xml_id}').id,
'sequence': 1000,
'company_id': company.id,
})
......@@ -96,16 +97,16 @@ class Company(models.Model):
return False
new_code = self.env['account.account']._search_new_account_code(self, len(sales_tax_accounts[0].code), sales_tax_accounts[0].code[:-2])
oss_account = self.env['account.account'].create({
'name': '%s OSS' % sales_tax_accounts[0].name,
'name': f'{sales_tax_accounts[0].name} OSS',
'code': new_code,
'user_type_id': sales_tax_accounts[0].user_type_id.id,
'company_id': self.id,
})
self.env['ir.model.data'].create({
'name': 'oss_tax_account_company_%s' % self.id,
'name': f'oss_tax_account_company_{self.id}',
'module': 'l10n_eu_service',
'model': 'account.account',
'res_id': oss_account.id,
'noupdate': True,
})
return self.env.ref('l10n_eu_service.oss_tax_account_company_%s' % self.id)
return self.env.ref(f'l10n_eu_service.oss_tax_account_company_{self.id}')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment