[9.0] [l10n_fr_siret] new:add siret unicity #61

Open
wants to merge 2 commits into
from

Projects

None yet

4 participants

@njeudy
njeudy commented Feb 1, 2016
  • Add siret unicity constraint.
  • Shown final user company name that already has this siret number
njeudy added some commits Feb 1, 2016
@njeudy njeudy new: [l10n_fr_siret] add siret unicity
- Add siret unicity constraint.
64f6e9a
@njeudy njeudy fix: restore .pot file
b7a1b90
@gurneyalex gurneyalex commented on the diff Feb 8, 2016
l10n_fr_siret/partner.py
@@ -58,6 +57,12 @@ def _get_siret(self):
@api.constrains('siren', 'nic')
def _check_siret(self):
"""Check the SIREN's and NIC's keys (last digits)"""
+ # Check unicity of siret
+ for partner in self.env['res.partner'].search([('id', '!=', self.id),('siret', 'not in', [False,''])]):
+ siret = str(self.siren) + str(self.nic)
+ if siret == partner.siret:
+ raise ValidationError(_("Siret must be unique !\n It was defined for '%s'.") % partner.name)
+
@gurneyalex
gurneyalex Feb 8, 2016 Member

why not a UNIQUE SQL index on siren + nic ? I'm concerned about performance issues with this implementation.

@njeudy
njeudy Feb 8, 2016

@gurneyalex you're right it could be better to use UNIQUE SQL index on big database .. will try it and update code accordingly.

@legalsylvain legalsylvain added this to the 9.0 milestone Mar 25, 2016
@gurneyalex
Member

@njeudy setting needs fixing for now.

@alexis-via
Contributor

I agree that siret unicity is a good idea. But, if we have siret unicity as default, we should also have vat number unicity as defaut, but there is no such thing in the official addons nor in the OCA addons (at least I'm not aware of). So I don't know what to think about this. But, in the end, I tend to think that having siret unicity by default is a good thing in most scenarios... the problem is that it's not consistent with the handling of the vat field.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment