2
votes

I'm creating a log entry within a server action in Odoo 10. This is the server action Python code:

if record:
    env['ir.logging'].create({
        'type': 'server',
        'name': 'test',
        'level': record._name,
        'path': 'test',
        'line': 'test,
        'func': '#',
        'message': '#'
    })

The line value for level of record._name gets me the name of the current model as a string, for example, product.product, or sale.order.

However, I don't think the _name attribute is not meant to be part of the public API. Does anyone know of a public way to retrieve the name of the model?

The model variable is also available in the server action, which returns product.product(). However, want product.product, without the parenthesis. I realize I could just use a string method to trim off the (), but I'm wondering if there is an intended way to get just the name of the model as a string.

Any ideas?

1

1 Answers

2
votes

I don't see another way. _name is "private" and you could use __str__, which will give you the model name and the ids of the current RecordSet. The regex for odoo's model names is r'^[a-z0-9_.]+$', so i suggest, what you've already known: trim off everything at the end.