From 563a2b320cbf8d469decf3dbb73e88a7d3061059 Mon Sep 17 00:00:00 2001 From: "Paolo Gatti (pgi)" Date: Mon, 6 Feb 2023 23:31:25 +0000 Subject: [PATCH] [FIX] l10n_it_edi: Share Capital and Sole Shareholder not mandatory If the business is incorporated, both these fields must be present. We don't have a field to know whether the business is incorporated, but in any case the fields must be both present or not present. opw-3127832 closes odoo/odoo#112366 X-original-commit: b3de98d4dd248f56461f735a6cae143296a96a0a Signed-off-by: Josse Colpaert Signed-off-by: Paolo Gatti (pgi) --- addons/l10n_it_edi/models/res_company.py | 26 ++++++++++++++++-------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/addons/l10n_it_edi/models/res_company.py b/addons/l10n_it_edi/models/res_company.py index 6eb47ecc07c..5faec176e75 100644 --- a/addons/l10n_it_edi/models/res_company.py +++ b/addons/l10n_it_edi/models/res_company.py @@ -73,20 +73,28 @@ class ResCompany(models.Model): @api.constrains('l10n_it_has_eco_index', 'l10n_it_eco_index_office', 'l10n_it_eco_index_number', - 'l10n_it_eco_index_share_capital', - 'l10n_it_eco_index_sole_shareholder', 'l10n_it_eco_index_liquidation_state') def _check_eco_admin_index(self): for record in self: - if not record.l10n_it_has_eco_index: - continue - if not record.l10n_it_eco_index_office\ - or not record.l10n_it_eco_index_number\ - or not record.l10n_it_eco_index_share_capital\ - or not record.l10n_it_eco_index_sole_shareholder\ - or not record.l10n_it_eco_index_liquidation_state: + if (record.l10n_it_has_eco_index + and (not record.l10n_it_eco_index_office + or not record.l10n_it_eco_index_number + or not record.l10n_it_eco_index_liquidation_state)): raise ValidationError(_("All fields about the Economic and Administrative Index must be completed.")) + @api.constrains('l10n_it_has_eco_index', + 'l10n_it_eco_index_share_capital', + 'l10n_it_eco_index_sole_shareholder') + def _check_eco_incorporated(self): + """ If the business is incorporated, both these fields must be present. + We don't know whether the business is incorporated, but in any case the fields + must be both present or not present. """ + for record in self: + if (record.l10n_it_has_eco_index + and bool(record.l10n_it_eco_index_share_capital) ^ bool(record.l10n_it_eco_index_sole_shareholder)): + raise ValidationError(_("If one of Share Capital or Sole Shareholder is present, " + "then they must be both filled out.")) + @api.constrains('l10n_it_has_tax_representative', 'l10n_it_tax_representative_partner_id') def _check_tax_representative(self):