mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[ADD]pms: company configuration document required
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import logging
|
||||
|
||||
from odoo import api, fields, models
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
from odoo.addons.base_vat.models.res_partner import _eu_country_vat
|
||||
|
||||
CODE_SPAIN = "ES"
|
||||
|
||||
@@ -33,7 +36,90 @@ class ResPartner(models.Model):
|
||||
res = super(ResPartner, self)._check_enought_invoice_data()
|
||||
if not res:
|
||||
return res
|
||||
if self.country_id.code == "ES":
|
||||
if not self.state_id and not self.zip:
|
||||
if not self.country_id or not self.city or not (self.street or self.street2):
|
||||
return False
|
||||
if not self.vat:
|
||||
if self.country_id.code == "ES":
|
||||
return False
|
||||
elif not self.aeat_identification:
|
||||
return False
|
||||
return True
|
||||
|
||||
def write(self, vals):
|
||||
res = super(ResPartner, self).write(vals)
|
||||
# REVIEW: Force Contrain vat
|
||||
# https://github.com/odoo/odoo/issues/23242
|
||||
if vals.get("vat") or vals.get("country_id"):
|
||||
self.check_vat()
|
||||
self._pms_check_unique_vat()
|
||||
return res
|
||||
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
records = super(ResPartner, self).create(vals)
|
||||
# REVIEW: Force Contrain vat
|
||||
# https://github.com/odoo/odoo/issues/23242
|
||||
if vals.get("vat") or vals.get("country_id"):
|
||||
records.check_vat()
|
||||
records._pms_check_unique_vat()
|
||||
return records
|
||||
|
||||
# This function is a candidate to be moved to the module
|
||||
# partner_vat_unique
|
||||
def _pms_check_unique_vat(self):
|
||||
Partner = self.with_context(active_test=False).sudo()
|
||||
europe = self.env.ref("base.europe")
|
||||
if not europe:
|
||||
europe = self.env["res.country.group"].search(
|
||||
[("name", "=", "Europe")], limit=1
|
||||
)
|
||||
for partner in self.filtered(lambda p: p.vat and p.country_id):
|
||||
partner_country_code = partner.commercial_partner_id.country_id.code
|
||||
vat_country, vat_number = self._split_vat(partner.vat)
|
||||
if europe and partner.country_id.id in europe.country_ids.ids:
|
||||
vat_country = _eu_country_vat.get(vat_country, vat_country).upper()
|
||||
vat_with_code = (
|
||||
partner.vat
|
||||
if partner_country_code.lower() == vat_country
|
||||
else partner_country_code.upper() + partner.vat
|
||||
)
|
||||
vat_without_code = (
|
||||
partner.vat
|
||||
if partner_country_code.lower() != vat_country
|
||||
else vat_country
|
||||
)
|
||||
domain = [
|
||||
("company_id", "in", [False, partner.company_id.id]),
|
||||
"|",
|
||||
("vat", "=", vat_with_code),
|
||||
("vat", "=", vat_without_code),
|
||||
]
|
||||
domain += [("id", "!=", partner.id), "!", ("id", "child_of", partner.id)]
|
||||
repeat_partner = Partner.search(domain, limit=1)
|
||||
if bool(partner.vat) and not partner.parent_id and repeat_partner:
|
||||
raise UserError(
|
||||
_("The VAT number %s already exists in other contacts: %s")
|
||||
% (
|
||||
vat_without_code,
|
||||
repeat_partner.name,
|
||||
)
|
||||
)
|
||||
|
||||
def _missing_document(self, vals, partners=False):
|
||||
res = super(ResPartner, self)._missing_document(vals)
|
||||
if not res:
|
||||
return res
|
||||
if (
|
||||
vals.get("aeat_identification") is False
|
||||
or vals.get("aeat_identification") == ""
|
||||
or (
|
||||
"aeat_identification" not in vals
|
||||
and (
|
||||
any([not partner.aeat_identification for partner in partners])
|
||||
if partners
|
||||
else True
|
||||
)
|
||||
)
|
||||
):
|
||||
return True
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user