Contributors mailing list archives
contributors@odoo-community.org
Browse archives
Odoo 9.0: Sale order line and computed field
by
mehdi.ghezal
Dear Contributors,
I come across a problem with the Odoo Sale module (Odoo 9.0) and my modules ; a bunch of modules that work together actually. I cannot figure out if it's my modules wrong or if it's an issue in Odoo, so I seek some feedback.
I already look in Github, hunting for some issue and each time I think it could be related, the issue still the same after I apply the patch in my Odoo instance :(
For make it more simple, let's say I have one unique module that add a new computed field in sale.order.line. This field allow the user to see in realtime what will be the remaining (not reserved) quantity in stock if this sale order is confirmed.
Let's say I have a Product A with 100 units in stock and 1 delivery that reserve 10 units. If the user create a sale order with 1 line of Product A with a quantity of 10, the new field will show a remaining quantity of 80 units: 90 in stock not reserved - 10 requested. If the user update the quantity to 20, the new field will show 70 units remaining.
This feature work fine even if I notice that the computed method is called many time when the user update the quantity.
For keep it simple, let's say I update my module to allow the user to make a stock reservation based on the sale order without confirm it. For this purpose, a stock picking is created, with a stock move and everything is assigned ; like an standard transfert in Odoo.
The update also add two new fields:
- Sale order line: reservation_move_ids = fields.One2many(comodel_name='stock.move', inverse_name='reservation_sale_order_line')
- Stock move: reservation_sale_order_line = fields.Many2one(comodel_name='sale.order.line')
Theses two fields are used to keep track of reservations per sale.order.line. Obviously when the reservation is made, the sale order line is write in the stock move but keep it out of the scope for simplicity.
I keep the same example as before so ; I have a Product A with 100 units in stock and 1 delivery that reserve 10 units. If the user create a sale order with 1 line of Product A with a quantity of 10, the remaining quantity field will show 80 units: 90 in stock not reserved - 10 requested.
If the user, reserve the sale order ; the remaining quantity field will now show 70 units: 80 in stock not reserved - 10 requested. It seems correct but in my case, when the sale order is confirmed the reservation is cancelled ; so the correct value for the remaining quantity should be 80 units.
So I update the method that compute the remaining quantity to do the following operation: 80 in stock not reserved - 10 requested + 10 reserved by the line. For know how many product is reserved by a sale order line I use the new field reservation_move_ids.
If I refresh and display the sale order in view mode, everything work fine. If I edit the sale order and modify the quantity of the sale order line the remaining quantity go wrong but when I save it's correct again...
Like I said before, when I check the call of the computation method, I notice it's called many time but now I also notice that the result is not the same between each call.
I make a single module that bundle everything and a video for illustrate the behavior.
You can see the video here : https://drive.google.com/file/d/1sSpT4awJFJmfBe9JkTOiix4NqJTL0r7-/view
You can download / see the module here : https://drive.google.com/drive/folders/1xM1WELDeVRlVHHvOb0J5qb-upP2CGzvq
Have you any clue about what's happen ?
An issue or did I do something wrong ?
Your feedback will be greatly appreciate.
Best regards,
Mehdi