Я использую odoo11 (python3) и для разработки собственного модуля.
Я хотел бы получить количество продукции (вручную или по прогнозу) для отдельного склада.
Просто я выбираю любой отдельный склад и показываю количество товара для этого склада.
На самом деле моя цель - две вещи
1. общее количество доступного продукта
2. Количество продуктов в зависимости от местоположения
Это мой код
class Threshold(models.Model):
_name="threshold.threshold"
main_location=fields.Many2many("stock.warehouse", string="Main Location")
product=fields.Many2many("product.template", string="Product")
category=fields.Many2one("product.category", string="Category")
attribute=fields.Many2many("product.attribute", string="Attribute")
threshold_value=fields.Integer(string="Threshold Value")
transfer_quantity=fields.Integer(string="Transfer Quantity")
status_button=fields.Selection([('0','Active'),('1','Dissmiss')], default='0', index=True, string="Status")
threshold_selection=fields.Selection([('0','Product'),('1','Category'),], default= '0', index=True, string="Threshold Selection")
product_quantity=fields.Integer(compute="_product_based_on_warehouse", store=True)
@api.depends('main_location','product_quantity')
def _product_based_on_warehouse(self):
count_products = 0
self.env['product.template'].with_context(warehouse=self.main_location).search([], limit=1)
self.product_quantity=products print(f'Product Quantity: {self.product_quantity}')