bom物料清单
This commit is contained in:
@@ -8,4 +8,6 @@ from . import fixture_material_search
|
||||
from . import fixture_enroll
|
||||
from . import temporary_data_processing_methods
|
||||
from . import stock
|
||||
|
||||
from . import jikimo_bom
|
||||
from . import tool_inventory
|
||||
from . import functional_cutting_tool_model
|
||||
@@ -0,0 +1,6 @@
|
||||
from odoo import models, fields
|
||||
|
||||
|
||||
class SyncFunctionalCuttingToolModel(models.Model):
|
||||
_inherit = 'sf.functional.cutting.tool.model'
|
||||
cutting_tool_type_ids = fields.Many2many('sf.cutting.tool.type', string='整体式刀具物料')
|
||||
96
sf_tool_management/models/jikimo_bom.py
Normal file
96
sf_tool_management/models/jikimo_bom.py
Normal file
@@ -0,0 +1,96 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from xml import etree
|
||||
|
||||
from odoo import models, fields, api, Command
|
||||
from odoo.http import request
|
||||
|
||||
|
||||
class jikimo_bom(models.Model):
|
||||
_name = 'jikimo.bom'
|
||||
_description = '功能刀具物料清单'
|
||||
tool_inventory_id = fields.Many2one('sf.tool.inventory', '功能刀具清单')
|
||||
tool_name = fields.Char(related="tool_inventory_id.name", string='功能刀具名称')
|
||||
functional_cutting_tool_model_id = fields.Many2one(related='tool_inventory_id.functional_cutting_tool_model_id',
|
||||
string='功能刀具类型')
|
||||
tool_groups_id = fields.Many2one(related='tool_inventory_id.tool_groups_id', string='刀具组')
|
||||
tool_length = fields.Float(related='tool_inventory_id.tool_length', string='刀具总长(mm)')
|
||||
diameter = fields.Float(related='tool_inventory_id.diameter', string='直径(mm)')
|
||||
angle = fields.Float(related='tool_inventory_id.angle', string='R角(mm)')
|
||||
extension = fields.Float(related='tool_inventory_id.extension', string='伸出长度(mm)')
|
||||
product_ids = fields.Many2many('product.product', string='产品')
|
||||
knife_handle_model = fields.Selection(related='tool_inventory_id.knife_handle_model', string='使用刀柄型号')
|
||||
options = fields.Char('产品清单')
|
||||
|
||||
def name_get(self):
|
||||
result = []
|
||||
for bom in self:
|
||||
result.append((bom.id, '功能刀具物料清单'))
|
||||
return result
|
||||
def bom_product_domains(self, assembly_options):
|
||||
self.options = assembly_options
|
||||
cutting_tool_materials = self.env['sf.cutting.tool.material'].search(
|
||||
[('name', 'in', assembly_options.split('+'))])
|
||||
domains = []
|
||||
for index, option in enumerate(cutting_tool_materials):
|
||||
domain = ['&',('cutting_tool_material_id', '=', option.id),
|
||||
("cutting_tool_type_id", "in",
|
||||
self.tool_inventory_id.functional_cutting_tool_model_id.cutting_tool_type_ids.ids)]
|
||||
if option.name == '刀柄':
|
||||
domain = ['&']+domain+[ ("cutting_tool_taper_shank_model", "=", self.tool_inventory_id.knife_handle_model)]
|
||||
|
||||
if option.name == '整体式刀具':
|
||||
domain=['&']+domain+[
|
||||
'|',
|
||||
# 刀具直径
|
||||
('cutting_tool_blade_diameter', '=', self.tool_inventory_id.diameter),
|
||||
|
||||
# r角
|
||||
('cutting_tool_blade_tip_working_size', '=', self.tool_inventory_id.angle)]
|
||||
if option.name == '刀杆':
|
||||
domain = ['&'] + domain + [
|
||||
("cutting_tool_cutter_arbor_diameter", "=", self.tool_inventory_id.diameter)]
|
||||
if option.name == '刀片':
|
||||
domain = ['&'] + domain + [
|
||||
("cutting_tool_blade_tip_circular_arc_radius", "=", self.tool_inventory_id.angle)]
|
||||
if option.name == '刀盘':
|
||||
domain = ['&'] + domain + [
|
||||
("cutting_tool_cutter_head_diameter", "=", self.tool_inventory_id.diameter)]
|
||||
domains=domains+domain
|
||||
if index != 0:
|
||||
domains = ['|'] + domains
|
||||
# wqwqwe = self.env['product.product'].search(ddd)
|
||||
# product = self.env['product.product'].search(domain)
|
||||
# if product:
|
||||
# products = products + product
|
||||
return domains
|
||||
|
||||
def generate_bill_materials(self, assembly_options):
|
||||
domains=self.bom_product_domains(assembly_options)
|
||||
products = self.env['product.product'].search(domains)
|
||||
if products:
|
||||
self.product_ids = [Command.set(products.ids)]
|
||||
# if option.name == '刀盘':
|
||||
# hilt = self.env['product.product'].search(
|
||||
# [('cutting_tool_blade_diameter', '=', self.tool_inventory_id.diameter),
|
||||
# ('cutting_tool_material_id', '=', option.id)])
|
||||
# self.product_ids = [Command.set(hilt.ids)]k
|
||||
|
||||
|
||||
class jikimo_bom_line(models.Model):
|
||||
_name = 'jikimo.bom.line'
|
||||
_description = 'jikimo.bom.line'
|
||||
|
||||
name = fields.Char()
|
||||
|
||||
|
||||
class ProductProduct(models.Model):
|
||||
_inherit = 'product.product'
|
||||
|
||||
def search(self, args, offset=0, limit=None, order=None, count=False):
|
||||
# 你可以在这里修改 `args` 以调整搜索条件
|
||||
# 例如,添加额外的搜索条件
|
||||
if self.env.context.get('jikimo_bom_product'):
|
||||
bom_id = self.env['jikimo.bom'].browse(request.session.get('jikimo_bom_product').get('bom_id'))
|
||||
domains = bom_id.bom_product_domains(bom_id.options)
|
||||
args=args+domains
|
||||
return super(ProductProduct, self).search(args, offset=offset, limit=limit, order=order, count=count)
|
||||
34
sf_tool_management/models/tool_inventory.py
Normal file
34
sf_tool_management/models/tool_inventory.py
Normal file
@@ -0,0 +1,34 @@
|
||||
from odoo import models, fields
|
||||
from odoo.http import request
|
||||
|
||||
|
||||
class ToolInventory(models.Model):
|
||||
_inherit = 'sf.tool.inventory'
|
||||
_description = '功能刀具清单'
|
||||
knife_handle_model = fields.Selection([('BT30', 'BT30'), ('BT40', 'BT40'), ('BT50', 'BT50'), ('GSK30', 'GSK30'), ('GSK40', 'GSK40'), ('GSK50', 'GSK50')], string='使用刀柄型号')
|
||||
jikimo_bom_ids = fields.One2many('jikimo.bom','tool_inventory_id', 'bom单')
|
||||
def bom_mainfest(self):
|
||||
|
||||
jikimo_bom_ids = self.mapped('jikimo_bom_ids')
|
||||
if not jikimo_bom_ids:
|
||||
self._bom_mainfest()
|
||||
return self.bom_mainfest()
|
||||
request.session['jikimo_bom_product'] = {'bom_id': int(self.jikimo_bom_ids)}
|
||||
# context = dict(self.env.context)
|
||||
# context.update({'jikimo_bom_product': self.jikimo_bom_ids.options})
|
||||
# if self.functional_cutting_tool_model_id.cutting_tool_type_ids:
|
||||
# context.update({'jikimo_bom_product_cutting_tool_type': self.functional_cutting_tool_model_id.cutting_tool_type_ids.ids})
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
'name': '刀具组装清单',
|
||||
'res_model': 'jikimo.bom',
|
||||
'view_mode': 'form',
|
||||
'view_id': self.env.ref('sf_tool_management.view_jikimo_bom_form').id,
|
||||
'res_id': int(self.jikimo_bom_ids),
|
||||
'target': 'current', # Use 'new' to open in a new window/tab
|
||||
# {'jikimo_bom_product': self.jikimo_bom_ids.options}
|
||||
}
|
||||
|
||||
# 创建bom单
|
||||
def _bom_mainfest(self):
|
||||
self.env['jikimo.bom'].create({'tool_inventory_id':self.id})
|
||||
Reference in New Issue
Block a user