This question has been flagged
1014 Views

Salesforecast(first model) is the master class and salesforecastproducts model holds the products list and salesforecast.products.itemlines holds the bom list. but when i add a product in the table it was supposed to fill the next page of the notebook it's not. The problem i guess is on the onChange Thanks for the help



from odoo import fields, models,api


class Salesforecast(models.Model):
""" Manufacturing Orders """
_name = 'mrp.salesforecast'
_description = 'Salesforecast model'
salesforecast_name = fields.Char(
'Salesforecast ref')

salesforecast_product = fields.One2many('mrp.salesforecastproducts', 'salesforecast_id', 'Salesforecast Products')
salesforecast_items = fields.One2many(related='salesforecast_product.salesforecast_product_items_id',string="Ingredients",store=True, required=True)


class SalesforecastProducts(models.Model):
""" Manufacturing Orders """
_name = 'mrp.salesforecastproducts'
_description = 'Salesforecast Products'



@api.onchange('product_qty','bom_id')
def onchange_product_id(self):
""" Finds UoM of changed product. """
for rec in self:
if self.bom_id and rec.product_qty > 0:
bom = self.env['mrp.bom']._bom_find(product=rec.product_id,
bom_type='normal')
list_bom_items = []
for bo in bom:
obje = {
'item_id': bo.product_id.id,
'product_id': rec.product_id.id,
'item_qty': bo.product_qty ,
'item_available': bo.product_id.qty_available,
'item_required': 1}
list_bom_items.append((0, 0, obje))
rec.salesforecast_product_items_id = list_bom_items

salesforecast_id = fields.Many2one(
'mrp.salesforecast', 'Salesforecast', store=True)
product_id = fields.Many2one(
'product.product', 'Product Name', store=True)
salesforecast_product_items_id = fields.One2many('mrp.salesforecastproductsitems', 'salesforcast_product_id',
string="Items List")
product_qty = fields.Float(
'Quantity Forecasted',
default=1.0, digits='Product Unit of Measure',
readonly=False, required=True)
product_batch_size = fields.Float(
'Batch Size',
default=1.0, digits='Product Unit of Measure',
required=True)
bom_id = fields.Many2one(
'mrp.bom', 'Bill of Material',
domain="""[
('product_id','=',product_id),
'&',
('product_tmpl_id.product_variant_ids','=',product_id),
('product_id','=',False),
('type', '=', 'normal')]""",
check_company=True, store=True)




class SalesforecastProductsItems(models.Model):
""" salesforecast ingredients """
_name = 'mrp.salesforecastproductsitems'
_description = 'Salesforecast BOM Items'

salesforcast_product_id = fields.Many2one('mrp.salesforecastproducts', 'salesforecast product ref')
item_id = fields.Many2one(
'product.product', 'Item Name')
product_id = fields.Many2one(
'product.product', 'Product')
item_qty = fields.Float(
'Required Quantity',
default=1.0)

item_available = fields.Float(
'Qty available',
related='item_id.qty_available',
readonly=False, store=True)

item_required = fields.Float(
'Item required')



Avatar
Discard