完善库存模块新增功能及编码规则,已实现据货架分别展示下属货位的看板,待优化
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
|
@@ -1,5 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<data>
|
||||
<record id="view_location_tree2_sf_inherit" model="ir.ui.view">
|
||||
<field name="name">stock.location.tree.sf.inherit</field>
|
||||
<field name="model">stock.location</field>
|
||||
<field name="inherit_id" ref="stock.view_location_tree2"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//tree/field[@name='complete_name']" position="before">
|
||||
<field name="barcode"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_location_form_sf_inherit" model="ir.ui.view">
|
||||
<field name="name">stock.location.form.sf.inherit</field>
|
||||
<field name="model">stock.location</field>
|
||||
@@ -17,7 +29,7 @@
|
||||
<field name="location_type"/>
|
||||
<field name="channel" attrs="{'invisible': [('hide_shelf', '=', False)], 'required': [('hide_shelf', '!=', False)]}"/>
|
||||
<field name="direction" attrs="{'invisible': [('hide_shelf', '=', False)], 'required': [('hide_shelf', '!=', False)]}"/>
|
||||
<field name="location_status" attrs="{'invisible': [('hide_location', '=', False)], 'required': [('hide_location', '!=', False)]}"/>
|
||||
<field name="product_sn_id" attrs="{'invisible': [('hide_location', '=', False)], 'required': [('hide_location', '!=', False)]}"/>
|
||||
|
||||
</group>
|
||||
<group>
|
||||
@@ -26,13 +38,87 @@
|
||||
<field name="shelf_height" attrs="{'invisible': [('hide_shelf', '=', False)], 'required': [('hide_shelf', '!=', False)]}"/>
|
||||
<field name="shelf_layer" attrs="{'invisible': [('hide_shelf', '=', False)], 'required': [('hide_shelf', '!=', False)]}"/>
|
||||
<field name="layer_capacity" attrs="{'invisible': [('hide_shelf', '=', False)], 'required': [('hide_shelf', '!=', False)]}"/>
|
||||
<field name="product_id"/>
|
||||
<!-- <field name="product_sn_id"/> -->
|
||||
<field name="product_id" attrs="{'invisible': [('hide_location', '=', False)], 'required': [('hide_location', '!=', False)]}"/>
|
||||
<field name="location_status" attrs="{'invisible': [('hide_location', '=', False)], 'required': [('hide_location', '!=', False)]}"/>
|
||||
|
||||
</group>
|
||||
|
||||
</group>
|
||||
</xpath>
|
||||
<!-- <xpath expr="//form/sheet/div/button" position="before"> -->
|
||||
<!-- <button string="生成货位" name="create_location" type="object" class="oe_highlight" attrs="{'invisible': [('hide_shelf', '=', False)]}"/> -->
|
||||
<!-- </xpath> -->
|
||||
<xpath expr="//form/sheet" position="before">
|
||||
<header>
|
||||
<button string="生成货位" name="create_location" type="object" class="oe_highlight" attrs="{'invisible': [('hide_shelf', '=', False)]}"/>
|
||||
</header>
|
||||
</xpath>
|
||||
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_location_search_sf_inherit" model="ir.ui.view">
|
||||
<field name="name">stock.location.search.sf.inherit</field>
|
||||
<field name="model">stock.location</field>
|
||||
<field name="inherit_id" ref="stock.view_location_search"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//search[1]" position="inside">
|
||||
<searchpanel class="account_root">
|
||||
<!-- <field name="location_type" icon="fa-filter"/> -->
|
||||
<field name="location_id" select="multi" domain="[('location_type', '=', '货架')]"/>
|
||||
</searchpanel>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
<record id="example_kanban_view" model="ir.ui.view">
|
||||
<field name="name">example.kanban</field>
|
||||
<field name="model">stock.location</field>
|
||||
<field name="arch" type="xml">
|
||||
<kanban class="o_kanban_mobile">
|
||||
<templates>
|
||||
<t t-name="kanban-box">
|
||||
<div t-attf-class="oe_kanban_card">
|
||||
<!-- 标题 -->
|
||||
<div class="o_kanban_card_header">
|
||||
<div class="o_kanban_card_header_title">
|
||||
<field name="name"/>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 内容 -->
|
||||
<div class="o_kanban_record_bottom">
|
||||
<field name="location_status"/>
|
||||
</div>
|
||||
</div>
|
||||
</t>
|
||||
</templates>
|
||||
</kanban>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="kanban_action_id" model="ir.actions.act_window">
|
||||
<field name="name">货位状态</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">stock.location</field>
|
||||
<field name="view_mode">kanban,form</field>
|
||||
</record>
|
||||
|
||||
<!-- <record id="example_action" model="ir.actions.act_window"> -->
|
||||
<!-- <field name="name">Example</field> -->
|
||||
<!-- <field name="type">ir.actions.act_window</field> -->
|
||||
<!-- <field name="res_model">stock.location</field> -->
|
||||
<!-- <field name="view_mode">kanban</field> -->
|
||||
<!-- <field name="searchpanel">true</field> -->
|
||||
<!-- <field name="searchpanel_field_label">货架</field> -->
|
||||
<!-- <field name="searchpanel_field_name">parent_id</field> -->
|
||||
<!-- <field name="searchpanel_field_group_by">['parent_id']</field> -->
|
||||
<!-- <field name="domain">[('location_type', '=', '货位')]</field> -->
|
||||
<!-- </record> -->
|
||||
|
||||
|
||||
<menuitem id="menu_stock_location" name="货位状态" parent="stock.menu_stock_root"
|
||||
sequence="50"
|
||||
action="kanban_action_id"/>
|
||||
|
||||
|
||||
</data>
|
||||
</odoo>
|
||||
|
||||
Reference in New Issue
Block a user