0
votes

I've defined on a custom module a new stock.location like this:

<record id="location_stock" model="stock.location">
    <field name="name">ReparacionUnidades</field>
    <field name="location_id" ref="stock.stock_location_locations_virtual"/>
    <field name="usage">production</field>
    <field name="company_id"></field>
</record>

Now, I want to set this location as default on two fields, with the new API, like this:

x_location_src_id = fields.Many2one('stock.location', string=u'Ubicacion Origen de Productos', required=True,
                                   readonly=False, default='ReparacionUnidades',
                                   help="Location where the system will look for components.")
x_location_dest_id = fields.Many2one('stock.location', string=u'Ubicacion Destino de Productos', required=True,
                                    readonly=False, default='ReparacionUnidades',
                                     help="Location where the system will look for components.")

With the default attribute, now, in this moment, this appears empty on the form.

Obviously, I'm not calling the location in the correct way, so, how can I call, or better, what will be the equivalent, of:

ref="stock.stock_location_locations_virtual"

On this case?

I've searched into the stock_location DB table, but really I have no clue.

Any ideas?

EDIT

I've also tried like this:

def _static_location(self):
    return ReparacionUnidades

Then, call on default attribute, this _static_location object, but ReparacionUnidades is obviously not defined.

1

1 Answers

1
votes

Try:

default=_static_location

and define your method like:

def _static_location(self):
     return self.env.ref('your_module_name.location_stock')

The method will have to be declared before the field.