Hi @Pete Charalampopoulos
I hope you are doing well,
For you evaluate the values from the html field you will need to the following customisation in Odoo:
- In html field you will need to write as following:
ex:
A/E Core Return Credit Grade A ${object.grade_a} Grade B ${object.grade_b} Grade C ${object.grade_c}
30 Day Return Policy, Credit to be issued with in 7 days of receipt.
- You will need to make adjustment to the document file(xml). Where the html field is defined.
ex.
Please find the code example from the below comments :
- You will need to create the method get_evaluated_val() define the method on res.users to use it throughout odoo.
def get_evaluated_val(self, obj, val, check=False):
"""Evaluate dynamic vals in html field as odoo only evaluates html"""
# Regex to match ${...} pattern
MAIN_REGEX = r"\${.*?}"
val = eval_val = val or ''
# Logic here is to find whole pattern matching ${...},
# Then extract ... from ${}, evaluate the value of ... using safe eval
# Replace the whole match ${...} with evaluated val in the main string
# Replace 1 match at a time to avoid errors next iterations if same
# value is used multiple times
try:
matches = re.finditer(MAIN_REGEX, val, re.MULTILINE)
for match in matches:
to_eval_val = (match.group()).strip().split("${")[1].split("}")[0]
val = safe_eval(to_eval_val, {"object": obj})
eval_val = eval_val.replace((match.group()), val or "", 1)
if not check:
return eval_val
return True
except Exception as e:
raise ValidationError(e)
- You will also need to define a check method on particular model ex. sale.order to check if dynamic fields exist or not.
@api.constrains("html_field")
def _check_html_field(self):
"""
Method to check the dynamic field exists or not.
"""
for record in self:
self.env.user.get_evaluated_val(
record, record.html_field, check=True
)
I hope this will be helpful.
Please note for the above method will only convert dynamic placeholders to value (text representation) but will not display it like field widgets do ie. it will not add currency symbol like monetary widget.
Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari
Works like a charm. Thank you