Search code examples
postgresqlbackendodoo

In which table are subscription tags saved?


I'm currently working with the database of Odoo to bulk import and export data. For that I also use tags. For example I need to bulk tag 500 subscriptions. Does anyone know in which tables the relations between model and tag are saved in?

I already found those:

  • res_partner_res_partner_category_rel

  • sale_subscription_template_tag_rel

What I'm looking for are the tags on subscription level. Through the URL I can see, that the model I'm looking at is "sale.subscription". Therefore I started looking for a table named "sale_subscription_tag_relation" but there is nothing. sale_subscription_template_tag_rel is empty while there are already subscriptions tagged. So it can't be that.

The information shown on the UI needs to be stored somewhere, but I just can't find out where. The URL im looking at:

https://localhost/web#id=CUSTOMER_ID&action=454&active_id=1779&model=sale.subscription&view_type=form&cids=1&menu_id=329

Tables for the subscription model:

sale_subscription
sale_subscription_alert
sale_subscription_alert_sale_subscription_template_rel
sale_subscription_close_reason
sale_subscription_close_reason_wizard
sale_subscription_line
sale_subscription_price_wizard
sale_subscription_snapshot
sale_subscription_stage
sale_subscription_template
sale_subscription_template_tag_rel
sale_subscription_wizard
sale_subscription_wizard_option

Solution

  • If the relation name is not specified, Odoo will compute it based on the alphabetical order of the tables names (model, comodel).

    tables = sorted([model._table, comodel._table])
    self.relation = '%s_%s_rel' % tuple(tables)
    

    Check in sale.subscription model if the relation parameter is set on the tags field and if not, use the above code to compute it ( The comodel name is usually the first parameter of the Many2many field).

    Edit:

    For example, the tag_ids field defined in the event module does not specify the relation.

    The comodel name is event.tag and the field is defined in event.type model, to get the table names, we need to replace . with _ to get the table names.

    In the following code, we will sort the model and comodel table names in ascending order and use the result to construct the relation name using format string (It will replace the %s with a table name in the provided order)

    >>> tables = sorted(['event_type', 'event_tag'])
    >>> tables
    ['event_tag', 'event_type']
    >>> relation = '%s_%s_rel' % tuple(tables)
    >>> relation
    'event_tag_event_type_rel'
    

    There should be a table named event_tag_event_type_rel in the database after installing the module.