53 lines
2.7 KiB
Python
53 lines
2.7 KiB
Python
# -*- coding: utf-8 -*-
|
|
from odoo import fields, models, api, SUPERUSER_ID
|
|
|
|
|
|
class ToolMaterial(models.Model):
|
|
_name = 'sf.tool.material.search'
|
|
_description = '刀具物料搜索'
|
|
|
|
product_id = fields.Many2one('product.product', string='刀具物料产品')
|
|
|
|
name = fields.Char('名称', related='product_id.name')
|
|
code = fields.Char('编码')
|
|
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('总数量', compute='_compute_number', store=True)
|
|
usable_num = fields.Integer('可用数量', compute='_compute_number', store=True)
|
|
have_been_used_num = fields.Integer('在用数量', compute='_compute_number', store=True)
|
|
scrap_num = fields.Integer('报废数量', compute='_compute_number', store=True)
|
|
|
|
barcode_ids = fields.One2many('stock.lot', 'tool_material_search_id', string='序列号', readonly=True)
|
|
|
|
@api.depends('product_id.stock_quant_ids.quantity')
|
|
def _compute_number(self):
|
|
for record in self:
|
|
usable_num = 0
|
|
have_been_used_num = 0
|
|
scrap_num = 0
|
|
for quant in record.product_id.stock_quant_ids:
|
|
location = quant.location_id.name
|
|
if location == '刀具房':
|
|
usable_num += quant.quantity
|
|
elif location == '刀具组装位置':
|
|
have_been_used_num += quant.quantity
|
|
elif location == 'Scrap':
|
|
scrap_num += quant.quantity
|
|
record.usable_num = usable_num
|
|
record.have_been_used_num = have_been_used_num
|
|
record.scrap_num = scrap_num
|
|
record.number = usable_num + have_been_used_num + scrap_num
|
|
|
|
@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)
|