库存货架货位修改基本完成,推送测试

This commit is contained in:
mgw
2023-11-28 16:42:19 +08:00
parent 4d8b463cb3
commit 2c1a101c24
5 changed files with 279 additions and 137 deletions

View File

@@ -16,6 +16,7 @@
'security/ir.model.access.csv',
'views/view.xml',
'views/shelf_location.xml',
'views/change_stock_move_views.xml',
],
'demo': [
],

View File

@@ -185,33 +185,29 @@ class SfLocation(models.Model):
"""
当仓库类型为货架时,自动生成其下面的货位,数量为货架层数*层数容量
"""
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': '空闲'
})
pass
# 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的代码
# area_type_barcode = self.location_id.barcode
area_type_barcode = self.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)
pass
# # 这里是你生成barcode的代码
# # area_type_barcode = self.location_id.barcode
# area_type_barcode = self.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
class ShelfLocation(models.Model):
@@ -227,9 +223,12 @@ class ShelfLocation(models.Model):
('货位', '货位')
], string='存储类型')
# 绑定库区
shelf_location_id = fields.Many2one('stock.location', string='所属库区', domain=[('location_type', '=', '库区')])
location_id = fields.Many2one('stock.location', string='所属库区', domain=[('location_type', '=', '库区')])
# 产品类别 关联product.category
product_type = fields.Many2many('product.category', string='产品类别')
# product_type = fields.Many2many('product.category', string='产品类别')
# picking_product_type = fields.Many2many('stock.picking', string='调拨产品类别', related='location_dest_id.product_type')
# 货架独有字段通道、方向、货架高度m、货架层数、层数容量
channel = fields.Char(string='通道')
direction = fields.Selection([
@@ -253,6 +252,16 @@ class ShelfLocation(models.Model):
hide_shelf = fields.Boolean(compute='_compute_hide_what', string='隐藏货架')
hide_location = fields.Boolean(compute='_compute_hide_what', string='隐藏货位')
@api.onchange('shelf_location_id')
def _onchange_shelf_location_id(self):
"""
根据货架的所属库区修改货位的所属库区
"""
all_location = self.env['sf.shelf.location'].search([('name', 'ilike', self.name)])
for record in self:
for location in all_location:
location.location_id = record.shelf_location_id.id
@api.depends('product_sn_id')
def _compute_product_id(self):
"""
@@ -264,7 +273,7 @@ class ShelfLocation(models.Model):
record.location_status = '占用'
else:
record.product_id = False
# record.location_status = '空闲'
record.location_status = '空闲'
@api.depends('location_type')
def _compute_hide_what(self):
@@ -292,10 +301,10 @@ class ShelfLocation(models.Model):
for j in range(self.layer_capacity):
self.create({
'name': self.name + '-' + str(i + 1) + '' + '-' + str(j + 1) + '位置',
'location_id': self.id,
'location_id': self.shelf_location_id.id,
'location_type': '货位',
'barcode': self.generate_barcode(i, j),
'location_status': '空闲'
'location_status': '空闲',
})
def generate_barcode(self, i, j):
@@ -309,11 +318,125 @@ class ShelfLocation(models.Model):
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)
class Sf_stock_move_line(models.Model):
_inherit = 'stock.move.line'
current_location_id = fields.Many2one(
'sf.shelf.location', string='当前货位', compute='_compute_current_location_id', store=True)
# location_dest_id = fields.Many2one('stock.location', string='目标库位')
location_dest_id_product_type = fields.Many2many(related='location_dest_id.product_type')
location_dest_id_value = fields.Integer(compute='_compute_location_dest_id_value', store=True)
# def button_test(self):
# print(self.picking_id.name)
# stock_picking = self.env['stock.picking'].search([('name', '=', self.picking_id.name)], limit=1)
# print(self.picking_id.name)
# print(aa.move_line_ids.lot_id.name)
# # 获取当前的stock.picking对象
# current_picking = self.env['stock.picking'].search([('name', '=', self.picking_id.name)], limit=1)
#
# # 获取当前picking的第一个stock.move对象
# current_move = current_picking.move_ids[0] if current_picking.move_ids else False
#
# # 如果存在相关的stock.move对象
# if current_move:
# # 获取源stock.move对象
# origin_move = current_move.move_orig_ids[0] if current_move.move_orig_ids else False
#
# # 从源stock.move对象获取源stock.picking对象
# origin_picking = origin_move.picking_id if origin_move else False
# # 现在origin_picking就是current_picking的上一步
# # 获取目标stock.move对象
# dest_move = current_move.move_dest_ids[0] if current_move.move_dest_ids else False
#
# # 从目标stock.move对象获取目标stock.picking对象
# dest_picking = dest_move.picking_id if dest_move else False
# # 现在dest_picking就是current_picking的下一步
@api.depends('location_id')
def _compute_current_location_id(self):
# for record in self:
# 获取当前的stock.picking对象
current_picking = self.env['stock.picking'].search([('name', '=', self.picking_id.name)], limit=1)
# 获取当前picking的第一个stock.move对象
current_move = current_picking.move_ids[0] if current_picking.move_ids else False
# 如果存在相关的stock.move对象
if current_move:
# 获取源stock.move对象
origin_move = current_move.move_orig_ids[0] if current_move.move_orig_ids else False
# 从源stock.move对象获取源stock.picking对象
origin_picking = origin_move.picking_id if origin_move else False
# 现在origin_picking就是current_picking的上一步
# 如果前一个调拨单有目标货位,那么当前调拨单的当前货位就是前一个调拨单的目标货位
if origin_picking:
for i in current_picking.move_line_ids:
for j in origin_picking.move_line_ids:
if j.destination_location_id:
if i.lot_id == j.lot_id:
i.current_location_id = j.destination_location_id
# if origin_picking.move_line_ids.destination_location_id:
# aa = origin_picking.move_line_ids
# bb = origin_picking.move_line_ids.destination_location_id
# record.current_location_id = origin_picking.move_line_ids.destination_location_id
#
# # 获取目标stock.move对象
# dest_move = current_move.move_dest_ids[0] if current_move.move_dest_ids else False
#
# # 从目标stock.move对象获取目标stock.picking对象
# dest_picking = dest_move.picking_id if dest_move else False
# # 现在dest_picking就是current_picking的下一步
# 是一张单据一张单据往下走的,所以这里的目标货位是上一张单据的当前货位,且这样去计算是可以的。
@api.depends('location_dest_id')
def _compute_location_dest_id_value(self):
for record in self:
record.location_dest_id_value = record.location_dest_id.id if record.location_dest_id else False
destination_location_id = fields.Many2one(
'sf.shelf.location', string='目标货位')
@api.onchange('destination_location_id')
def _compute_destination_location_id(self):
for record in self:
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
class SfStockPicking(models.Model):
_inherit = 'stock.picking'
def button_validate(self):
"""
重写验证方法,当验证时意味着调拨单已经完成,已经移动到了目标货位,所以需要将当前货位的状态改为空闲
"""
res = super(SfStockPicking, self).button_validate()
for line in self.move_line_ids:
if line:
if line.current_location_id:
line.current_location_id.product_sn_id = False
line.current_location_id = False
return res
class SfProcurementGroup(models.Model):

View File

@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record id="sf_stock_move_line_tree" model="ir.ui.view">
<field name="name">sf.stock.move.line.tree</field>
<field name="model">stock.move.line</field>
<field name="inherit_id" ref="stock.view_stock_move_line_detailed_operation_tree"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='location_id'][2]" position="after">
<field name="current_location_id"/>
</xpath>
<xpath expr="//field[@name='location_dest_id'][2]" position="after">
<field name="destination_location_id" domain="[
('location_type', '=', '货位'),
('location_id', '=', location_dest_id_value),
('location_status', '=', '空闲')
]"/>
<!-- <field name="location_dest_id_product_type"/> -->
<!-- <field name="location_dest_id"/> -->
<field name="location_dest_id_value" invisible="1"/>
<!-- <button name="button_test" string="测试" type="object" class="oe_highlight"/> -->
</xpath>
</field>
</record>
<record id="sf_stock_move_line_form" model="ir.ui.view">
<field name="name">sf.stock.move.line.form</field>
<field name="model">stock.move.line</field>
<field name="inherit_id" ref="stock.view_move_line_form"/>
<field name="arch" type="xml">
<xpath expr="//form//sheet//group//group//field[@name='location_id']" position="after">
<field name="current_location_id" options="{'no_create': False}"/>
</xpath>
<xpath expr="//form//sheet//group//group//field[@name='location_dest_id']" position="after">
<field name="destination_location_id" options="{'no_create': False}"/>
</xpath>
</field>
</record>
</data>
</odoo>

View File

@@ -28,15 +28,18 @@
<field name="name" string="名称"/>
<field name="barcode" string="编码"/>
<field name="location_type"/>
<field name="location_id"/>
<field name="shelf_location_id" attrs="{'invisible': [('location_type', '=', '货位')]}"/>
<field name="location_id" attrs="{'readonly': [('location_type', '=', '货位')], 'invisible': [('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="product_sn_id" attrs="{'invisible': [('hide_location', '=', False)], 'required': [('hide_location', '!=', False), ('location_status', '=', '空闲')]}"/>
<field name="product_sn_id" attrs="{'invisible': [('hide_location', '=', False)]}"/>
<!-- <field name="product_type" widget="many2many_tags"/> -->
<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" attrs="{'invisible': [('hide_location', '=', False)], 'required': [('hide_location', '!=', False), ('location_status', '=', '占用')]}"/>
<!-- <field name="product_id" attrs="{'invisible': [('hide_location', '=', False)], 'required': [('hide_location', '!=', False), ('location_status', '=', '占用')]}"/> -->
<field name="product_id" attrs="{'invisible': [('hide_location', '=', False)]}"/>
<!-- <field name="product_type" attrs="{'invisible': [('hide_location', '=', False)], 'required': [('hide_location', '!=', False), ('location_status', '=', '占用')]}" widget="many2many_tags"/> -->
<field name="location_status" attrs="{'invisible': [('hide_location', '=', False)], 'required': [('hide_location', '!=', False)]}"/>
</group>
</sheet>
@@ -44,108 +47,49 @@
</field>
</record>
<!-- 自己生成 -->
<!-- <record id="view_shelf_location_search" model="ir.ui.view"> -->
<!-- <field name="name">Shelf Location</field> -->
<!-- <field name="model">sf.shelf.location</field> -->
<!-- <field name="arch" type="xml"> -->
<!-- <search string="Shelf Location"> -->
<!-- <field name="name" string="名称"/> -->
<!-- <field name="barcode" string="编码"/> -->
<!-- <field name="location_type"/> -->
<!-- <field name="channel"/> -->
<!-- <field name="direction"/> -->
<!-- <field name="shelf_height"/> -->
<!-- <field name="shelf_layer"/> -->
<!-- <field name="layer_capacity"/> -->
<!-- </search> -->
<!-- </field> -->
<!-- </record> -->
<!-- -->
<!-- <record id="view_shelf_location_kanban" model="ir.ui.view"> -->
<!-- <field name="name">Shelf Location</field> -->
<!-- <field name="model">sf.shelf.location</field> -->
<!-- <field name="arch" type="xml"> -->
<!-- <kanban class="o_kanban_mobile" js_class="custom_kanban"> -->
<!-- <field name="name"/> -->
<!-- <field name="barcode"/> -->
<!-- <field name="location_type"/> -->
<!-- <field name="channel"/> -->
<!-- <field name="direction"/> -->
<!-- <field name="shelf_height"/> -->
<!-- <field name="shelf_layer"/> -->
<!-- <field name="layer_capacity"/> -->
<!-- </kanban> -->
<!-- </field> -->
<!-- </record> -->
<!-- -->
<!-- <record id="action_shelf_location" model="ir.actions.act_window"> -->
<!-- <field name="name">Shelf Location</field> -->
<!-- <field name="res_model">sf.shelf.location</field> -->
<!-- <field name="view_mode">tree,form,kanban</field> -->
<!-- <field name="search_view_id" ref="view_shelf_location_search"/> -->
<!-- </record> -->
<!-- -->
<!-- <menuitem id="menu_shelf_location" name="Shelf Location" parent="sf_stock.menu_stock" sequence="1"/> -->
<!-- <menuitem id="menu_shelf_location_tree" name="Shelf Location" parent="menu_shelf_location" action="action_shelf_location" sequence="1"/> -->
<!-- <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" js_class="custom_kanban"> -->
<!-- <templates> -->
<!-- <t t-name="kanban-box"> -->
<!-- <div t-attf-class="oe_kanban_card oe_kanban_global_click -->
<!-- #{record.location_status.raw_value == '空闲' ? 'kanban_color_1' : ''} -->
<!-- #{record.location_status.raw_value == '占用' ? 'kanban_color_2' : ''} -->
<!-- #{record.location_status.raw_value == '禁用' ? 'kanban_color_3' : ''}"> -->
<!-- --><!-- 标题 -->
<!-- <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 class="o_kanban_record_bottom"> -->
<!-- <field name="product_sn_id"/> -->
<!-- <span> | </span> -->
<!-- <field name="product_id"/> -->
<!-- </div> -->
<!-- </div> -->
<!-- </t> -->
<record id="shelf_location_kanban_view" model="ir.ui.view">
<field name="name">shelf.location.kanban</field>
<field name="model">sf.shelf.location</field>
<field name="arch" type="xml">
<kanban class="o_kanban_mobile" js_class="custom_kanban">
<templates>
<t t-name="kanban-box">
<div t-attf-class="oe_kanban_card oe_kanban_global_click
#{record.location_status.raw_value == '空闲' ? 'kanban_color_1' : ''}
#{record.location_status.raw_value == '占用' ? 'kanban_color_2' : ''}
#{record.location_status.raw_value == '禁用' ? 'kanban_color_3' : ''}">
<!-- 标题 -->
<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 class="o_kanban_record_bottom">
<field name="product_sn_id"/>
<span> | </span>
<field name="product_id"/>
</div>
</div>
</t>
<!-- <t t-name="kanban-box"> -->
<!-- <div t-attf-class="oe_kanban_card oe_kanban_global_click -->
<!-- #{record.location_status.raw_value == '空闲' ? 'kanban_color_1' : ''} -->
<!-- #{record.location_status.raw_value == '占用' ? 'kanban_color_2' : ''} -->
<!-- #{record.location_status.raw_value == '禁用' ? 'kanban_color_3' : ''}"> -->
<!-- --><!-- --><!-- 看板内容 -->
<!-- --><!-- 看板内容 -->
<!-- </div> -->
<!-- <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> -->
@@ -156,17 +100,50 @@
<!-- </div> -->
<!-- </div> -->
<!-- </t> -->
<!-- </templates> -->
<!-- </kanban> -->
<!-- </field> -->
<!-- </record> -->
</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="shelf_location_search_view" model="ir.ui.view">
<field name="name">shelf.location.search</field>
<field name="model">sf.shelf.location</field>
<field name="arch" type="xml">
<search string="货架货位">
<searchpanel class="account_root">
<!-- <field name="location_type" icon="fa-filter"/> -->
<field name="location_id" select="multi" icon="fa-filter"/>
<!-- <field name="location_status" icon="fa-filter"/> -->
</searchpanel>
</search>
</field>
</record>
<record id="shelf_location_kanban_action_id" model="ir.actions.act_window">
<field name="name">货架货位</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">sf.shelf.location</field>
<field name="view_mode">kanban,form</field>
<field name="domain">[('location_type', '=', '货位')]</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="shelf_location_kanban_menu" name="货位看板" parent="stock.menu_stock_root"
sequence="51"
action="shelf_location_kanban_action_id"/>
<record id="action_sf_shelf_location" model="ir.actions.act_window">
<field name="name">货架货位</field>

View File

@@ -158,9 +158,9 @@
<!-- </record> -->
<menuitem id="menu_stock_location" name="货位状态" parent="stock.menu_stock_root"
sequence="50"
action="kanban_action_id"/>
<!-- <menuitem id="menu_stock_location" name="货位状态" parent="stock.menu_stock_root" -->
<!-- sequence="50" -->
<!-- action="kanban_action_id"/> -->
</data>