1、重构刀具物料查询模型;2、新增产品创建时产品类别为刀具时,创建刀具物料查询模型记录;3、新增序列号和刀具物料查询模型的关联字段,新增刀具物料是否可用状态字段;并在新增序列号记录时,如果关联的产品的产品类别为刀具时,对对应刀具物料查询记录进行关联;
This commit is contained in:
@@ -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