1、重构刀具物料查询模型;2、新增产品创建时产品类别为刀具时,创建刀具物料查询模型记录;3、新增序列号和刀具物料查询模型的关联字段,新增刀具物料是否可用状态字段;并在新增序列号记录时,如果关联的产品的产品类别为刀具时,对对应刀具物料查询记录进行关联;
This commit is contained in:
@@ -32,6 +32,19 @@ class SfMaintenanceEquipmentTool(models.Model):
|
||||
class StockLot(models.Model):
|
||||
_inherit = 'stock.lot'
|
||||
|
||||
tool_material_search_id = fields.Many2one('sf.tool.material.search', string='刀具物料搜索')
|
||||
tool_material_status = fields.Selection([('可用', '可用'), ('在用', '在用'), ('报废', '报废')], string='状态',
|
||||
compute='_compute_tool_material_status')
|
||||
|
||||
@api.depends('quant_ids')
|
||||
def _compute_tool_material_status(self):
|
||||
for record in self:
|
||||
if record:
|
||||
if record.quant_ids[-1].location_id.name == '刀具组装位置':
|
||||
record.tool_material_status = '在用'
|
||||
else:
|
||||
record.tool_material_status = '可用'
|
||||
|
||||
@api.model
|
||||
def name_search(self, name='', args=None, operator='ilike', limit=100):
|
||||
# 调用父类的name_search方法
|
||||
@@ -52,3 +65,30 @@ class StockLot(models.Model):
|
||||
if objs.product_id.categ_id.name == '刀具':
|
||||
raise ValidationError('这是【%s】物料,请扫入正确的【%s】物料!!!' % (
|
||||
objs.product_id.cutting_tool_material_id.name, args[2][2]))
|
||||
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
records = super(StockLot, self).create(vals_list)
|
||||
for record in records:
|
||||
if record.product_id.categ_id.name == '刀具':
|
||||
tool_material_search = self.env['sf.tool.material.search'].sudo().search(
|
||||
[('cutting_tool_material_id', '=', record.product_id.cutting_tool_material_id.id),
|
||||
('cutting_tool_standard_library_id', '=', record.product_id.cutting_tool_model_id.id),
|
||||
('specification_id', '=', record.product_id.specification_id.id)])
|
||||
if tool_material_search:
|
||||
record.tool_material_search_id = tool_material_search
|
||||
return records
|
||||
|
||||
|
||||
class ProductProduct(models.Model):
|
||||
_inherit = 'product.product'
|
||||
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
records = super(ProductProduct, self).create(vals_list)
|
||||
for record in records:
|
||||
if record.categ_id.name == '刀具':
|
||||
self.env['sf.tool.material.search'].sudo().create({
|
||||
'product_id': record.id
|
||||
})
|
||||
return records
|
||||
|
||||
@@ -5,7 +5,7 @@ from odoo import fields, models, api, SUPERUSER_ID
|
||||
# from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
# 刀具物料搜索
|
||||
# 刀具物料搜索(待删除)
|
||||
class SfToolMaterialSearch(models.Model):
|
||||
_name = 'sf.tool.material.search'
|
||||
_description = '刀具物料搜索'
|
||||
@@ -302,3 +302,55 @@ class SfToolMaterialSearch(models.Model):
|
||||
warehouse_area = fields.Char('库区')
|
||||
warehouse_location = fields.Char('库位')
|
||||
three_d_model = fields.Many2one('ir.attachment', '3D模型')
|
||||
|
||||
|
||||
class ToolMaterial(models.Model):
|
||||
_name = 'sf.tool.material.search'
|
||||
_description = '刀具物料搜索'
|
||||
|
||||
product_id = fields.Many2one('product.product', string='刀具物料产品')
|
||||
|
||||
name = fields.Char('名称', related='product_id.name')
|
||||
cutting_tool_material_id = fields.Many2one('sf.cutting.tool.material', '刀具物料',
|
||||
related='product_id.cutting_tool_material_id',
|
||||
store=True,
|
||||
group_expand='_read_group_cutting_tool_material_id')
|
||||
tool_material_name = fields.Char('物料名称', related='product_id.cutting_tool_material_id.name')
|
||||
cutting_tool_standard_library_id = fields.Many2one('sf.cutting_tool.standard.library', '刀具型号',
|
||||
related='product_id.cutting_tool_model_id')
|
||||
specification_id = fields.Many2one('sf.tool.materials.basic.parameters', '规格',
|
||||
related='product_id.specification_id')
|
||||
image = fields.Binary('图片', related='product_id.image_1920')
|
||||
number = fields.Integer('总数量', readonly=True, compute='_compute_number')
|
||||
usable_num = fields.Integer('可用数量', readonly=True)
|
||||
have_been_used_num = fields.Integer('在用数量', readonly=True)
|
||||
scrap_num = fields.Integer('报废数量', readonly=True)
|
||||
|
||||
barcode_ids = fields.One2many('stock.lot', 'tool_material_search_id', string='序列号', readonly=True)
|
||||
|
||||
@api.depends('barcode_ids')
|
||||
def _compute_number(self):
|
||||
usable_num = 0
|
||||
have_been_used_num = 0
|
||||
scrap_num = 0
|
||||
for record in self:
|
||||
if record.barcode_ids:
|
||||
record.number = len(record.barcode_ids)
|
||||
for barcode_id in record.barcode_ids:
|
||||
if barcode_id.quant_ids[-1].location_id.name == '刀具组装位置':
|
||||
have_been_used_num = have_been_used_num + 1
|
||||
else:
|
||||
usable_num = usable_num + 1
|
||||
record.usable_num = usable_num
|
||||
record.have_been_used_num = have_been_used_num
|
||||
record.scrap_num = scrap_num
|
||||
else:
|
||||
record.number = 0
|
||||
record.usable_num = 0
|
||||
record.have_been_used_num = 0
|
||||
record.scrap_num = 0
|
||||
|
||||
@api.model
|
||||
def _read_group_cutting_tool_material_id(self, categories, domain, order):
|
||||
cutting_tool_material_id = categories._search([], order=order, access_rights_uid=SUPERUSER_ID)
|
||||
return categories.browse(cutting_tool_material_id)
|
||||
|
||||
Reference in New Issue
Block a user