This question has been flagged
1 Reply
4397 Views

Hello

What would consider to be the best way to fill a field automatically when creating an order?

I mean, in my instance, when I create a new production order, this in turn creates work orders required to comply with that order, in theory, the only thing that should be put to complete is the product and quantity. But that leaves me empty routing_id field that I need to be completed automatically depending on the product selected.

I think, given my limited experience with OpenERP, that this can be done by looking for the product that is created with the order, taking the routing id from a couple of records and fill the field with this data. That is a first impression on how to do it.

But I wanted to confirm if anyone knows or has any idea how to do it using some other method.

Thank you very much.

Avatar
Discard
Best Answer

Hi Carlos, there are some methods available to fill your field automatically.

(1) You can write method in _defaults of your object.

For example,

def _get_routing(self, cr, uid, context=None):
    // Your code & return the routing_id you want
    return routing_id[0]

_defaults = {
         'routing_id' : _get_routing,
        }

(2) On change of product_id you can return routing_id.

(3) You can overwrite create method and fill your field.

Thanks.

Avatar
Discard
Author

That what i thought. I think am gonna go with the first option. I am more familiar with that than the last 2. Thanks.