From 0d7c269c3bb7c4e2ea9c849d5943f8cac67155cd Mon Sep 17 00:00:00 2001 From: mgw <1392924357@qq.com> Date: Tue, 4 Jul 2023 20:05:59 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E7=BB=A7=E6=89=BF=E5=8E=9F=E7=94=9F?= =?UTF-8?q?=E5=BA=93=E5=AD=98=E6=A8=A1=E5=9D=97=EF=BC=8C=E4=B8=BA=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE=E6=A8=A1=E5=9E=8B=E5=A2=9E=E5=8A=A0=E5=BA=93=E5=8C=BA?= =?UTF-8?q?=E5=BA=93=E4=BD=8D=E7=AD=89=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_warehouse/__init__.py | 3 + sf_warehouse/__manifest__.py | 35 +++++++ sf_warehouse/models/__init__.py | 2 + sf_warehouse/models/model.py | 113 ++++++++++++++++++++++ sf_warehouse/security/ir.model.access.csv | 19 ++++ sf_warehouse/static/src/change.scss | 11 +++ sf_warehouse/views/view.xml | 38 ++++++++ 7 files changed, 221 insertions(+) create mode 100644 sf_warehouse/__init__.py create mode 100644 sf_warehouse/__manifest__.py create mode 100644 sf_warehouse/models/__init__.py create mode 100644 sf_warehouse/models/model.py create mode 100644 sf_warehouse/security/ir.model.access.csv create mode 100644 sf_warehouse/static/src/change.scss create mode 100644 sf_warehouse/views/view.xml diff --git a/sf_warehouse/__init__.py b/sf_warehouse/__init__.py new file mode 100644 index 00000000..815c355c --- /dev/null +++ b/sf_warehouse/__init__.py @@ -0,0 +1,3 @@ +# -*-coding:utf-8-*- +from . import models + diff --git a/sf_warehouse/__manifest__.py b/sf_warehouse/__manifest__.py new file mode 100644 index 00000000..6ad297c8 --- /dev/null +++ b/sf_warehouse/__manifest__.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. +{ + 'name': '机企猫智能工厂 库存管理', + 'version': '1.0', + 'summary': '智能工厂库存管理', + 'sequence': 1, + 'description': """ +在本模块,升级了odoo原生的库存模块 + """, + 'category': 'sf', + 'website': 'https://www.sf.jikimo.com', + 'depends': ['stock', ], + 'data': [ + #'security/group_security.xml', + # 'security/ir.model.access.csv', + 'views/view.xml', + ], + 'demo': [ + ], + 'assets': { + + 'web.assets_qweb': [ + ], + 'web.assets_backend':[ + # 'sf_tool_management/static/src/change.scss' + ] + + + }, + 'license': 'LGPL-3', + 'installable': True, + 'application': False, + 'auto_install': False, +} diff --git a/sf_warehouse/models/__init__.py b/sf_warehouse/models/__init__.py new file mode 100644 index 00000000..833a0ba1 --- /dev/null +++ b/sf_warehouse/models/__init__.py @@ -0,0 +1,2 @@ +from . import model + diff --git a/sf_warehouse/models/model.py b/sf_warehouse/models/model.py new file mode 100644 index 00000000..1cfc3cde --- /dev/null +++ b/sf_warehouse/models/model.py @@ -0,0 +1,113 @@ +# -*- coding: utf-8 -*- +from odoo import fields, models, api +from odoo.exceptions import ValidationError + + +class SfLocation(models.Model): + _inherit = 'stock.location' + + # 重写字段定义 + name = fields.Char('Location Name', required=True, size=20) + barcode = fields.Char('Barcode', copy=False, required=True, size=15) + + # 仓库类别(selection:仓库、库区、库位、货位) + location_type = fields.Selection([ + ('仓库', '仓库'), + ('库区', '库区'), + ('库位', '库位'), + ('货位', '货位') + ], string='仓库类别') + # 仓库类型(分类:成品库、坯料库、原材料库、刀具库、线边料库、线边刀库) + location_category = fields.Selection([ + ('成品库', '成品库'), + ('坯料库', '坯料库'), + ('原材料库', '原材料库'), + ('刀具库', '刀具库'), + ('线边料库', '线边料库'), + ('线边刀库', '线边刀库') + ], string='仓库类型') + # 库区类型(selection:拣货区、存货区、收货区、退货区、次品区) + area_type = fields.Selection([ + ('拣货区', '拣货区'), + ('存货区', '存货区'), + ('收货区', '收货区'), + ('退货区', '退货区'), + ('次品区', '次品区') + ], string='库区类型') + # 货架独有字段:通道、方向、货架高度(m)、货架层数、层数容量 + channel = fields.Char(string='通道') + direction = fields.Selection([ + ('R', 'R'), + ('L', 'L') + ], string='方向') + shelf_height = fields.Float(string='货架高度(m)') + shelf_layer = fields.Integer(string='货架层数') + layer_capacity = fields.Integer(string='层数容量') + + # 货位独有字段:货位状态、产品(关联产品对象)、产品序列号(关联产品序列号对象) + location_status = fields.Selection([ + ('空闲', '空闲'), + ('占用', '占用'), + ('禁用', '禁用') + ], string='货位状态', default='空闲') + product_id = fields.Many2one('product.template', string='产品') + # product_sn_id = fields.Many2one('product.serial.number', string='产品序列号') + + # 添加SQL约束 + _sql_constraints = [ + ('name_uniq', 'unique(name)', '位置名称必须唯一!'), + ] + + hide_location_type = fields.Boolean(compute='_compute_hide_what', string='隐藏仓库') + hide_area = fields.Boolean(compute='_compute_hide_what', string='隐藏库区') + hide_shelf = fields.Boolean(compute='_compute_hide_what', string='隐藏货架') + hide_location = fields.Boolean(compute='_compute_hide_what', string='隐藏货位') + + @api.depends('location_type') + def _compute_hide_what(self): + """ + 根据仓库类别,隐藏不需要的字段 + :return: + """ + for record in self: + record.hide_location_type = False + record.hide_area = False + record.hide_shelf = False + record.hide_location = False + if record.location_type and record.location_type == '仓库': + record.hide_location_type = True + elif record.location_type and record.location_type == '库区': + record.hide_area = True + elif record.location_type and record.location_type == '库位': + record.hide_shelf = True + elif record.location_type and record.location_type == '货位': + record.hide_location = True + else: + pass + + # # 添加Python约束 + # @api.constrains('name', 'barcode') + # def _check_len(self): + # for rec in self: + # if len(rec.name) > 20: + # raise ValidationError("Location Name length must be less equal than 20!") + # if len(rec.barcode) > 15: + # raise ValidationError("Barcode length must be less equal than 15!") + + @api.model + def default_get(self, fields): + res = super(SfLocation, self).default_get(fields) + if 'barcode' in fields and 'barcode' not in res: + # 这里是你生成barcode的代码 + res['barcode'] = self.generate_barcode() # 假设你有一个方法generate_barcode来生成barcode + return res + + def generate_barcode(self): + # 这里是你生成barcode的代码 + # 这只是一个示例,你需要根据你的实际需求来编写这个方法 + last_location = self.search([], order='id desc', limit=1) + if last_location: + last_barcode = int(last_location.barcode or 0) + return str(last_barcode + 1).zfill(8) + else: + return '00000001' diff --git a/sf_warehouse/security/ir.model.access.csv b/sf_warehouse/security/ir.model.access.csv new file mode 100644 index 00000000..6cb8bc16 --- /dev/null +++ b/sf_warehouse/security/ir.model.access.csv @@ -0,0 +1,19 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_sf_functional_cutting_tool_entity,sf.functional.cutting.tool.entity,model_sf_functional_cutting_tool_entity,base.group_user,1,1,1,1 +access_sf_cam_work_order_program_knife_plan,sf.cam.work.order.program.knife.plan,model_sf_cam_work_order_program_knife_plan,base.group_user,1,1,1,1 +access_sf_machine_table_tool_changing_apply,sf.machine.table.tool.changing.apply,model_sf_machine_table_tool_changing_apply,base.group_user,1,1,1,1 + + +access_sf_tool_change_requirement_information,sf.tool.change.requirement.information,model_sf_tool_change_requirement_information,base.group_user,1,1,1,1 +access_sf_tool_transfer_request_information,sf.tool.transfer.request.information,model_sf_tool_transfer_request_information,base.group_user,1,1,1,1 +access_sf_apply_for_tooling,sf.apply.for.tooling,model_sf_apply_for_tooling,base.group_user,1,1,1,1 + +access_sf_functional_tool_assembly,sf.functional.tool.assembly,model_sf_functional_tool_assembly,base.group_user,1,1,1,1 +access_sf_functional_tool_assembly_order,sf.functional.tool.assembly.order,model_sf_functional_tool_assembly_order,base.group_user,1,1,1,1 +access_sf_delivery_of_cargo_from_storage,sf.delivery.of.cargo.from.storage,model_sf_delivery_of_cargo_from_storage,base.group_user,1,1,1,1 +access_sf_tool_material_search,sf.tool.material.search,model_sf_tool_material_search,base.group_user,1,1,1,1 + + + + + diff --git a/sf_warehouse/static/src/change.scss b/sf_warehouse/static/src/change.scss new file mode 100644 index 00000000..40fdcc8e --- /dev/null +++ b/sf_warehouse/static/src/change.scss @@ -0,0 +1,11 @@ +.modal-content .o_cp_buttons { + display:none +} + +.modal-content .o_control_panel { + display:none +} + +.modal-content .o_list_button { + +} \ No newline at end of file diff --git a/sf_warehouse/views/view.xml b/sf_warehouse/views/view.xml new file mode 100644 index 00000000..cefa513e --- /dev/null +++ b/sf_warehouse/views/view.xml @@ -0,0 +1,38 @@ + + + + stock.location.form.sf.inherit + stock.location + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From b754534b5bde6287d84485c884df0934eff5379c Mon Sep 17 00:00:00 2001 From: mgw <1392924357@qq.com> Date: Wed, 5 Jul 2023 23:02:22 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=BA=93=E5=AD=98?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E6=96=B0=E5=A2=9E=E5=8A=9F=E8=83=BD=E5=8F=8A?= =?UTF-8?q?=E7=BC=96=E7=A0=81=E8=A7=84=E5=88=99=EF=BC=8C=E5=B7=B2=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E6=8D=AE=E8=B4=A7=E6=9E=B6=E5=88=86=E5=88=AB=E5=B1=95?= =?UTF-8?q?=E7=A4=BA=E4=B8=8B=E5=B1=9E=E8=B4=A7=E4=BD=8D=E7=9A=84=E7=9C=8B?= =?UTF-8?q?=E6=9D=BF=EF=BC=8C=E5=BE=85=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_warehouse/models/model.py | 113 +++++++++++++++++----- sf_warehouse/security/ir.model.access.csv | 17 +--- sf_warehouse/views/view.xml | 92 +++++++++++++++++- 3 files changed, 179 insertions(+), 43 deletions(-) diff --git a/sf_warehouse/models/model.py b/sf_warehouse/models/model.py index 1cfc3cde..cdbaded9 100644 --- a/sf_warehouse/models/model.py +++ b/sf_warehouse/models/model.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- from odoo import fields, models, api -from odoo.exceptions import ValidationError +from odoo.exceptions import ValidationError, UserError class SfLocation(models.Model): @@ -14,7 +14,7 @@ class SfLocation(models.Model): location_type = fields.Selection([ ('仓库', '仓库'), ('库区', '库区'), - ('库位', '库位'), + ('货架', '货架'), ('货位', '货位') ], string='仓库类别') # 仓库类型(分类:成品库、坯料库、原材料库、刀具库、线边料库、线边刀库) @@ -35,14 +35,14 @@ class SfLocation(models.Model): ('次品区', '次品区') ], string='库区类型') # 货架独有字段:通道、方向、货架高度(m)、货架层数、层数容量 - channel = fields.Char(string='通道') + channel = fields.Char(string='通道', required=True) direction = fields.Selection([ ('R', 'R'), ('L', 'L') - ], string='方向') + ], string='方向', required=True) shelf_height = fields.Float(string='货架高度(m)') - shelf_layer = fields.Integer(string='货架层数') - layer_capacity = fields.Integer(string='层数容量') + shelf_layer = fields.Integer(string='货架层数', required=True) + layer_capacity = fields.Integer(string='层数容量', required=True) # 货位独有字段:货位状态、产品(关联产品对象)、产品序列号(关联产品序列号对象) location_status = fields.Selection([ @@ -50,8 +50,9 @@ class SfLocation(models.Model): ('占用', '占用'), ('禁用', '禁用') ], string='货位状态', default='空闲') - product_id = fields.Many2one('product.template', string='产品') - # product_sn_id = fields.Many2one('product.serial.number', string='产品序列号') + # product_id = fields.Many2one('product.template', string='产品') + product_id = fields.Many2one('product.product', string='产品', compute='_compute_product_id', readonly=True) + product_sn_id = fields.Many2one('stock.lot', string='产品序列号') # 添加SQL约束 _sql_constraints = [ @@ -63,6 +64,34 @@ class SfLocation(models.Model): hide_shelf = fields.Boolean(compute='_compute_hide_what', string='隐藏货架') hide_location = fields.Boolean(compute='_compute_hide_what', string='隐藏货位') + # @api.constrains('shelf_height') + # def _check_shelf_height(self): + # for record in self: + # if not (0 <= record.shelf_height < 1000): # 限制字段值在0到999之间 + # raise UserError('shelf_height的值必须在0到1000之间') + # + # @api.constrains('shelf_layer') + # def _check_shelf_layer(self): + # for record in self: + # if not (0 < record.shelf_layer < 1000): + # raise UserError('shelf_layer的值必须在0到999之间,且不能为0') + # + # @api.constrains('layer_capacity') + # def _check_layer_capacity(self): + # for record in self: + # if not (0 <= record.layer_capacity < 1000): + # raise UserError('layer_capacity的值必须在0到999之间,且不能为0') + + @api.depends('product_sn_id') + def _compute_product_id(self): + for record in self: + if record.product_sn_id: + record.product_id = record.product_sn_id.product_id + record.location_status = '占用' + else: + record.product_id = False + record.location_status = '空闲' + @api.depends('location_type') def _compute_hide_what(self): """ @@ -78,7 +107,7 @@ class SfLocation(models.Model): record.hide_location_type = True elif record.location_type and record.location_type == '库区': record.hide_area = True - elif record.location_type and record.location_type == '库位': + elif record.location_type and record.location_type == '货架': record.hide_shelf = True elif record.location_type and record.location_type == '货位': record.hide_location = True @@ -94,20 +123,56 @@ class SfLocation(models.Model): # if len(rec.barcode) > 15: # raise ValidationError("Barcode length must be less equal than 15!") - @api.model - def default_get(self, fields): - res = super(SfLocation, self).default_get(fields) - if 'barcode' in fields and 'barcode' not in res: - # 这里是你生成barcode的代码 - res['barcode'] = self.generate_barcode() # 假设你有一个方法generate_barcode来生成barcode - return res + # @api.model + # def default_get(self, fields): + # print('fields:', fields) + # res = super(SfLocation, self).default_get(fields) + # print('res:', res) + # if 'barcode' in fields and 'barcode' not in res: + # # 这里是你生成barcode的代码 + # pass + # # res['barcode'] = self.generate_barcode() # 假设你有一个方法generate_barcode来生成barcode + # return res + # @api.model + # def create(self, vals): + # """ + # 重写create方法,当仓库类型为货架时,自动生成其下面的货位,数量为货架层数*层数容量 + # """ + # res = super(SfLocation, self).create(vals) + # if res.location_type == '货架': + # for i in range(res.shelf_layer): + # for j in range(res.layer_capacity): + # self.create({ + # 'name': res.name + '-' + str(i+1) + '-' + str(j+1), + # 'location_id': res.id, + # 'location_type': '货位', + # 'barcode': self.generate_barcode(res, i, j), + # 'location_status': '空闲' + # }) + # return res - def generate_barcode(self): + # 生成货位 + def create_location(self): + if self.location_type == '货架': + for i in range(self.shelf_layer): + for j in range(self.layer_capacity): + self.create({ + 'name': self.name + '-' + str(i + 1) + '层' + '-' + str(j + 1) + '位置', + 'location_id': self.id, + 'location_type': '货位', + 'barcode': self.generate_barcode(i, j), + 'location_status': '空闲' + }) + + def generate_barcode(self, i, j): # 这里是你生成barcode的代码 - # 这只是一个示例,你需要根据你的实际需求来编写这个方法 - last_location = self.search([], order='id desc', limit=1) - if last_location: - last_barcode = int(last_location.barcode or 0) - return str(last_barcode + 1).zfill(8) - else: - return '00000001' + area_type_barcode = self.location_id.barcode + i_str = str(i + 1).zfill(3) # 确保是两位数,如果不足两位,左侧补0 + j_str = str(j + 1).zfill(3) # 确保是两位数,如果不足两位,左侧补0 + return area_type_barcode + self.channel + self.direction + '-' + self.barcode + '-' + i_str + '-' + j_str + + + # def generate_barcode(self, i, j): + # # 这里是你生成barcode的代码 + # area_type_barcode = self.location_id.barcode + # return area_type_barcode + self.channel + self.direction + '-' + self.barcode + '-' + str(i + 1) + '-' + str(j + 1) diff --git a/sf_warehouse/security/ir.model.access.csv b/sf_warehouse/security/ir.model.access.csv index 6cb8bc16..94ce7d2b 100644 --- a/sf_warehouse/security/ir.model.access.csv +++ b/sf_warehouse/security/ir.model.access.csv @@ -1,19 +1,4 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink -access_sf_functional_cutting_tool_entity,sf.functional.cutting.tool.entity,model_sf_functional_cutting_tool_entity,base.group_user,1,1,1,1 -access_sf_cam_work_order_program_knife_plan,sf.cam.work.order.program.knife.plan,model_sf_cam_work_order_program_knife_plan,base.group_user,1,1,1,1 -access_sf_machine_table_tool_changing_apply,sf.machine.table.tool.changing.apply,model_sf_machine_table_tool_changing_apply,base.group_user,1,1,1,1 - - -access_sf_tool_change_requirement_information,sf.tool.change.requirement.information,model_sf_tool_change_requirement_information,base.group_user,1,1,1,1 -access_sf_tool_transfer_request_information,sf.tool.transfer.request.information,model_sf_tool_transfer_request_information,base.group_user,1,1,1,1 -access_sf_apply_for_tooling,sf.apply.for.tooling,model_sf_apply_for_tooling,base.group_user,1,1,1,1 - -access_sf_functional_tool_assembly,sf.functional.tool.assembly,model_sf_functional_tool_assembly,base.group_user,1,1,1,1 -access_sf_functional_tool_assembly_order,sf.functional.tool.assembly.order,model_sf_functional_tool_assembly_order,base.group_user,1,1,1,1 -access_sf_delivery_of_cargo_from_storage,sf.delivery.of.cargo.from.storage,model_sf_delivery_of_cargo_from_storage,base.group_user,1,1,1,1 -access_sf_tool_material_search,sf.tool.material.search,model_sf_tool_material_search,base.group_user,1,1,1,1 - - - +access_stock_location,stock.location,model_stock_location,base.group_user,1,1,1,1 diff --git a/sf_warehouse/views/view.xml b/sf_warehouse/views/view.xml index cefa513e..2d674285 100644 --- a/sf_warehouse/views/view.xml +++ b/sf_warehouse/views/view.xml @@ -1,5 +1,17 @@ + + + stock.location.tree.sf.inherit + stock.location + + + + + + + + stock.location.form.sf.inherit stock.location @@ -17,7 +29,7 @@ - + @@ -26,13 +38,87 @@ - - + + + + + + +
+
+
+
+ + + stock.location.search.sf.inherit + stock.location + + + + + + + + + example.kanban + stock.location + + + + +
+ +
+
+ +
+
+ +
+ +
+
+
+
+
+
+
+ + + 货位状态 + ir.actions.act_window + stock.location + kanban,form + + + + + + + + + + + + + + + + + + +
From 3a653a9485958d2117ba9ae71463b660b317417a Mon Sep 17 00:00:00 2001 From: mgw <1392924357@qq.com> Date: Thu, 6 Jul 2023 09:38:57 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=B4=A7=E4=BD=8D?= =?UTF-8?q?=E7=9C=8B=E6=9D=BF=E6=98=BE=E7=A4=BA=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_warehouse/views/view.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sf_warehouse/views/view.xml b/sf_warehouse/views/view.xml index 2d674285..e2b4a3b1 100644 --- a/sf_warehouse/views/view.xml +++ b/sf_warehouse/views/view.xml @@ -88,6 +88,11 @@
+
+ + | + +