NeoVe
NeoVe

Reputation: 3897

Stock picking from fleet model - Odoo v9 community

I'm trying to create a stock.picking from fleet.vehicle.log.services model on Odoo v9 community.

So far I'm trying like this:

stock_picking = fields.Many2one("stock.picking", "Picking", required=True)
state = fields.Selection(string="Estados", store=True, readonly=True, related="stock_picking.state")
product_id = fields.Many2one(string="Producto", store=True, readonly=True, related="stock_picking.product_id")
location_id = fields.Many2one(string="Almacén Origen", store=True, readonly=True, related="stock_picking.location_id")
location_dest_id = fields.Many2one(string="Almacén Destino", store=True, readonly=True, related="stock_picking.location_dest_id")  

The result of this, is that every time I create a stock.picking from this form model (fleet.vehicle.log.services), it populates the product and location fields with the ones from the picking I've just created.

So, what is the problem here? Well, I need to put the product and locations from this form not just bring the ones from the picking, the relationship should work in reverse.

I hope I've explained myself.

Upvotes: 0

Views: 65

Answers (1)

thangtn
thangtn

Reputation: 876

The problem is related field in Odoo is read only field (you dont need to put option readonly in field when using related field) and the value will be filled automatically from the related model field (in this case product and location values will have same value with related model fields). If you want to input the value yourself, just remove related field option for product and location.

product_id = fields.Many2one("stocking.picking", string="Producto", store=True,readonly=True)
location_id = fields.Many2one("stock.picking", string="Almacén Origen", store=True, readonly=True)
location_dest_id = fields.Many2one("stock.picking", string="Almacén Destino", readonly=True)  

Upvotes: 1

Related Questions