56 lines
2.7 KiB
Python
56 lines
2.7 KiB
Python
from odoo import models, fields, api, SUPERUSER_ID
|
|
|
|
|
|
class FixtureMaterialSearch(models.Model):
|
|
_name = 'sf.fixture.material.search'
|
|
_description = '夹具物料搜索'
|
|
|
|
product_id = fields.Many2one('product.product', string='夹具物料产品')
|
|
|
|
name = fields.Char('名称', related='product_id.name')
|
|
code = fields.Char('编码')
|
|
fixture_material_id = fields.Many2one('sf.fixture.material', '夹具物料',
|
|
related='product_id.fixture_material_id',
|
|
store=True,
|
|
group_expand='_read_group_fixture_material_id')
|
|
fixture_material_name = fields.Char('物料名称', related='product_id.fixture_material_id.name')
|
|
fixture_model_id = fields.Many2one('sf.fixture.model', '夹具型号',
|
|
related='product_id.fixture_model_id')
|
|
specification_fixture_id = fields.Many2one('sf.fixture.materials.basic.parameters', '规格',
|
|
related='product_id.specification_fixture_id')
|
|
image = fields.Binary('图片', related='product_id.image_1920')
|
|
number = fields.Integer('总数量', compute='_compute_number')
|
|
usable_num = fields.Integer('可用数量', compute='_compute_number')
|
|
have_been_used_num = fields.Integer('在用数量', compute='_compute_number')
|
|
scrap_num = fields.Integer('报废数量', compute='_compute_number')
|
|
|
|
barcode_ids = fields.One2many('stock.lot', 'fixture_material_search_id', string='序列号', readonly=True)
|
|
|
|
@api.depends('barcode_ids')
|
|
def _compute_number(self):
|
|
for record in self:
|
|
usable_num = 0
|
|
have_been_used_num = 0
|
|
scrap_num = 0
|
|
if record.barcode_ids:
|
|
record.number = len(record.barcode_ids)
|
|
for barcode_id in record.barcode_ids:
|
|
if barcode_id.quant_ids:
|
|
if barcode_id.quant_ids[-1].location_id.name not in '夹具房':
|
|
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_fixture_material_id(self, categories, domain, order):
|
|
fixture_material_id = categories._search([], order=order, access_rights_uid=SUPERUSER_ID)
|
|
return categories.browse(fixture_material_id)
|