[IMP] survey_record_generation : add param ignore_if_mandatory_field_is_missing
Some checks failed
pre-commit / pre-commit (pull_request) Failing after 1m38s
Some checks failed
pre-commit / pre-commit (pull_request) Failing after 1m38s
This commit is contained in:
@@ -33,6 +33,12 @@ class SurveyRecordCreation(models.Model):
|
||||
store=True,
|
||||
string="Allowed Fields",
|
||||
)
|
||||
ignore_if_mandatory_field_is_missing = fields.Boolean(
|
||||
string="Ignore creation if a mandatory field is missing",
|
||||
help="If a mandatory field is missing when trying to create the record, "
|
||||
"an error is raised when the survey is submitted. "
|
||||
"If this option is activated, the error is ignored."
|
||||
)
|
||||
|
||||
@api.depends("field_values_ids.field_id")
|
||||
def _compute_allowed_field_ids(self):
|
||||
|
||||
@@ -81,17 +81,15 @@ class SurveyUserInput(models.Model):
|
||||
existing_record.write(vals_with_keys_not_in_record)
|
||||
record = existing_record
|
||||
else:
|
||||
if (
|
||||
model == "res.partner"
|
||||
and ignore_when_res_partner_mandatory_fields_are_missing
|
||||
):
|
||||
# this part has been developed for Calim specific needs :
|
||||
# being able to ignore some Contacts creation
|
||||
# TODO : find a way to make it generic for all models
|
||||
if not vals.get("lastname") and not vals.get("firstname"):
|
||||
try:
|
||||
with self.env.cr.savepoint():
|
||||
record = self.env[model].create(vals)
|
||||
except Exception:
|
||||
# This a broad exception because it could be IntegrityError,
|
||||
# EmptyNamesError in case partner_firstname is installed etc...
|
||||
if record_creation.ignore_if_mandatory_field_is_missing:
|
||||
continue
|
||||
# Create record
|
||||
record = self.env[model].create(vals)
|
||||
raise
|
||||
# Link generated records to user input
|
||||
self.env["survey.generated.record"].create(
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user