From 8dfef16b519ff2a4f94f98df7479d8d62831eb6c Mon Sep 17 00:00:00 2001 From: yuxianghui <3437689193@qq.com> Date: Thu, 18 Apr 2024 15:38:16 +0800 Subject: [PATCH 1/4] =?UTF-8?q?1=E3=80=81=E4=BA=A7=E5=93=81=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E3=80=81=E5=88=B6=E9=80=A0=E8=AE=A2=E5=8D=95=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E3=80=81=E5=B7=A5=E5=8D=95=E6=A8=A1=E5=9E=8B=EF=BC=8C?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=BA=E5=B7=A5=E7=BC=96=E7=A8=8B=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=EF=BC=9B2=E3=80=81=E6=94=BE=E5=BC=80=E5=B7=A5?= =?UTF-8?q?=E5=8D=95=E6=89=AB=E6=8F=8F=E7=BB=91=E5=AE=9ARfid=E7=9A=84?= =?UTF-8?q?=E6=A3=80=E9=AA=8C=E5=8A=9F=E8=83=BD=EF=BC=9B3=E3=80=81bfm?= =?UTF-8?q?=E4=B8=8B=E5=8D=95=E5=88=9B=E5=BB=BA=E4=BA=A7=E5=93=81=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E4=BA=BA=E5=B7=A5=E6=8A=A5=E4=BB=B7=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E5=86=85=E5=AE=B9=EF=BC=9B4=E3=80=81=E4=BC=98=E5=8C=96CNC?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=94=A8=E5=88=80=E6=A3=80=E9=AA=8C=E5=BA=93?= =?UTF-8?q?=E5=8C=BA=E6=98=AF=E5=90=A6=E6=9C=89=E5=88=80=E7=9A=84=E6=B5=81?= =?UTF-8?q?=E7=A8=8B=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_manufacturing/models/mrp_production.py | 2 + sf_manufacturing/models/mrp_workorder.py | 10 ++-- sf_manufacturing/models/product_template.py | 2 +- sf_sale/models/sale_order.py | 6 +++ sf_tool_management/models/base.py | 53 +++++++++++++-------- sf_tool_management/models/mrp_workorder.py | 1 + sf_warehouse/models/model.py | 2 +- 7 files changed, 50 insertions(+), 26 deletions(-) diff --git a/sf_manufacturing/models/mrp_production.py b/sf_manufacturing/models/mrp_production.py index dff2763b..24ac58b2 100644 --- a/sf_manufacturing/models/mrp_production.py +++ b/sf_manufacturing/models/mrp_production.py @@ -57,6 +57,8 @@ class MrpProduction(models.Model): production_line_state = fields.Selection([('待上产线', '待上产线'), ('已上产线', '已上产线'), ('已下产线', '已下产线')], string='上/下产线', default='待上产线') + manual_quotation = fields.Boolean('人工编程', default=False) + @api.depends( 'move_raw_ids.state', 'move_raw_ids.quantity_done', 'move_finished_ids.state', 'workorder_ids.state', 'product_qty', 'qty_producing', 'schedule_state') diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py index 134922d1..c9d72b79 100644 --- a/sf_manufacturing/models/mrp_workorder.py +++ b/sf_manufacturing/models/mrp_workorder.py @@ -46,6 +46,8 @@ class ResMrpWorkOrder(models.Model): ], string="工序类型") results = fields.Char('结果') + manual_quotation = fields.Boolean('人工编程', default=False) + @api.onchange('users_ids') def get_user_permissions(self): uid = self.env.uid @@ -984,9 +986,9 @@ class SfWorkOrderBarcodes(models.Model): workorder = self.env['mrp.workorder'].browse(self.ids) # workorder = self.env['mrp.workorder'].search( # [('routing_type', '=', '装夹预调'), ('production_id', '=', self.production_id.id)]) - # workorder_old = self.env['mrp.workorder'].search([('rfid_code', '=', barcode)]) - # if workorder_old: - # raise UserError('该托盘已绑定工件,请先解除绑定!!!') + workorder_old = self.env['mrp.workorder'].search([('rfid_code', '=', barcode)]) + if workorder_old: + raise UserError('该托盘已绑定工件,请先解除绑定!!!') if workorder: if workorder.routing_type == '装夹预调': if workorder.state in ['done']: @@ -1046,7 +1048,7 @@ class SfWorkOrderBarcodes(models.Model): for item in workorder_rfid: if item.state == "progress": item.write({'rfid_code': barcode}) - # raise UserError('该托盘信息不存在!!!') + raise UserError('该托盘信息不存在!!!') # stock_move_line = self.env['stock.move.line'].search([('lot_name', '=', barcode)]) # if stock_move_line.product_id.categ_type == '夹具': # workorder.write({ diff --git a/sf_manufacturing/models/product_template.py b/sf_manufacturing/models/product_template.py index f3cba150..57ad0eaa 100644 --- a/sf_manufacturing/models/product_template.py +++ b/sf_manufacturing/models/product_template.py @@ -10,7 +10,6 @@ from OCC.Extend.DataExchange import read_step_file from OCC.Extend.DataExchange import write_stl_file - class ResProductMo(models.Model): _inherit = 'product.template' @@ -616,6 +615,7 @@ class ResProductMo(models.Model): 'process_parameters_code') else self.get_process_parameters_id(item['process_parameters_code']), 'model_remark': item['remark'], 'default_code': '%s-%s' % (order_number, i), + 'manual_quotation': item['manual_quotation'] or False, 'active': True, } copy_product_id.sudo().write(vals) diff --git a/sf_sale/models/sale_order.py b/sf_sale/models/sale_order.py index 05523194..379ff199 100644 --- a/sf_sale/models/sale_order.py +++ b/sf_sale/models/sale_order.py @@ -142,6 +142,12 @@ class ResaleOrderLine(models.Model): check_status = fields.Selection(related='order_id.check_status') +class ProductTemplate(models.Model): + _inherit = 'product.template' + + manual_quotation = fields.Boolean('人工编程', default=False) + + class RePurchaseOrder(models.Model): _inherit = 'purchase.order' diff --git a/sf_tool_management/models/base.py b/sf_tool_management/models/base.py index 56391077..01c3de46 100644 --- a/sf_tool_management/models/base.py +++ b/sf_tool_management/models/base.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +import logging + from datetime import timedelta from odoo import SUPERUSER_ID from odoo import fields, models, api @@ -191,7 +193,7 @@ class CAMWorkOrderProgramKnifePlan(models.Model): machine_table_name_id = fields.Many2one('maintenance.equipment', string='机床名称', domain="[('production_line_id', '=', production_line_id)]") machine_table_name = fields.Char(string='机台号', readonly=True, related='machine_table_name_id.name') - cutter_spacing_code_id = fields.Many2one('maintenance.equipment.tool', string='刀位号', required=True, + cutter_spacing_code_id = fields.Many2one('maintenance.equipment.tool', string='刀位号', domain="[('equipment_id', '=', machine_table_name_id)]") whether_standard_knife = fields.Boolean(string='是否标准刀', default=True) need_knife_time = fields.Datetime(string='用刀时间', readonly=False) @@ -201,19 +203,20 @@ class CAMWorkOrderProgramKnifePlan(models.Model): barcode_id = fields.Many2one('stock.lot', string='功能刀具序列号', domain=[('product_id.name', '=', '功能刀具')]) - functional_tool_name = fields.Char(string='功能刀具名称', compute='_compute_functional_tool_name') - functional_tool_type_id = fields.Many2one('sf.functional.cutting.tool.model', string='功能刀具类型', readonly=False) - tool_groups_id = fields.Many2one('sf.tool.groups', '刀具组') - diameter = fields.Integer(string='刀具直径(mm)', readonly=False) - tool_included_angle = fields.Float(string='刀尖R角(mm)', readonly=False) - tool_loading_length = fields.Float(string='总长度(mm)', readonly=False) + functional_tool_name = fields.Char(string='功能刀具名称', readonly=True) + functional_tool_type_id = fields.Many2one('sf.functional.cutting.tool.model', string='功能刀具类型', + compute='_compute_tool_number', store=True) + tool_groups_id = fields.Many2one('sf.tool.groups', '刀具组', compute='_compute_tool_number', store=True) + diameter = fields.Integer(string='刀具直径(mm)', compute='_compute_tool_number', store=True) + tool_included_angle = fields.Float(string='刀尖R角(mm)', compute='_compute_tool_number', store=True) + tool_loading_length = fields.Float(string='总长度(mm)', compute='_compute_tool_number', store=True) extension_length = fields.Float(string='伸出长(mm)') effective_length = fields.Float(string='有效长(mm)') new_former = fields.Selection([('0', '新'), ('1', '旧')], string='新/旧', readonly=False, default='0') coarse_middle_thin = fields.Selection([("1", "粗"), ('2', '中'), ('3', '精')], default='3', string='粗/中/精', readonly=False) L_D = fields.Float(string='L/D值', readonly=False) - clearance_length = fields.Float(string='避空长(mm)', readonly=False) + clearance_length = fields.Float(string='避空长(mm)', compute='_compute_tool_number', store=True) required_cutting_time = fields.Integer(string='需切削时长', readonly=False) process_type = fields.Char('加工类型') margin_x_y = fields.Float('余量_X/Y') @@ -229,15 +232,24 @@ class CAMWorkOrderProgramKnifePlan(models.Model): active = fields.Boolean(string='已归档', default=True) - @api.depends('diameter', 'tool_included_angle', 'tool_groups_id') - def _compute_functional_tool_name(self): - for obj in self: - if obj.tool_groups_id: - obj.functional_tool_name = '%s-D%sR%s' % ( - obj.tool_groups_id.name, obj.diameter, - obj.tool_included_angle) + @api.depends('functional_tool_name') + def _compute_tool_number(self): + for item in self: + inventory = self.env['sf.tool.inventory'].sudo().search([('name', '=', item.functional_tool_name)]) + if inventory: + item.functional_tool_type_id = inventory.functional_cutting_tool_model_id.id + item.tool_groups_id = inventory.tool_groups_id.id + item.diameter = int(inventory.diameter) + item.tool_included_angle = inventory.angle + item.tool_loading_length = inventory.tool_length + item.clearance_length = inventory.blade_length else: - obj.functional_tool_name = None + item.functional_tool_type_id = False + item.tool_groups_id = False + item.diameter = 0 + item.tool_included_angle = 0 + item.tool_loading_length = 0 + item.clearance_length = 0 @api.model def _read_group_names(self, categories, domain, order): @@ -311,10 +323,9 @@ class CAMWorkOrderProgramKnifePlan(models.Model): 根据传入的工单信息,查询是否有需要的功能刀具,如果没有则生成CAM工单程序用刀计划 """ status = False - if cnc_processing.functional_tool_type_id and cnc_processing.cutting_tool_name: + if cnc_processing.cutting_tool_name: functional_tools = self.env['sf.real.time.distribution.of.functional.tools'].sudo().search( - [('sf_cutting_tool_type_id', '=', cnc_processing.functional_tool_type_id.id), - ('name', '=', cnc_processing.cutting_tool_name)]) + [('name', '=', cnc_processing.cutting_tool_name)]) if functional_tools: for functional_tool in functional_tools: if functional_tool.on_tool_stock_num == 0: @@ -327,7 +338,6 @@ class CAMWorkOrderProgramKnifePlan(models.Model): 'name': cnc_processing.workorder_id.production_id.name, 'cam_procedure_code': cnc_processing.program_name, 'filename': cnc_processing.cnc_id.name, - 'functional_tool_type_id': cnc_processing.functional_tool_type_id.id, 'functional_tool_name': cnc_processing.cutting_tool_name, 'cam_cutter_spacing_code': cnc_processing.cutting_tool_no, 'process_type': cnc_processing.processing_type, @@ -338,8 +348,11 @@ class CAMWorkOrderProgramKnifePlan(models.Model): 'shank_model': cnc_processing.cutting_tool_handle_type, 'estimated_processing_time': cnc_processing.estimated_processing_time, }) + logging.info('CAM工单程序用刀计划创建成功!!!') # 创建装刀请求 knife_plan.apply_for_tooling() + else: + logging.info('功能刀具【%s】满足CNC用刀需求!!!') class FunctionalToolAssembly(models.Model): diff --git a/sf_tool_management/models/mrp_workorder.py b/sf_tool_management/models/mrp_workorder.py index df9a341e..8098c5a1 100644 --- a/sf_tool_management/models/mrp_workorder.py +++ b/sf_tool_management/models/mrp_workorder.py @@ -36,6 +36,7 @@ class CNCprocessing(models.Model): obj = super(CNCprocessing, self).create(vals) # 调用CAM工单程序用刀计划创建方法 self.env['sf.cam.work.order.program.knife.plan'].create_cam_work_plan(obj) + logging.info('成功调用CAM工单程序用刀计划创建方法!!!') return obj diff --git a/sf_warehouse/models/model.py b/sf_warehouse/models/model.py index b4bec292..9ff18ebe 100644 --- a/sf_warehouse/models/model.py +++ b/sf_warehouse/models/model.py @@ -531,7 +531,7 @@ class Sf_stock_move_line(models.Model): current_product_id = fields.Integer(compute='_compute_location_dest_id_value', store=True) there_is_no_sn = fields.Boolean('是否有序列号', default=False) - rfid = fields.Char('Rfid', readonly=True) + rfid = fields.Char('Rfid') rfid_barcode = fields.Char('Rfid', compute='_compute_rfid') @api.depends('lot_id') From f26b4510cf86901712fdbcdac56826bb63436ce2 Mon Sep 17 00:00:00 2001 From: yuxianghui <3437689193@qq.com> Date: Thu, 18 Apr 2024 19:10:41 +0800 Subject: [PATCH 2/4] =?UTF-8?q?1=E3=80=81=E9=87=87=E8=B4=AD=E5=85=A5?= =?UTF-8?q?=E5=BA=93=E4=BD=9C=E4=B8=9A=E8=AF=A6=E6=83=85=E7=9A=84=E7=9B=AE?= =?UTF-8?q?=E6=A0=87=E4=BD=8D=E7=BD=AE=E5=AD=97=E6=AE=B5=E5=85=B3=E9=97=AD?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E5=8A=9F=E8=83=BD=EF=BC=8C=E5=85=B3=E9=97=AD?= =?UTF-8?q?=E8=B4=A7=E4=BD=8D=E7=9A=84=E5=88=9B=E5=BB=BA=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=EF=BC=9B2=E3=80=81=E4=BC=98=E5=8C=96=E5=85=A5=E5=BA=93?= =?UTF-8?q?=E5=88=B0=E8=B4=A7=E4=BD=8D=E6=B5=81=E7=A8=8B=EF=BC=88=E8=BF=9B?= =?UTF-8?q?=E8=A1=8C=E4=B8=AD=EF=BC=89=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../product_template_management_view.xml | 1 + sf_manufacturing/models/mrp_production.py | 2 +- sf_manufacturing/models/mrp_workorder.py | 2 +- sf_manufacturing/models/product_template.py | 3 ++ sf_sale/models/sale_order.py | 6 --- sf_warehouse/models/model.py | 49 ++++++++++++++----- .../views/change_stock_move_views.xml | 2 +- sf_warehouse/views/shelf_location.xml | 4 +- 8 files changed, 45 insertions(+), 24 deletions(-) diff --git a/sf_dlm_management/views/product_template_management_view.xml b/sf_dlm_management/views/product_template_management_view.xml index 453de6a3..94fc6b45 100644 --- a/sf_dlm_management/views/product_template_management_view.xml +++ b/sf_dlm_management/views/product_template_management_view.xml @@ -10,6 +10,7 @@ + diff --git a/sf_manufacturing/models/mrp_production.py b/sf_manufacturing/models/mrp_production.py index 24ac58b2..9deba53d 100644 --- a/sf_manufacturing/models/mrp_production.py +++ b/sf_manufacturing/models/mrp_production.py @@ -57,7 +57,7 @@ class MrpProduction(models.Model): production_line_state = fields.Selection([('待上产线', '待上产线'), ('已上产线', '已上产线'), ('已下产线', '已下产线')], string='上/下产线', default='待上产线') - manual_quotation = fields.Boolean('人工编程', default=False) + manual_quotation = fields.Boolean('人工编程', default=False, readonly=True) @api.depends( 'move_raw_ids.state', 'move_raw_ids.quantity_done', 'move_finished_ids.state', diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py index c9d72b79..a2da9d7c 100644 --- a/sf_manufacturing/models/mrp_workorder.py +++ b/sf_manufacturing/models/mrp_workorder.py @@ -46,7 +46,7 @@ class ResMrpWorkOrder(models.Model): ], string="工序类型") results = fields.Char('结果') - manual_quotation = fields.Boolean('人工编程', default=False) + manual_quotation = fields.Boolean('人工编程', default=False, readonly=True) @api.onchange('users_ids') def get_user_permissions(self): diff --git a/sf_manufacturing/models/product_template.py b/sf_manufacturing/models/product_template.py index 57ad0eaa..52f1fc9d 100644 --- a/sf_manufacturing/models/product_template.py +++ b/sf_manufacturing/models/product_template.py @@ -521,6 +521,9 @@ class ResProductMo(models.Model): string='注册状态', default='未注册') industry_code = fields.Char('行业编码', readonly=True) + # bfm下单 + manual_quotation = fields.Boolean('人工编程', default=False, readonly=True) + @api.constrains('tool_length') def _check_tool_length_size(self): if self.tool_length > 1000000: diff --git a/sf_sale/models/sale_order.py b/sf_sale/models/sale_order.py index 379ff199..05523194 100644 --- a/sf_sale/models/sale_order.py +++ b/sf_sale/models/sale_order.py @@ -142,12 +142,6 @@ class ResaleOrderLine(models.Model): check_status = fields.Selection(related='order_id.check_status') -class ProductTemplate(models.Model): - _inherit = 'product.template' - - manual_quotation = fields.Boolean('人工编程', default=False) - - class RePurchaseOrder(models.Model): _inherit = 'purchase.order' diff --git a/sf_warehouse/models/model.py b/sf_warehouse/models/model.py index 9ff18ebe..718a5877 100644 --- a/sf_warehouse/models/model.py +++ b/sf_warehouse/models/model.py @@ -191,6 +191,7 @@ class SfLocation(models.Model): # return res # 生成货位 + def create_location(self): """ 当仓库类型为货架时,自动生成其下面的货位,数量为货架层数*层数容量 @@ -429,7 +430,6 @@ class ShelfLocation(models.Model): } return action - # # 仓库类别(selection:库区、库位、货位) # location_type = fields.Selection([ # ('货架', '货架'), @@ -516,6 +516,19 @@ class ShelfLocation(models.Model): else: raise UserError("该库位无产品") + @api.model_create_multi + def create(self, vals_list): + # 编码重复校验 + barcode_list = [] + for val in vals_list: + location = self.search([('barcode', '=', val['barcode'])]) + if location: + barcode_list.append(val['name']) + if barcode_list: + raise UserError("货位编码【%s】存在重复" % barcode_list) + records = super(ShelfLocation, self).create(vals_list) + return records + class Sf_stock_move_line(models.Model): _name = 'stock.move.line' @@ -812,35 +825,42 @@ class Sf_stock_move_line(models.Model): destination_location_id = fields.Many2one( 'sf.shelf.location', string='目标货位') - @api.onchange('destination_location_id') - def _compute_destination_location_id(self): + def compute_destination_location_id(self): for record in self: + obj = self.env['sf.shelf.location'].search([('name', '=', + self.destination_location_id.name)]) + # if obj.product_id and obj.product_id != record.product_id: + # # 判断货位产品和将入到该货位的产品是否是同一种 + # raise ValidationError( + # '【%s】产品和【%s】货位的【%s】产品不同,请重新选择【%s】产品的货位!!!' % + # (record.product_id, obj.name, obj.product_id, record.product_id)) if record.lot_id: shelf_location_obj = self.env['sf.shelf.location'].search( [('product_sn_id', '=', record.lot_id.id)]) if shelf_location_obj: shelf_location_obj.product_sn_id = False - # obj = self.env['sf.shelf.location'].search([('location_id', '=', - # self.destination_location_id.id)]) - obj = self.env['sf.shelf.location'].search([('name', '=', - self.destination_location_id.name)]) if obj: obj.product_sn_id = record.lot_id.id - else: - pass else: - obj = self.env['sf.shelf.location'].search([('name', '=', - self.destination_location_id.name)]) if obj: obj.product_sn_id = record.lot_id.id else: - obj = self.env['sf.shelf.location'].search([('name', '=', - self.destination_location_id.name)]) if obj: obj.product_id = record.product_id.id # obj.location_status = '占用' obj.product_num += record.reserved_uom_qty + @api.onchange('destination_location_id') + def _check_destination_location_id(self): + for item in self: + if item: + line_destination_location_ids = [] + for obj in item.picking_id.move_line_ids: + if obj.destination_location_id: + line_destination_location_ids.append(obj.destination_location_id.barcode) + if item.destination_location_id.barcode in line_destination_location_ids: + raise ValidationError('【%s】货位已经被占用,请重新选择!!!' % item.destination_location_id.barcode) + class SfStockPicking(models.Model): _inherit = 'stock.picking' @@ -863,12 +883,15 @@ class SfStockPicking(models.Model): res = super(SfStockPicking, self).button_validate() for line in self.move_line_ids: if line: + # 调用入库方法进行入库 + line.compute_destination_location_id() if line.current_location_id: if line.current_location_id.product_sn_id: line.current_location_id.product_sn_id = False # line.current_location_id.location_status = '空闲' line.current_location_id.product_num = 0 + # 对入库作业的刀柄和托盘进行Rfid绑定校验 for move in self.move_ids: if move and move.product_id.cutting_tool_material_id.name == '刀柄' or '托盘' in ( move.product_id.fixture_material_id.name or ''): diff --git a/sf_warehouse/views/change_stock_move_views.xml b/sf_warehouse/views/change_stock_move_views.xml index 7af154b7..519eca85 100644 --- a/sf_warehouse/views/change_stock_move_views.xml +++ b/sf_warehouse/views/change_stock_move_views.xml @@ -19,7 +19,7 @@ + '=', there_is_no_sn)]" options="{'no_create': True,'no_create_edit':True}"/> diff --git a/sf_warehouse/views/shelf_location.xml b/sf_warehouse/views/shelf_location.xml index d736f89c..ff8f54b2 100644 --- a/sf_warehouse/views/shelf_location.xml +++ b/sf_warehouse/views/shelf_location.xml @@ -126,7 +126,7 @@ Shelf Location form sf.shelf.location -
+
@@ -175,7 +175,7 @@ shelf.location.kanban sf.shelf.location - +
- +
- - - - - + + + + + diff --git a/sf_warehouse/wizard/__init__.py b/sf_warehouse/wizard/__init__.py new file mode 100644 index 00000000..20a7f5c4 --- /dev/null +++ b/sf_warehouse/wizard/__init__.py @@ -0,0 +1 @@ +from . import wizard \ No newline at end of file diff --git a/sf_warehouse/wizard/wizard.py b/sf_warehouse/wizard/wizard.py new file mode 100644 index 00000000..7961819b --- /dev/null +++ b/sf_warehouse/wizard/wizard.py @@ -0,0 +1,64 @@ +from odoo import fields, models, api +from odoo.exceptions import UserError, ValidationError + + +class ShelfLocationWizard(models.TransientModel): + _name = 'sf.shelf.location.wizard' + _description = '货位变更' + + name = fields.Char('') + + current_location_id = fields.Many2one('stock.location', string='所属库区', readonly=True) + + current_shelf_id = fields.Many2one('sf.shelf', string='当前货架', readonly=True) + current_barcode = fields.Char('当前货位编码', readonly=True) + current_name = fields.Char('当前货位名称', readonly=True) + current_product_id = fields.Many2one('product.product', string='产品', readonly=True) + + destination_shelf_id = fields.Many2one('sf.shelf', string='目标货架', compute='_compute_destination_name') + destination_barcode_id = fields.Many2one('sf.shelf.location', string='目标货位编码', required=True, + domain="") + destination_name = fields.Char('目标货位名称', compute='_compute_destination_name') + + def return_domain(self): + val = [('location_status', '=', '空闲')] + if self.current_product_id: + val = ['|', ('location_status', '=', '空闲'), ('product_id', '=', self.current_product_id)] + if self.destination_shelf_id: + val.append(('shelf_id', '=', self.destination_shelf_id)) + return "%s" % val + + @api.depends('destination_barcode_id') + def _compute_destination_name(self): + if self.destination_barcode_id: + self.destination_name = self.destination_barcode_id.name + self.destination_shelf_id = self.destination_barcode_id.shelf_id.id + else: + self.destination_name = '' + self.destination_shelf_id = False + + # + # @api.onchange('destination_barcode_id') + # def _onchange_destination_shelf_id(self): + # if self.destination_barcode_id: + # self.destination_shelf_id = self.destination_barcode_id.shelf_id.id + + def confirm_the_change(self): + shelf_location = self.env['sf.shelf.location'].sudo().search([('barcode', '=', self.current_barcode)]) + # 变更货位 + if self.destination_barcode_id and shelf_location: + if self.destination_barcode_id.product_id and self.destination_barcode_id.product_id == shelf_location.current_product_id and not self.destination_barcode_id.product_sn_id: + self.destination_barcode_id.product_num += shelf_location.product_num + else: + self.destination_barcode_id.product_sn_id = shelf_location.product_sn_id.id + self.destination_barcode_id.product_id = shelf_location.product_id.id + self.destination_barcode_id.product_num = shelf_location.product_num + + shelf_location.product_sn_id = False + shelf_location.product_id = False + shelf_location.product_num = 0 + else: + raise ValidationError('目标货位出错,请联系管理员!') + + # 关闭弹出窗口 + return {'type': 'ir.actions.act_window_close'} diff --git a/sf_warehouse/wizard/wizard_view.xml b/sf_warehouse/wizard/wizard_view.xml new file mode 100644 index 00000000..1bb95e15 --- /dev/null +++ b/sf_warehouse/wizard/wizard_view.xml @@ -0,0 +1,49 @@ + + + + 货位变更 + sf.shelf.location.wizard + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+
+ + + 货位变更 + ir.actions.act_window + sf.shelf.location.wizard + form + + new + +
\ No newline at end of file