def _compute_invalid_fields(self): project_id = self.env.user.project_id for l in self: mold_product = self.env['product.product'].with_context( lang=None).search([('category_code', '=', 'mold'), ('default_code', '=', parse_str(l.name))]) l.product_id = None invalid_fields = l.validate_mold_product(mold_product, l) if len(invalid_fields) == 0: product_tmpl = self.env['product.template'].with_context( lang=None).search([('name', '=', parse_str(l.material)), ('categ_id', '=', l.demand_id.categ_id.id)]) product = self.env['product.product'].with_context( lang=None).search([ ('project_id', '=', project_id.id), ('product_tmpl_id', '=', product_tmpl.id), ('name', '=', parse_str(l.material)), ('default_code', '=', parse_str(l.name)), ('raw_supplier_name', '=', l.demand_id.supplier.id), ('raw_supplier_part_no', '=', parse_str(l.supplier_part_no)), ('weight', '=', parse_float(l.net_weight)), ('volume', '=', parse_float(l.order_length)) ]) invalid_fields = l.validate_product(product, l) if len(invalid_fields) == 0: l.product_id = product l.invalid_fields = json.dumps(invalid_fields)
def validate_mold_product(self, product, l): invalid_fields = [] if product and product.category_code == 'mold': sellers = product.seller_ids for sl in sellers: data_correct = False has_supplier_name = False has_supplier_part_no = False # or not sellers has_material = False # or not sellers has_net_weight = False # or not sellers if sl.supplier_name == parse_str(l.demand_id.supplier.name): has_supplier_name = True if sl.product_code == parse_str(l.supplier_part_no): has_supplier_part_no = True if sl.product_material == parse_str(l.material): has_material = True if sl.weight == parse_float(l.net_weight): has_net_weight = True if has_supplier_name and has_supplier_part_no and has_material and has_net_weight: data_correct = True break else: continue if not data_correct: invalid_fields.append('name') invalid_fields.append('supplier_name') invalid_fields.append('supplier_part_no') invalid_fields.append('material') invalid_fields.append('net_weight') else: invalid_fields.append('name') invalid_fields.append('supplier_name') invalid_fields.append('supplier_part_no') invalid_fields.append('material') invalid_fields.append('net_weight') return invalid_fields
def act_confirm(self): atlas_id = self.env.context.get('atlas_id') atlas = self.env['tokiku.atlas'].browse(atlas_id) if not atlas.is_imported and atlas.atlas_version == 0: atlas.is_imported = True atlas.edit_atlas_id = atlas edit_atlas = atlas.edit_atlas_id new_atlas = edit_atlas.copy() reason = self.new_version_atlas_reason new_atlas.new_version_atlas_reason = reason edit_atlas.new_version_atlas_reason = reason new_atlas.is_imported = True last_atlas = self.env['tokiku.atlas'].search([('edit_atlas_id', '=', atlas.edit_atlas_id.id)], order="atlas_version desc", limit=1) new_atlas.atlas_version = last_atlas.atlas_version + 1 new_atlas.design_change_atlas_version = self.design_change_atlas_version edit_atlas.design_change_atlas_version = self.design_change_atlas_version project_id = self.env.user.project_id # products = [] id_map = {} count = 0 # for p in new_atlas.atlas_line_ids: # count = count+1 # print ("count %d" % count) # if (not p.name or len(p.name.strip()) == 0) and (not p.unit_qty or len(p.unit_qty.strip()) == 0): # continue # # # if category code # if p.categ_id.code == 'aluminum' or 'raw': # product = self.env['product.product'].sudo().search( # [('project_id', '=', project_id.id), # ('categ_id', '=', p.categ_id.id), # ('default_code', '=', p.name), # ('part_no', '=', p.code), # ], limit=1) # # print ("aluminum") # else: # product = self.env['product.product'].sudo().search( # [('project_id', '=', project_id.id), # ('categ_id', '=', p.categ_id.id), # ('default_code', '=', p.name), # ], limit=1) # # if not product: # product = self.env['product.product'].sudo().create({ # 'project_id': project_id.id, # 'categ_id': p.categ_id.id, # 'default_code': parse_str(p.name), # 'part_no': parse_str(p.code), # 'name': parse_str(p.description), # 'type': 'product', # }) # id_map[p.id] = product.id al_dict = {} for al in atlas.atlas_line_ids: if al.panel_categ_id.code: al_key = "%s/%s" % (al.panel_categ_id.code, al.name) if al_dict.get(al.panel_categ_id.code): if al_dict[al.panel_categ_id.code].get(al_key): al_dict[al.panel_categ_id.code][al_key] = [al, al_dict[al.panel_categ_id.code][al_key][ 1] + parse_int(al.qty)] else: al_dict[al.panel_categ_id.code][al_key] = [al, parse_int(al.qty)] else: al_dict[al.panel_categ_id.code] = {} al_dict[al.panel_categ_id.code][al_key] = [al, parse_int(al.qty)] _logger.info('al_dict:%s' % al_dict) # pl_dict = {} line_count = 0 for code in al_dict.iterkeys(): _logger.info('code:%s' % code) categ = self.env['product.category'].sudo().search([('code', '=', code), ('parent_id.code', '!=', 'assembly_section')]) panel = self.env['tokiku.panel'].sudo().search( [('project_id', '=', self.env.user.project_id.id), ('categ_id', '=', categ.id)], limit=1) if not panel: panel = self.env['tokiku.panel'].sudo().create( {'project_id': self.env.user.project_id.id, 'categ_id': categ.id}) pl_dict = {} # use edit atlas id to identify the newest atlas information, ex: name changed for pl in panel.line_ids.filtered(lambda x: x.atlas_id.id == atlas.edit_atlas_id.id): pl.atlas_demand_qty = 0 pl_key = "%s/%s" % (code, pl.default_code) _logger.info('pl pkey:%s' % pl_key) if not pl_dict.get(pl_key): pl_dict[pl_key] = [pl] # Clear all this atlas items in panel line to 0 to avoid items are deleted and qty isn't clear _logger.info('pl_dict:%s' % pl_dict) line_insert = [] count = 0 # for al in atlas.atlas_line_ids.filtered(lambda x: x.panel_categ_id.id == categ.id and x.name): # qty_dict = {} for key in al_dict.get(code).iterkeys(): al = al_dict[code][key][0] al_qty = al_dict[code][key][1] count = count + 1 line_count += 1 # if al.panel_categ_id.code == 'raw': # elif al.panel_categ_id.code == 'aluminum': # else: # pls = panel.line_ids.filtered(lambda x: x.default_code == al.name and x.atlas_id.id == atlas.edit_atlas_id.id) # x.code == al.code) p_key = "%s/%s" % (code, al.name) _logger.info('al pkey:%s' % p_key) if pl_dict.get(p_key): # pl.atlas_demand_qty = 0 for pl in pl_dict[p_key]: pl.atlas_id = atlas.edit_atlas_id pl.atlas_demand_qty += al_qty pl.description = parse_str(al.description) pl.surface_coating = parse_str(al.coating) pl.color_code = parse_str(al.color_code) pl.assembly_section = parse_str(al.assembly_section) pl.material = parse_str(al.material) pl.assembly_section = parse_str(al.assembly_section) else: if code in ['aluminum', 'raw']: product = self.env['product.product'].sudo().search( [('project_id', '=', project_id.id), ('categ_id', '=', al.categ_id.id), ('default_code', '=', al.name), ('part_no', '=', al.code), ], limit=1) product._compute_mold_id() else: product = self.env['product.product'].sudo().search( [('project_id', '=', project_id.id), ('categ_id', '=', al.categ_id.id), ('default_code', '=', al.name), ], limit=1) if not product: product = self.env['product.product'].sudo().create({ 'project_id': project_id.id, 'categ_id': al.categ_id.id, 'default_code': parse_str(al.name), 'part_no': parse_str(al.code), 'name': parse_str(al.description), 'type': 'product', }) # print ('prod_categ_id %s' % al.panel_categ_id.id) line_insert.append((0, 0, {'product_id': product.id, 'atlas_id': atlas.edit_atlas_id.id, # use edit_atlas_id to keep atlas data up to date 'atlas_demand_qty': al_qty, 'atlas_bom': parse_str(al.bom_no), 'description': parse_str(al.description), 'code': parse_str(al.code), 'cutting_length': parse_float(al.cutting_length), 'cutting_width': parse_float(al.cutting_width), 'color_code': parse_str(al.color_code), 'heating': parse_str(al.heating), 'surface_coating': parse_str(al.coating), 'atlas_unit_qty': parse_float(al.unit_qty), 'material': parse_str(al.material), 'assembly_section': parse_str(al.assembly_section), 'prod_categ_id': al.panel_categ_id, })) panel.sudo().line_ids = line_insert # panel._compute_order_line_ids() # panel.line_ids._compute_order_lines() panel.line_ids._compute_demand_qty() panel.line_ids._compute_rest_demand_qty() panel.line_ids._compute_area() # panel.refresh = True msg = _('%d Panel Line imported.') % line_count ctx = dict( default_message=msg, ) return { 'name': _('Import Results'), 'type': 'ir.actions.act_window', 'view_type': 'form', 'view_mode': 'form', 'res_model': 'biznavi.msgbox', 'target': 'new', 'context': ctx, }
def act_import(self): for d in self: if d.mold_line_ids.filtered(lambda x: x.invalid_fields and len(x.invalid_fields) > 5): raise UserError(_('Please fix the invalid field before import!')) return panel_id = self.env['tokiku.panel'].sudo().search([('project_id', '=', self.env.user.project_id.id), ('categ_id', '=', d.categ_id.id)], limit=1) # d.project_id.id product_tmpl = self.env['product.template'].with_context(lang=None).search([('name', '=', 'Die')]) attr_id = self.env['product.attribute'].with_context(lang=None).search([('name', '=', 'Extrusion Number')]) # panel_id._compute_order_line_ids() for p in panel_id.line_ids: p.mold_demand_qty = 0 for l in self.mold_line_ids: l.invalid_fields = [] l.product_id = None supplier = self.env['res.partner'].sudo().search( [('supplier', '=', True), ('ref', '=', parse_str(l.supplier_name))]) if not supplier: l.invalid_fields = json.dumps(['supplier_name']) else: attr_value = self.env['product.attribute.value'].sudo().with_context(lang=None).search( [('attribute_id', '=', attr_id.id), ('name', '=', parse_str(l.code))]) if not attr_value: attr_value = self.env['product.attribute.value'].with_context( {'active_id': product_tmpl.id}).create( {'attribute_id': attr_id.id, 'name': parse_str(l.code)}) product = product_tmpl.product_variant_ids.filtered( lambda x: attr_value.id in [a.id for a in x.attribute_value_ids]) if not product: line_id = product_tmpl.attribute_line_ids.filtered(lambda x: x.attribute_id.id == attr_id.id) if not line_id: line_id = self.env['product.attribute.line'].create( {'product_tmpl_id': product_tmpl.id, 'attribute_id': attr_id.id}) line_id.value_ids = [(4, attr_value.id)] product = self.env['product.product'].create({ 'product_tmpl_id': product_tmpl.id, 'default_code': parse_str(l.code), 'attribute_value_ids': [(4, attr_value.id), ], }) product = product_tmpl.product_variant_ids.filtered( lambda x: attr_value.id in [a.id for a in x.attribute_value_ids]) product.project_id = self.env.user.project_id.id product.description = parse_str(l.name) product.paint_area = parse_str(l.paint_area) seller_id = product.seller_ids.filtered(lambda x: x.product_id.id == product.id and x.name.id == supplier.id and x.product_material == parse_str(l.material) and x.product_code == parse_str(l.supplier_part_no) and x.weight == parse_float(l.net_weight) ) if seller_id: seller_id.product_code = parse_str(l.supplier_part_no) seller_id.min_qty = parse_float(l.min_qty) seller_id.ingot = parse_str(l.ingot) seller_id.coating = parse_str(l.coating) # seller_id.paint_area = parse_str(l.paint_area) else: product.seller_ids = [(0, 0, { 'product_id': product.id, 'name': supplier.id, 'product_code': parse_str(l.supplier_part_no), 'min_qty': parse_float(l.min_qty), 'product_material': parse_str(l.material), 'weight': parse_float(l.net_weight), # 'paint_area': parse_str(l.paint_area), 'coating': parse_str(l.coating), 'ingot': parse_str(l.ingot) })] seller_id = product.seller_ids.filtered(lambda x: x.product_id.id == product.id and x.name.id == supplier.id and x.product_material == parse_str(l.material) and x.product_code == parse_str(l.supplier_part_no) and x.weight == parse_float(l.net_weight)) l.product_id = product l.seller_id = seller_id pl = panel_id.line_ids.filtered(lambda x: x.product_id.id == product.id and x.seller_id.id == seller_id.id) if pl: panel_id.sudo().line_ids = [ (1, pl[0].id, {'mold_demand_qty': l.qty, 'mold_expected_arrival_date': l.mold_expected_arrival_date, 'material_expected_delivery_date': l.material_expected_delivery_date, })] # pl._compute_order_lines() pl._compute_demand_qty() pl._compute_order_qty() pl._compute_rest_demand_qty() pl._compute_weight() pl._compute_weight_sub() else: panel_id.sudo().line_ids = [(0, 0, {'product_id': product.id, 'seller_id': seller_id.id, 'supplier_part_no': seller_id.product_code, 'weight': seller_id.weight, 'mold_demand_qty': l.qty, 'description': parse_str(l.name), 'material': product.name, 'mold_expected_arrival_date': l.mold_expected_arrival_date, 'material_expected_delivery_date': l.material_expected_delivery_date, })] # panel_id.sudo().line_ids._compute_order_lines() panel_id.sudo().line_ids._compute_demand_qty() panel_id.sudo().line_ids._compute_order_qty() panel_id.sudo().line_ids._compute_rest_demand_qty() panel_id.sudo().line_ids._compute_weight() panel_id.sudo().line_ids._compute_weight_sub()
def validate_product(self, product, l): invalid_fields = [] supplier = self.env['res.partner'].sudo().search( [('supplier', '=', True), ('ref', '=', parse_str(l.supplier_name))]) if not supplier: invalid_fields.append('supplier_name') return invalid_fields if product: # sellers = product.seller_ids.filtered(lambda x: x.name.ref == parse_str(l.supplier_name)) sellers = product.seller_ids # print(sellers) same_name_seller = [] # for s in product.seller_ids: # sellers.append(s.supplier_name) # has_paint_area = False or not sellers # has_coating = False or not sellers # has_ingot = False or not sellers # if parse_str(l.supplier_name) in sellers: for sl in sellers: data_correct = False has_supplier_name = False has_supplier_part_no = False # or not sellers has_material = False # or not sellers has_net_weight = False # or not sellers # print(sl.supplier_name) # print(parse_str(l.supplier_name)) if sl.name.ref == parse_str(l.supplier_name): has_supplier_name = True # print("has_supplier_name %s" % has_supplier_name) if sl.product_code == parse_str(l.supplier_part_no): has_supplier_part_no = True # print("has_supplier_part_no %s" % has_supplier_part_no) if sl.product_material == parse_str(l.material): has_material = True # print("has_material %s" % has_material) if sl.weight == parse_float(l.net_weight): has_net_weight = True # print("has_net_weight %s" % has_net_weight) if has_supplier_name and has_supplier_part_no and has_material and has_net_weight: data_correct = True break else: continue if not data_correct: invalid_fields.append('supplier_name') invalid_fields.append('supplier_part_no') invalid_fields.append('material') invalid_fields.append('net_weight') else: invalid_fields.append('*') # append('*') means no product exists. return invalid_fields # for seller in sellers: # if seller.product_code == parse_str(l.supplier_part_no): # has_supplier_part_no = True # if seller.material == parse_str(l.material): # has_material = True # if seller.weight == parse_float(l.net_weight): # has_net_weight = True # if seller.paint_area == parse_str(l.paint_area): # has_paint_area = True # if seller.coating == parse_str(l.coating): # has_coating = True # if seller.ingot == parse_str(l.ingot): # has_ingot = True # if not has_supplier_part_no: # invalid_fields.append('supplier_part_no') # if not has_material: # invalid_fields.append('material') # if not has_net_weight: # invalid_fields.append('net_weight') # if not has_paint_area: # invalid_fields.append('paint_area') # if not has_coating: # invalid_fields.append('coating') # if not has_ingot: # invalid_fields.append('ingot') # if product.weight != parse_float(l.net_weight): # invalid_fields.append('net_weight') # if product.material != parse_str(l.material): # invalid_fields.append('material') # if product.coating and product.coating != parse_str(l.coating): # invalid_fields.append('coating') # if product.ingot and product.ingot != parse_str(l.ingot): # invalid_fields.append('ingot')
def act_import(self): project_id = self.env.user.project_id attr_id = self.env['product.attribute'].with_context(lang=None).search( [('name', '=', 'Extrusion Number')]) length_id = self.env['product.attribute'].with_context( lang=None).search([('name', '=', 'Length')]) for d in self: if d.demand_line_ids.filtered( lambda x: x.invalid_fields and len(x.invalid_fields) > 5): raise UserError( _('Please fix the invalid field before import!')) return panel_id = self.env['tokiku.panel'].search([ ('project_id', '=', project_id.id), ('categ_id', '=', d.categ_id.id) ]) # panel_id._compute_order_line_ids() for l in self.demand_line_ids: product_tmpl = self.env['product.template'].with_context( lang=None).search([('name', '=', parse_str(l.material)), ('categ_id', '=', l.demand_id.categ_id.id)]) if not product_tmpl: product_tmpl = self.env['product.template'].create({ 'name': parse_str(l.material), 'categ_id': d.categ_id.id, 'type': 'consu', 'default_code': parse_str(l.name), }) product = self.env['product.product'].sudo().search( [ ('project_id', '=', project_id.id), ('product_tmpl_id', '=', product_tmpl.id), ('name', '=', parse_str(l.material)), ('default_code', '=', l.name), # this field is tokiku default code. ('raw_supplier_name', '=', l.demand_id.supplier.id), ('raw_supplier_part_no', '=', l.supplier_part_no), ('weight', '=', l.net_weight), ('volume', '=', l.order_length) ], limit=1) # print ("product %s" % product) # mold = self.env['product.product'].search( # [('category_code', '=', 'mold'), # ('default_code', '=', l.name)], limit=1) # if product and mold: # product.mold_id = mold.id l.invalid_fields = [] l.product_id = None attr_value = self.env['product.attribute.value'].sudo( ).with_context(lang=None).search([ ('attribute_id', '=', attr_id.id), ('name', '=', parse_str(l.name)) ]) if not attr_value: attr_value = self.env[ 'product.attribute.value'].with_context({ 'active_id': product_tmpl.id }).create({ 'attribute_id': attr_id.id, 'name': parse_str(l.name) }) length_value = self.env['product.attribute.value'].sudo( ).with_context(lang=None).search([ ('attribute_id', '=', length_id.id), ('name', '=', parse_str(l.order_length)) ]) if not length_value: length_value = self.env[ 'product.attribute.value'].with_context({ 'active_id': product_tmpl.id }).create({ 'attribute_id': length_id.id, 'name': parse_str(l.order_length) }) if not product: # elif p.categ_code == 'raw': # mold = self.env['product.product'].search( # [('category_code', '=', 'mold'), # ('default_code', '=', p.name)], limit=1) mold_product = self.env['product.product'].with_context( lang=None).search([('name', '=', 'Die'), ('attribute_value_ids', '=', attr_value.id)]) line_id = product_tmpl.attribute_line_ids.filtered( lambda x: x.attribute_id.id == attr_id.id) if not line_id: line_id = self.env['product.attribute.line'].create({ 'product_tmpl_id': product_tmpl.id, 'attribute_id': attr_id.id }) line_id.value_ids = [(4, attr_value.id)] length_line_id = product_tmpl.attribute_line_ids.filtered( lambda x: x.attribute_id.id == length_id.id) if not length_line_id: length_line_id = self.env[ 'product.attribute.line'].create({ 'product_tmpl_id': product_tmpl.id, 'attribute_id': length_id.id }) length_line_id.value_ids = [(4, length_value.id)] product = self.env['product.product'].create({ 'project_id': project_id.id, 'product_tmpl_id': product_tmpl.id, 'default_code': parse_str(l.name), 'volume': parse_float(l.order_length), 'weight': parse_float(l.net_weight), 'paint_area': mold_product.paint_area, 'coating': mold_product.coating, 'ingot': mold_product.ingot, 'seller_ids': [(0, 0, { 'product_id': product.id, 'name': d.supplier.id, 'product_code': parse_str(l.supplier_part_no), 'min_qty': parse_float(l.min_qty) })], 'attribute_value_ids': [(4, attr_value.id), (4, length_value.id)], 'raw_supplier_name': l.demand_id.supplier.id, 'raw_supplier_part_no': parse_str(l.supplier_part_no), }) # if mold: # product.write({'mold_id': mold.id}) l.product_id = product pl = panel_id.line_ids.filtered( lambda x: x.product_id.id == product.id) # pl._compute_order_lines() pl._compute_demand_qty() pl._compute_order_qty() pl._compute_rest_demand_qty() pl._compute_weight() pl._compute_weight_sub() if not pl: panel_id.sudo().line_ids = [(0, 0, { 'product_id': product.id, 'supplier_part_no': product.raw_supplier_part_no, 'supplier_name': product.raw_supplier_name, 'weight': product.weight, 'material': l.material, 'cutting_length': product.volume, 'demand_qty': l.qty })] panel_id.sudo().line_ids._compute_order_lines() panel_id.sudo().line_ids._compute_demand_qty() panel_id.sudo().line_ids._compute_order_qty() panel_id.sudo().line_ids._compute_rest_demand_qty() panel_id.sudo().line_ids._compute_weight() panel_id.sudo().line_ids._compute_weight_sub()
def _onchange_partner_id(self): get_supplier_id = self.env.context.get('default_supplier_id') self.partner_id = get_supplier_id get_order_id = self.env.context.get('order_id') order = self.env['purchase.order'].browse(get_order_id) get_demand_id = self.env.context.get('demand_id') demand = self.env['tokiku.demand'].browse(get_demand_id) material_categ = {} wizard_lines = [] name = {} unit_weight = {} length = {} demand_qty = {} # 需求支數 demand_weight = {} # 需求支數 rest_demand_qty = {} rest_demand_weight = {} # 需求重量 order_qty = {} # 訂購支數 order_weight = {} if demand: for line in demand.demand_line_ids: #group_key = "%s/%s" % (line.material, line.net_weight) group_key = "%s" % (line.material) if group_key in name: demand_qty[group_key] += parse_int(line.qty) else: name[group_key] = line.material demand_qty[group_key] = parse_int(line.qty) unit_weight[group_key] = parse_float(line.net_weight) # demand_weight[group_key] = unit_weight[group_key] * demand_qty[group_key] # round ((unit_weight[group_key] * demand_qty[group_key]), 3) demand_weight[group_key] = parse_float( line.net_weight) * (parse_float(line.order_length) / 1000) * demand_qty[group_key] for categ_line in name: wizard_lines.append(( 0, 0, { 'name': name[categ_line], 'demand_qty': demand_qty[categ_line], 'unit_weight': unit_weight[categ_line], 'demand_weight': demand_weight[categ_line], # 'demand_weight': unit_weight[categ_line] * float(demand_qty[categ_line]), })) elif order.categ_code == 'raw': for line in order.order_line: if material_categ.has_key(line.name): material_categ[line.name] += line.raw_pricing_total_weight else: material_categ[line.name] = line.raw_pricing_total_weight for categ_line in material_categ: wizard_lines.append((0, 0, { 'name': categ_line, 'raw_pricing_total_weight': material_categ[categ_line], 'product_id': line.product_id.id, })) elif order.categ_code == 'aluminum': for line in order.order_line: group_key = "%s" % line.material if group_key in name: demand_qty[group_key] += line.demand_qty order_qty[group_key] += line.product_qty rest_demand_qty[group_key] = demand_qty[ group_key] - order_qty[group_key] rest_demand_weight[ group_key] = line.refine_pricing_single_weight * rest_demand_qty[ group_key] order_weight[ group_key] += line.refine_pricing_single_weight * line.product_qty demand_weight[ group_key] = line.refine_pricing_single_weight * demand_qty[ group_key] else: name[group_key] = line.material unit_weight[group_key] = line.unit_weight demand_qty[group_key] = line.demand_qty order_qty[group_key] = line.product_qty rest_demand_qty[group_key] = demand_qty[ group_key] - order_qty[group_key] rest_demand_weight[ group_key] = line.refine_pricing_single_weight * rest_demand_qty[ group_key] order_weight[ group_key] = line.refine_pricing_single_weight * line.product_qty demand_weight[ group_key] = line.refine_pricing_single_weight * demand_qty[ group_key] for categ_line in name: wizard_lines.append((0, 0, { 'name': name[categ_line], 'unit_weight': unit_weight[categ_line], 'demand_qty': demand_qty[categ_line], 'demand_weight': demand_weight[categ_line], 'rest_demand_qty': rest_demand_qty[group_key], 'rest_demand_weight': rest_demand_weight[categ_line], 'order_qty': order_qty[categ_line], 'order_weight': order_weight[categ_line], })) # order_weight = fields.Float('Order Weight') # rest_order_qty = fields.Float('Rest Order Qty') # rest_order_weight = fields.Float('Rest Order Weight') # received_qty = fields.Float('Received Qty') # not_received_qty = fields.Float('Not Received Qty') # product_id = fields.Many2one('product.product', string='Product') elif order.categ_code == 'glass': for line in order.order_line: group_key = "%s" % line.material if group_key in name: demand_qty[group_key] += line.demand_qty order_qty[group_key] += line.product_qty rest_demand_qty[group_key] = demand_qty[ group_key] - order_qty[group_key] rest_demand_weight[ group_key] = line.refine_pricing_single_weight * rest_demand_qty[ group_key] order_weight[ group_key] += line.refine_pricing_single_weight * line.product_qty demand_weight[ group_key] = line.refine_pricing_single_weight * demand_qty[ group_key] else: name[group_key] = line.material unit_weight[group_key] = line.unit_weight demand_qty[group_key] = line.demand_qty order_qty[group_key] = line.product_qty rest_demand_qty[group_key] = demand_qty[ group_key] - order_qty[group_key] rest_demand_weight[ group_key] = line.refine_pricing_single_weight * rest_demand_qty[ group_key] order_weight[ group_key] = line.refine_pricing_single_weight * line.product_qty demand_weight[ group_key] = line.refine_pricing_single_weight * demand_qty[ group_key] for categ_line in name: wizard_lines.append((0, 0, { 'name': name[categ_line], 'unit_weight': unit_weight[categ_line], 'demand_qty': demand_qty[categ_line], 'demand_weight': demand_weight[categ_line], 'rest_demand_qty': rest_demand_qty[group_key], 'rest_demand_weight': rest_demand_weight[categ_line], 'order_qty': order_qty[categ_line], 'order_weight': order_weight[categ_line], })) elif order.categ_code == 'plate': for line in order.order_line: group_key = "%s" % line.material if group_key in name: demand_qty[group_key] += line.demand_qty order_qty[group_key] += line.product_qty rest_demand_qty[group_key] = demand_qty[ group_key] - order_qty[group_key] rest_demand_weight[ group_key] = line.refine_pricing_single_weight * rest_demand_qty[ group_key] order_weight[ group_key] += line.refine_pricing_single_weight * line.product_qty demand_weight[ group_key] = line.refine_pricing_single_weight * demand_qty[ group_key] else: name[group_key] = line.material unit_weight[group_key] = line.unit_weight demand_qty[group_key] = line.demand_qty order_qty[group_key] = line.product_qty rest_demand_qty[group_key] = demand_qty[ group_key] - order_qty[group_key] rest_demand_weight[ group_key] = line.refine_pricing_single_weight * rest_demand_qty[ group_key] order_weight[ group_key] = line.refine_pricing_single_weight * line.product_qty demand_weight[ group_key] = line.refine_pricing_single_weight * demand_qty[ group_key] for categ_line in name: wizard_lines.append((0, 0, { 'name': name[categ_line], 'unit_weight': unit_weight[categ_line], 'demand_qty': demand_qty[categ_line], 'demand_weight': demand_weight[categ_line], 'rest_demand_qty': rest_demand_qty[group_key], 'rest_demand_weight': rest_demand_weight[categ_line], 'order_qty': order_qty[categ_line], 'order_weight': order_weight[categ_line], })) elif order.categ_code == 'steel': for line in order.order_line: group_key = "%s" % line.material if group_key in name: demand_qty[group_key] += line.demand_qty order_qty[group_key] += line.product_qty rest_demand_qty[group_key] = demand_qty[ group_key] - order_qty[group_key] rest_demand_weight[ group_key] = line.refine_pricing_single_weight * rest_demand_qty[ group_key] order_weight[ group_key] += line.refine_pricing_single_weight * line.product_qty demand_weight[ group_key] = line.refine_pricing_single_weight * demand_qty[ group_key] else: name[group_key] = line.material unit_weight[group_key] = line.unit_weight demand_qty[group_key] = line.demand_qty order_qty[group_key] = line.product_qty rest_demand_qty[group_key] = demand_qty[ group_key] - order_qty[group_key] rest_demand_weight[ group_key] = line.refine_pricing_single_weight * rest_demand_qty[ group_key] order_weight[ group_key] = line.refine_pricing_single_weight * line.product_qty demand_weight[ group_key] = line.refine_pricing_single_weight * demand_qty[ group_key] for categ_line in name: wizard_lines.append((0, 0, { 'name': name[categ_line], 'unit_weight': unit_weight[categ_line], 'demand_qty': demand_qty[categ_line], 'demand_weight': demand_weight[categ_line], 'rest_demand_qty': rest_demand_qty[group_key], 'rest_demand_weight': rest_demand_weight[categ_line], 'order_qty': order_qty[categ_line], 'order_weight': order_weight[categ_line], })) elif order.categ_code == 'iron': for line in order.order_line: group_key = "%s" % line.material if group_key in name: demand_qty[group_key] += line.demand_qty order_qty[group_key] += line.product_qty rest_demand_qty[group_key] = demand_qty[ group_key] - order_qty[group_key] rest_demand_weight[ group_key] = line.refine_pricing_single_weight * rest_demand_qty[ group_key] order_weight[ group_key] += line.refine_pricing_single_weight * line.product_qty demand_weight[ group_key] = line.refine_pricing_single_weight * demand_qty[ group_key] else: name[group_key] = line.material unit_weight[group_key] = line.unit_weight demand_qty[group_key] = line.demand_qty order_qty[group_key] = line.product_qty rest_demand_qty[group_key] = demand_qty[ group_key] - order_qty[group_key] rest_demand_weight[ group_key] = line.refine_pricing_single_weight * rest_demand_qty[ group_key] order_weight[ group_key] = line.refine_pricing_single_weight * line.product_qty demand_weight[ group_key] = line.refine_pricing_single_weight * demand_qty[ group_key] for categ_line in name: wizard_lines.append((0, 0, { 'name': name[categ_line], 'unit_weight': unit_weight[categ_line], 'demand_qty': demand_qty[categ_line], 'demand_weight': demand_weight[categ_line], 'rest_demand_qty': rest_demand_qty[group_key], 'rest_demand_weight': rest_demand_weight[categ_line], 'order_qty': order_qty[categ_line], 'order_weight': order_weight[categ_line], })) self.tmp_grid = wizard_lines