From 10e5c1b50fe5dc90f8bc282ca3d420b2b5c3d59d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Mart=C3=ADnez?= Date: Mon, 2 Sep 2024 10:14:02 +0200 Subject: [PATCH] [FIX] base_import_pdf_by_template: Improve the import process to account for fixed values When fixed values are defined, default_x was used in the context of Form() but in some cases this was not respected (for example if the value was changed in an onchange, warehouse_id field of sale orders). We changed the way of creating the records to always take into account the fixed values. TT50650 --- .../wizards/wizard_base_import_pdf_upload.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/base_import_pdf_by_template/wizards/wizard_base_import_pdf_upload.py b/base_import_pdf_by_template/wizards/wizard_base_import_pdf_upload.py index 4505a9d799..1de1a8b757 100644 --- a/base_import_pdf_by_template/wizards/wizard_base_import_pdf_upload.py +++ b/base_import_pdf_by_template/wizards/wizard_base_import_pdf_upload.py @@ -171,7 +171,6 @@ def _process_set_value_form(self, _form, field_name, value): def _process_form(self): """Create record with Form() according to text.""" - # text = "".join(data) text = self.data template = self.template_id model = self.env[template.model] @@ -202,7 +201,15 @@ def _process_form(self): model_name=template.child_model, related_model="lines" )._process_set_value_form(line_form, field_name, line[field_name]) try: - record = model_form.save() + # Prepare vals (similar to .save()) + apply defaults (in case it has changed + # in some onchange for example: warehouse_id from sale orders) + vals = model_form._values_to_save() + for key in ctx: + if key.startswith("default_"): + field = key.replace("default_", "") + if field in vals: + vals.update({field: ctx[key]}) + record = model.with_context(**ctx).create(vals) except (AssertionError) as err: raise UserError(err) from err if self.log_text: