You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

66 lines
3.0 KiB

# -*- coding: utf-8 -*-
###############################################################################
#
# Cybrosys Technologies Pvt. Ltd.
# Copyright (C) 2025-TODAY Cybrosys Technologies(<https://www.cybrosys.com>).
# Author: Unnimaya CO (odoo@cybrosys.com)
#
# This program is free software: you can modify
# it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE (LGPL) as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU LESSER GENERAL PUBLIC LICENSE for more details.
#
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
###############################################################################
from odoo import api, fields, models, _
class MrpProduction(models.Model):
"""Available products that can be made using Bill of Materials"""
_inherit = "mrp.production"
product_count = fields.Integer(string="Available Quantity",
compute="_compute_product_count",
help="Number of products that can be made "
"using available BOMs.")
check_quant = fields.Boolean(string="Check Quantity",
help="To check before warning message")
@api.depends('product_id')
def _compute_product_count(self):
"""Check number of products that can be made using available BOMs"""
for record in self:
record.product_count = ''
product_id = record.bom_id.bom_line_ids.mapped('product_id')
bom_quantity = record.bom_id.bom_line_ids.mapped('product_qty')
product_quantity = [products.qty_available for products in
product_id]
product_count_min = []
for bom_quant, product_quant in zip(bom_quantity, product_quantity):
available_quantity = product_quant / bom_quant
product_count_min.append(available_quantity)
if 0 in product_quantity:
record.product_count = 0
record.check_quant = True
elif len(product_count_min) != 0:
record.product_count = min(product_count_min)
@api.onchange('bom_id')
def _onchange_bom_id(self):
"""If available quantity of product is zero show warning message """
if self.check_quant and self.product_count == 0:
return {
'warning': {
'title': (_('Warning')),
'message': (_(
'There is no available BOM quantities to '
'complete the manufacture')),
}
}