[ADD]pms: company configuration document required

This commit is contained in:
Darío Lodeiros
2022-11-19 18:17:20 +01:00
parent 977099e426
commit 52e5e545bf
5 changed files with 148 additions and 4 deletions

View File

@@ -531,7 +531,11 @@ class PmsCheckinPartner(models.Model):
"birthdate_date": record.birthdate_date,
"nationality_id": record.nationality_id.id,
}
partner = self.env["res.partner"].create(partner_values)
partner = (
self.env["res.partner"]
.with_context(avoid_document_restriction=True)
.create(partner_values)
)
record.partner_id = partner
@api.depends("email", "mobile")

View File

@@ -43,3 +43,10 @@ class ResCompany(models.Model):
""",
default="no",
)
document_partner_required = fields.Boolean(
string="Document partner required",
help="""If true, the partner document is required
to create a new contact""",
default=False,
)

View File

@@ -879,3 +879,49 @@ class ResPartner(models.Model):
_("The partner %s cannot be deleted"), various_partner.name
)
return super().unlink()
def create(self, vals):
check_missing_document = self._check_document_partner_required(vals)
if check_missing_document:
raise ValidationError(_("A document identification is required"))
return super().create(vals)
def write(self, vals):
check_missing_document = self._check_document_partner_required(
vals, partners=self
)
if check_missing_document:
raise ValidationError(_("A document identification is required"))
return super().write(vals)
@api.model
def _check_document_partner_required(self, vals, partners=False):
company_ids = (
self.env["res.company"].sudo().search([]).ids
if (not partners or any([not partner.company_id for partner in partners]))
else partners.mapped("company_id.id")
)
if not self.env.context.get("avoid_document_restriction") and any(
[
self.env["res.company"].browse(company_id).document_partner_required
for company_id in company_ids
]
):
return self._missing_document(vals, partners)
return False
@api.model
def _missing_document(self, vals, partners=False):
if (
vals.get("vat") is False
or vals.get("vat") == ""
or (
"vat" not in vals
and (
any([not partner.vat for partner in partners]) if partners else True
)
)
):
return True
return False

View File

@@ -15,6 +15,7 @@
<field name="url_advert" />
</xpath>
<xpath expr="//field[@name='vat']" position="after">
<field name="document_partner_required" />
<field name="check_min_partner_data_invoice" />
<field name="pms_invoice_downpayment_policy" />
</xpath>