Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
3144 Lượt xem

I have done a lot customisations using studio in Odoo 14. Now Im trying to add a column for Warehouse Location in stock.production.lot, but I can't figure out how to to this.


If I add a related field to: product_stock.quants_location.display_name I get the correct warehouse location if Qty=1. But if product Qty>1, warehouse location is displayed as Virtual Locations/Inventory adjustment.

Any idea how this could be solved?


//Rickard


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất


Odoo uses the same stock.production.lot object for Lot and Serial Number. In case of serial number, it is normal that this serial number is located in one location at a time, but in the case of Lot inventory, it can be divided into different locations, and it is not possible to display multiple locations in a single field, that's why Odoo added a smart button (Location) in the Header section of form view. If the user clicks on the Location Smart button, he will know where the inventory is.

If you want to show all locations on the list/tree you need to create a custom field (many2many) which calculates the field it will check where the serial/lot number is stored and add those locations.


You can refer to the following code snippet


location_ids = fields.Many2many('stock.location', compute='_compute_locations', string="Location")

def _compute_locations(self):
for lot in self:
location_ids = self.env['stock.quant'].search([('lot_id', '=', lot.id), ('quantity', '>', 0), ('location_id.usage', '=', 'internal')]).mapped('location_id').ids
lot.location_ids = [(6, 0, location_ids)]



Ảnh đại diện
Huỷ bỏ
Tác giả

Thanks Sagar.
If creating a many2many field, I get "No Records" for all Serial Number rows in tree view. I guess I need to configure the domain to get this done? Any idea how to configure the many2many field?

Hello Rickard Walster

I have updated the answer and provided you code snippet that shows how to add many2many calculated(compute) field that shows location

I'm trying to do this as well. Can this be done with Studio? If so, how?

Tác giả Câu trả lời hay nhất

Hello Sagar

Thanks you very much for your effort. However, it seems Im not skilled enough for this, and I don't have access to the server. Im only using Studio for customisations, so I don't really know how to configure the field using your code snippet.

I guess I should be able to create the field and configure it using studio and field settings, but I couldn't figure out how to.


PS. For clarification, each Serial Number is only located in one location, but since there are multiple Serial Numbers for a product, it gives different locations for each row in Lot/Serial tree view.

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 3 24
1163
3
thg 6 25
977
1
thg 10 24
1690
2
thg 10 24
3016
1
thg 7 24
2272