Skip to content

Commit

Permalink
[FIX] base_import_pdf_by_template: Improve the import process to acco…
Browse files Browse the repository at this point in the history
…unt 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
  • Loading branch information
victoralmau committed Sep 9, 2024
1 parent dde1dd8 commit 10e5c1b
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 10e5c1b

Please sign in to comment.