diff options
| author | Victor Feyens <vfe@odoo.com> | 2020-09-15 13:55:09 +0000 |
|---|---|---|
| committer | Victor Feyens <vfe@odoo.com> | 2020-10-22 13:10:54 +0000 |
| commit | 037012bc4e2935eb00a7f353529bb7ec55066733 (patch) | |
| tree | 3aa2efc3cfb905e9c15d382e9751cd15bdacc2db /addons/l10n_ar | |
| parent | 4ff9ff09193390d9b39b15046855f94a98ad8409 (diff) | |
[FIX] *: avoid direct references to countries
Ensure the code works fine even if countries are deleted.
Also consider "re"-created countries after deletion, by only considering
the country code, not the data reference.
This should reduce support requests related to deleted countries, and
ease the resolution of such problems by the users themselves.
TASK ID - 2368842
closes odoo/odoo#57837
Related: odoo/enterprise#13275
Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
Diffstat (limited to 'addons/l10n_ar')
| -rw-r--r-- | addons/l10n_ar/models/account_chart_template.py | 6 | ||||
| -rw-r--r-- | addons/l10n_ar/models/account_fiscal_position.py | 4 | ||||
| -rw-r--r-- | addons/l10n_ar/models/account_journal.py | 4 | ||||
| -rw-r--r-- | addons/l10n_ar/models/account_move.py | 16 | ||||
| -rw-r--r-- | addons/l10n_ar/models/l10n_latam_document_type.py | 4 | ||||
| -rw-r--r-- | addons/l10n_ar/models/res_company.py | 4 |
6 files changed, 19 insertions, 19 deletions
diff --git a/addons/l10n_ar/models/account_chart_template.py b/addons/l10n_ar/models/account_chart_template.py index 8ce14066993..a53709251a6 100644 --- a/addons/l10n_ar/models/account_chart_template.py +++ b/addons/l10n_ar/models/account_chart_template.py @@ -11,7 +11,7 @@ class AccountChartTemplate(models.Model): def _get_fp_vals(self, company, position): res = super()._get_fp_vals(company, position) - if company.country_id == self.env.ref('base.ar'): + if company.country_id.code == "AR": res['l10n_ar_afip_responsibility_type_ids'] = [ (6, False, position.l10n_ar_afip_responsibility_type_ids.ids)] return res @@ -20,7 +20,7 @@ class AccountChartTemplate(models.Model): """ If Argentinian chart, we modify the defaults values of sales journal to be a preprinted journal """ res = super()._prepare_all_journals(acc_template_ref, company, journals_dict=journals_dict) - if company.country_id == self.env.ref('base.ar'): + if company.country_id.code == "AR": for vals in res: if vals['type'] == 'sale': vals.update({ @@ -58,7 +58,7 @@ class AccountChartTemplate(models.Model): company_responsibility = company.l10n_ar_afip_responsibility_type_id company.write({ 'l10n_ar_afip_responsibility_type_id': coa_responsibility.id, - 'country_id': self.env.ref('base.ar').id, + 'country_id': self.env['res.country'].search([('code', '=', 'AR')]).id, 'tax_calculation_rounding_method': 'round_globally', }) # set CUIT identification type (which is the argentinian vat) in the created company partner instead of diff --git a/addons/l10n_ar/models/account_fiscal_position.py b/addons/l10n_ar/models/account_fiscal_position.py index 40875efb53e..3a510335b45 100644 --- a/addons/l10n_ar/models/account_fiscal_position.py +++ b/addons/l10n_ar/models/account_fiscal_position.py @@ -15,7 +15,7 @@ class AccountFiscalPosition(models.Model): def get_fiscal_position(self, partner_id, delivery_id=None): """ Take into account the partner afip responsibility in order to auto-detect the fiscal position """ company = self.env.company - if company.country_id == self.env.ref('base.ar'): + if company.country_id.code == "AR": PartnerObj = self.env['res.partner'] partner = PartnerObj.browse(partner_id) @@ -39,7 +39,7 @@ class AccountFiscalPosition(models.Model): @api.onchange('l10n_ar_afip_responsibility_type_ids', 'country_group_id', 'country_id', 'zip_from', 'zip_to') def _onchange_afip_responsibility(self): - if self.company_id.country_id == self.env.ref('base.ar'): + if self.company_id.country_id.code == "AR": if self.l10n_ar_afip_responsibility_type_ids and any(['country_group_id', 'country_id', 'zip_from', 'zip_to']): return {'warning': { 'title': _("Warning"), diff --git a/addons/l10n_ar/models/account_journal.py b/addons/l10n_ar/models/account_journal.py index 1f30df58cbc..0974ebaa5c6 100644 --- a/addons/l10n_ar/models/account_journal.py +++ b/addons/l10n_ar/models/account_journal.py @@ -107,7 +107,7 @@ class AccountJournal(models.Model): 'l10n_latam_use_documents') def _check_afip_configurations(self): """ Do not let the user update the journal if it already contains confirmed invoices """ - journals = self.filtered(lambda x: x.company_id.country_id == self.env.ref('base.ar') and x.type in ['sale', 'purchase']) + journals = self.filtered(lambda x: x.company_id.country_id.code == "AR" and x.type in ['sale', 'purchase']) invoices = self.env['account.move'].search([('journal_id', 'in', journals.ids), ('posted_before', '=', True)], limit=1) if invoices: raise ValidationError( @@ -118,7 +118,7 @@ class AccountJournal(models.Model): def _check_afip_pos_number(self): to_review = self.filtered( lambda x: x.type == 'sale' and x.l10n_latam_use_documents and - x.company_id.country_id == self.env.ref('base.ar')) + x.company_id.country_id.code == "AR") if to_review.filtered(lambda x: x.l10n_ar_afip_pos_number == 0): raise ValidationError(_('Please define an AFIP POS number')) diff --git a/addons/l10n_ar/models/account_move.py b/addons/l10n_ar/models/account_move.py index 970f37f4b92..4928929d63f 100644 --- a/addons/l10n_ar/models/account_move.py +++ b/addons/l10n_ar/models/account_move.py @@ -38,7 +38,7 @@ class AccountMove(models.Model): @api.constrains('move_type', 'journal_id') def _check_moves_use_documents(self): """ Do not let to create not invoices entries in journals that use documents """ - not_invoices = self.filtered(lambda x: x.company_id.country_id == self.env.ref('base.ar') and x.journal_id.type in ['sale', 'purchase'] and x.l10n_latam_use_documents and not x.is_invoice()) + not_invoices = self.filtered(lambda x: x.company_id.country_id.code == "AR" and x.journal_id.type in ['sale', 'purchase'] and x.l10n_latam_use_documents and not x.is_invoice()) if not_invoices: raise ValidationError(_("The selected Journal can't be used in this transaction, please select one that doesn't use documents as these are just for Invoices.")) @@ -49,7 +49,7 @@ class AccountMove(models.Model): @api.depends('invoice_line_ids', 'invoice_line_ids.product_id', 'invoice_line_ids.product_id.type', 'journal_id') def _compute_l10n_ar_afip_concept(self): - recs_afip = self.filtered(lambda x: x.company_id.country_id == self.env.ref('base.ar') and x.l10n_latam_use_documents) + recs_afip = self.filtered(lambda x: x.company_id.country_id.code == "AR" and x.l10n_latam_use_documents) for rec in recs_afip: rec.l10n_ar_afip_concept = rec._get_concept() remaining = self - recs_afip @@ -77,7 +77,7 @@ class AccountMove(models.Model): def _get_l10n_latam_documents_domain(self): self.ensure_one() domain = super()._get_l10n_latam_documents_domain() - if self.journal_id.company_id.country_id == self.env.ref('base.ar'): + if self.journal_id.company_id.country_id.code == "AR": letters = self.journal_id._get_journal_letter(counterpart_partner=self.partner_id.commercial_partner_id) domain += ['|', ('l10n_ar_letter', '=', False), ('l10n_ar_letter', 'in', letters)] codes = self.journal_id._get_journal_codes() @@ -113,7 +113,7 @@ class AccountMove(models.Model): @api.onchange('partner_id') def _onchange_afip_responsibility(self): - if self.company_id.country_id == self.env.ref('base.ar') and self.l10n_latam_use_documents and self.partner_id \ + if self.company_id.country_id.code == 'AR' and self.l10n_latam_use_documents and self.partner_id \ and not self.partner_id.l10n_ar_afip_responsibility_type_id: return {'warning': { 'title': _('Missing Partner Configuration'), @@ -124,7 +124,7 @@ class AccountMove(models.Model): def _onchange_partner_journal(self): """ This method is used when the invoice is created from the sale or subscription """ expo_journals = ['FEERCEL', 'FEEWS', 'FEERCELP'] - for rec in self.filtered(lambda x: x.company_id.country_id == self.env.ref('base.ar') and x.journal_id.type == 'sale' + for rec in self.filtered(lambda x: x.company_id.country_id.code == "AR" and x.journal_id.type == 'sale' and x.l10n_latam_use_documents and x.partner_id.l10n_ar_afip_responsibility_type_id): res_code = rec.partner_id.l10n_ar_afip_responsibility_type_id.code domain = [('company_id', '=', rec.company_id.id), ('l10n_latam_use_documents', '=', True), ('type', '=', 'sale')] @@ -146,7 +146,7 @@ class AccountMove(models.Model): raise RedirectWarning(msg, action.id, _('Go to Journals')) def _post(self, soft=True): - ar_invoices = self.filtered(lambda x: x.company_id.country_id == self.env.ref('base.ar') and x.l10n_latam_use_documents) + ar_invoices = self.filtered(lambda x: x.company_id.country_id.code == "AR" and x.l10n_latam_use_documents) for rec in ar_invoices: rec.l10n_ar_afip_responsibility_type_id = rec.commercial_partner_id.l10n_ar_afip_responsibility_type_id.id if rec.company_id.currency_id == rec.currency_id: @@ -201,14 +201,14 @@ class AccountMove(models.Model): def _get_starting_sequence(self): """ If use documents then will create a new starting sequence using the document type code prefix and the journal document number with a 8 padding number """ - if self.journal_id.l10n_latam_use_documents and self.env.company.country_id == self.env.ref('base.ar'): + if self.journal_id.l10n_latam_use_documents and self.env.company.country_id.code == "AR": if self.l10n_latam_document_type_id: return self._get_formatted_sequence() return super()._get_starting_sequence() def _get_last_sequence_domain(self, relaxed=False): where_string, param = super(AccountMove, self)._get_last_sequence_domain(relaxed) - if self.company_id.country_id == self.env.ref('base.ar') and self.l10n_latam_use_documents: + if self.company_id.country_id.code == "AR" and self.l10n_latam_use_documents: if not self.journal_id.l10n_ar_share_sequences: where_string += " AND l10n_latam_document_type_id = %(l10n_latam_document_type_id)s" param['l10n_latam_document_type_id'] = self.l10n_latam_document_type_id.id or 0 diff --git a/addons/l10n_ar/models/l10n_latam_document_type.py b/addons/l10n_ar/models/l10n_latam_document_type.py index 44f8a1c1971..5e15ad774d9 100644 --- a/addons/l10n_ar/models/l10n_latam_document_type.py +++ b/addons/l10n_ar/models/l10n_latam_document_type.py @@ -34,7 +34,7 @@ class L10nLatamDocumentType(models.Model): def _filter_taxes_included(self, taxes): """ In argentina we include taxes depending on document letter """ self.ensure_one() - if self.country_id == self.env.ref('base.ar') and self.l10n_ar_letter in ['B', 'C', 'X', 'R']: + if self.country_id.code == "AR" and self.l10n_ar_letter in ['B', 'C', 'X', 'R']: return taxes.filtered(lambda x: x.tax_group_id.l10n_ar_vat_afip_code) return super()._filter_taxes_included(taxes) @@ -44,7 +44,7 @@ class L10nLatamDocumentType(models.Model): * format the document_number against a pattern and return it """ self.ensure_one() - if self.country_id != self.env.ref('base.ar'): + if self.country_id.code != "AR": return super()._format_document_number(document_number) if not document_number: diff --git a/addons/l10n_ar/models/res_company.py b/addons/l10n_ar/models/res_company.py index 72bd820f979..62fe7563342 100644 --- a/addons/l10n_ar/models/res_company.py +++ b/addons/l10n_ar/models/res_company.py @@ -20,7 +20,7 @@ class ResCompany(models.Model): @api.onchange('country_id') def onchange_country(self): """ Argentinian companies use round_globally as tax_calculation_rounding_method """ - for rec in self.filtered(lambda x: x.country_id == self.env.ref('base.ar')): + for rec in self.filtered(lambda x: x.country_id.code == "AR"): rec.tax_calculation_rounding_method = 'round_globally' @api.depends('l10n_ar_afip_responsibility_type_id') @@ -33,7 +33,7 @@ class ResCompany(models.Model): def _localization_use_documents(self): """ Argentinian localization use documents """ self.ensure_one() - return True if self.country_id == self.env.ref('base.ar') else super()._localization_use_documents() + return True if self.country_id.code == "AR" else super()._localization_use_documents() @api.constrains('l10n_ar_afip_responsibility_type_id') def _check_accounting_info(self): |
