Search code examples
pythonodoo-12odoo-13

Accessing odoo fields using eval from another module


Could somebody help me understand the purpose of this line? I can see that it is referring to a field in accounts then the model account_move then the field amount_total.

I am trying to port this module from v12 to v13 but I get an error that amount_total does not exist. The field amount_total exists in that model

<field name="ks_record_field" eval="ref('account.field_account_move__amount_total')" />

The original field in the module I am porting is this.

<field name="ks_record_field" eval="ref('account.field_account_invoice__amount_total')" />


Solution

  • According to the data file field documentation :

    If a ref attribute is provided, its value must be a valid external id, which will be looked up and set as the field’s value.
    Mostly for Many2one and Reference fields.

    The eval attributes simply evaluates whatever Python expression it is provided and sets the result as the field’s value.
    The evaluation context contains various modules (time, datetime, timedelta, relativedelta), a function to resolve external identifiers (ref) and the model object for the current field if applicable (obj).

    When the data file is executed, Odoo will try to evaluate the expression specified by eval attribute and call xmlid_lookup which will return (id, res_model, res_id) or raise ValueError if not found.

    The Total field external identifier is not present in the database (not created or deleted) or has been modified.