[IMP] l10n_eu_oss: makes code more readable
Improves l10n_eu_oss code readability X-original-commit: aedd9bf60aa6d9eecb055e6f7871c24c8ed2e0f8 Part-of: odoo/odoo#86314
This commit is contained in:
committed by
william
parent
dbaaf59f74
commit
6bd3bb4528
@@ -39,18 +39,18 @@ class Company(models.Model):
|
||||
('foreign_vat', '!=', False),
|
||||
])
|
||||
oss_countries = eu_countries - company.account_fiscal_country_id - multi_tax_reports_countries_fpos.country_id
|
||||
for country in oss_countries:
|
||||
for destination_country in oss_countries:
|
||||
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),
|
||||
('foreign_vat', '=', 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,
|
||||
})
|
||||
@@ -58,26 +58,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_fiscal_country_id.code, domestic_tax.amount, country.code), False)
|
||||
tax_amount = EU_TAX_MAP.get((company.account_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):
|
||||
tax_group_fid = 'oss_tax_group_%s' % str(tax_amount).replace('.', '_')
|
||||
if not self.env.ref('l10n_eu_oss.%s' % tax_group_fid, raise_if_not_found=False):
|
||||
oss_tax_group_local_xml_id = f"oss_tax_group_{str(tax_amount).replace('.', '_')}"
|
||||
if not self.env.ref(f"l10n_eu_oss.{oss_tax_group_local_xml_id}", raise_if_not_found=False):
|
||||
self.env['ir.model.data'].create({
|
||||
'name': tax_group_fid,
|
||||
'name': oss_tax_group_local_xml_id,
|
||||
'module': 'l10n_eu_oss',
|
||||
'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_oss.%s' % tax_group_fid).id,
|
||||
'description': f"{tax_amount}%",
|
||||
'tax_group_id': self.env.ref(f'l10n_eu_oss.{oss_tax_group_local_xml_id}').id,
|
||||
'country_id': company.account_fiscal_country_id.id,
|
||||
'sequence': 1000,
|
||||
'company_id': company.id,
|
||||
@@ -114,16 +114,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_oss',
|
||||
'model': 'account.account',
|
||||
'res_id': oss_account.id,
|
||||
'noupdate': True,
|
||||
})
|
||||
return self.env.ref('l10n_eu_oss.oss_tax_account_company_%s' % self.id)
|
||||
return self.env.ref(f'l10n_eu_oss.oss_tax_account_company_{self.id}')
|
||||
|
||||
Reference in New Issue
Block a user