新增货架一键打印所有货位条码和单个打印货位条码
This commit is contained in:
@@ -222,11 +222,13 @@ class SfLocation(models.Model):
|
||||
|
||||
class SfShelf(models.Model):
|
||||
_name = 'sf.shelf'
|
||||
_inherit = ['printing.utils']
|
||||
_description = '货架'
|
||||
_order = 'create_date desc'
|
||||
|
||||
name = fields.Char('货架名称', required=True, size=20)
|
||||
barcode = fields.Char('编码', copy=False, size=15, required=True)
|
||||
|
||||
# 货位
|
||||
location_ids = fields.One2many('sf.shelf.location', 'shelf_id', string='货位')
|
||||
|
||||
@@ -300,9 +302,38 @@ class SfShelf(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 print_all_location_barcode(self):
|
||||
"""
|
||||
打印所有货位编码
|
||||
"""
|
||||
print('=======打印货架所有货位编码=========')
|
||||
for record in self.location_ids:
|
||||
print('record', record)
|
||||
if not record.barcode:
|
||||
continue
|
||||
record.ensure_one()
|
||||
# qr_code_data = record.lot_qr_code
|
||||
# if not qr_code_data:
|
||||
# raise UserError("没有找到二维码数据。")
|
||||
barcode = record.barcode
|
||||
# todo 待控制
|
||||
if not barcode:
|
||||
raise ValidationError("请先分配序列号")
|
||||
# host = "192.168.50.110" # 可以根据实际情况修改
|
||||
# port = 9100 # 可以根据实际情况修改
|
||||
|
||||
# 获取默认打印机配置
|
||||
printer_config = self.env['printer.configuration'].sudo().search([('model', '=', self._name)], limit=1)
|
||||
if not printer_config:
|
||||
raise UserError('请先配置打印机')
|
||||
host = printer_config.printer_id.ip_address
|
||||
port = printer_config.printer_id.port
|
||||
self.print_qr_code(barcode, host, port)
|
||||
|
||||
|
||||
class ShelfLocation(models.Model):
|
||||
_name = 'sf.shelf.location'
|
||||
_inherit = ['printing.utils']
|
||||
_description = '货位'
|
||||
_order = 'id asc, create_date asc'
|
||||
|
||||
@@ -326,6 +357,8 @@ class ShelfLocation(models.Model):
|
||||
|
||||
name = fields.Char('货位名称', required=True, size=20)
|
||||
barcode = fields.Char('货位编码', copy=False, size=50)
|
||||
qr_code = fields.Binary(string='二维码', compute='_compute_location_qr_code', store=True)
|
||||
|
||||
# 货架
|
||||
shelf_id = fields.Many2one('sf.shelf', string='货架')
|
||||
|
||||
@@ -337,6 +370,63 @@ class ShelfLocation(models.Model):
|
||||
def action_check(self):
|
||||
self.check_state = 'enable'
|
||||
|
||||
@api.depends('barcode')
|
||||
def _compute_location_qr_code(self):
|
||||
for record in self:
|
||||
if record.barcode:
|
||||
# 创建一个QRCode对象
|
||||
qr = qrcode.QRCode(
|
||||
version=1, # 设置版本, 1-40,控制二维码的大小
|
||||
error_correction=qrcode.constants.ERROR_CORRECT_L, # 设置错误校正等级
|
||||
box_size=10, # 设置每个格子的像素大小
|
||||
border=4, # 设置边框的格子宽度
|
||||
)
|
||||
# 添加数据
|
||||
qr.add_data(record.barcode)
|
||||
qr.make(fit=True)
|
||||
# 创建二维码图像
|
||||
img = qr.make_image(fill_color="black", back_color="white")
|
||||
# 创建一个内存文件
|
||||
buffer = io.BytesIO()
|
||||
img.save(buffer, format="PNG") # 将图像保存到内存文件中
|
||||
# 获取二进制数据
|
||||
binary_data = buffer.getvalue()
|
||||
# 使用Base64编码这些二进制数据
|
||||
data = base64.b64encode(binary_data)
|
||||
self.qr_code = data
|
||||
else:
|
||||
record.qr_code = False
|
||||
|
||||
def print_single_location_qr_code(self):
|
||||
self.ensure_one()
|
||||
qr_code_data = self.qr_code
|
||||
if not qr_code_data:
|
||||
raise UserError("没有找到二维码数据。")
|
||||
barcode = self.barcode
|
||||
# host = "192.168.50.110" # 可以根据实际情况修改
|
||||
# port = 9100 # 可以根据实际情况修改
|
||||
# 获取默认打印机配置
|
||||
printer_config = self.env['printer.configuration'].sudo().search([('model', '=', self._name)], limit=1)
|
||||
if not printer_config:
|
||||
raise UserError('请先配置打印机')
|
||||
host = printer_config.printer_id.ip_address
|
||||
port = printer_config.printer_id.port
|
||||
self.print_qr_code(barcode, host, port)
|
||||
# 获取当前wizard的视图ID或其他标识信息
|
||||
view_id = self.env.context.get('view_id')
|
||||
# 构造返回wizard页面的action字典
|
||||
action = {
|
||||
'type': 'ir.actions.act_window',
|
||||
'name': '返回 Wizard',
|
||||
'res_model': 'sf.shelf', # 替换为你的wizard模型名称
|
||||
'view_mode': 'form',
|
||||
'view_id': view_id, # 如果需要基于特定的视图返回
|
||||
'target': 'new', # 如果需要在新的窗口或标签页打开
|
||||
'res_id': self.shelf_id, # 如果你想要返回当前记录的视图
|
||||
}
|
||||
return action
|
||||
|
||||
|
||||
# # 仓库类别(selection:库区、库位、货位)
|
||||
# location_type = fields.Selection([
|
||||
# ('货架', '货架'),
|
||||
@@ -446,7 +536,7 @@ class Sf_stock_move_line(models.Model):
|
||||
raise UserError(_('抱歉,只有库管人员可以执行此动作'))
|
||||
|
||||
# 如果用户有权限,调用父类方法
|
||||
return super(CustomStockMoveLine, self).action_revert_inventory()
|
||||
return super().action_revert_inventory()
|
||||
|
||||
@api.depends('lot_name')
|
||||
def _compute_lot_qr_code(self):
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<data>
|
||||
<!-- 货架视图 -->
|
||||
<!-- 货架视图 -->
|
||||
<record id="view_sf_shelf" model="ir.ui.view">
|
||||
<field name="name">Sf Shelf</field>
|
||||
<field name="model">sf.shelf</field>
|
||||
@@ -9,7 +9,8 @@
|
||||
<form string="Sf Shelf">
|
||||
<header>
|
||||
<field name="is_there_area" invisible="1"/>
|
||||
<button string="生成货位" name="create_location" type="object" class="oe_highlight" attrs="{'invisible': [('is_there_area', '=', True)]}"/>
|
||||
<button string="生成货位" name="create_location" type="object" class="oe_highlight"
|
||||
attrs="{'invisible': [('is_there_area', '=', True)]}"/>
|
||||
</header>
|
||||
<sheet>
|
||||
<group>
|
||||
@@ -23,12 +24,21 @@
|
||||
<field name="shelf_layer" string="货架层数"/>
|
||||
<field name="layer_capacity" string="层数容量"/>
|
||||
</group>
|
||||
<field name="location_ids" widget="one2many_list">
|
||||
<tree string="Shelf Location">
|
||||
<field name="barcode" string="编码"/>
|
||||
<field name="name" string="名称"/>
|
||||
</tree>
|
||||
</field>
|
||||
<notebook>
|
||||
<page string="货位">
|
||||
<button name="print_all_location_barcode" type="object" string="一键打印"
|
||||
class="oe_highlight"/>
|
||||
<field name="location_ids" widget="one2many_list">
|
||||
<tree string="Shelf Location">
|
||||
<field name="barcode" string="编码"/>
|
||||
<field name="name" string="名称"/>
|
||||
<field name="qr_code" string="条码"/>
|
||||
<button string="打印" name="print_single_location_qr_code" type="object"
|
||||
class="oe_highlight"/>
|
||||
</tree>
|
||||
</field>
|
||||
</page>
|
||||
</notebook>
|
||||
</sheet>
|
||||
</form>
|
||||
</field>
|
||||
@@ -46,23 +56,23 @@
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- 货架action -->
|
||||
<!-- 货架action -->
|
||||
<record id="sf_shelf_action" model="ir.actions.act_window">
|
||||
<field name="name">货架</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">sf.shelf</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
<!-- <field name="view_id" ref="view_sf_shelf_tree"/> -->
|
||||
<!-- <field name="view_id" ref="view_sf_shelf_tree"/> -->
|
||||
</record>
|
||||
|
||||
<!-- 货架菜单 -->
|
||||
<!-- 货架菜单 -->
|
||||
<menuitem
|
||||
id="sf_shelf_menu"
|
||||
name="货架"
|
||||
parent="stock.menu_warehouse_config"
|
||||
sequence="19"
|
||||
action="sf_shelf_action"
|
||||
groups="sf_warehouse.group_sf_stock_user"/>
|
||||
id="sf_shelf_menu"
|
||||
name="货架"
|
||||
parent="stock.menu_warehouse_config"
|
||||
sequence="19"
|
||||
action="sf_shelf_action"
|
||||
groups="sf_warehouse.group_sf_stock_user"/>
|
||||
|
||||
|
||||
<record id="view_shelf_location_tree" model="ir.ui.view">
|
||||
@@ -120,9 +130,11 @@
|
||||
<header>
|
||||
|
||||
<field name="location_status" invisible="1"/>
|
||||
<button string="禁用货位" name="action_location_status_disable" type="object" class="oe_highlight"
|
||||
<button string="禁用货位" name="action_location_status_disable" type="object"
|
||||
class="oe_highlight"
|
||||
attrs="{'invisible': [('location_status', '!=', '空闲')]}"/>
|
||||
<button string="启用货位" name="action_location_status_enable" type="object" class="oe_highlight"
|
||||
<button string="启用货位" name="action_location_status_enable" type="object"
|
||||
class="oe_highlight"
|
||||
attrs="{'invisible': [('location_status', '!=', '禁用')]}"/>
|
||||
</header>
|
||||
<sheet>
|
||||
@@ -170,13 +182,13 @@
|
||||
#{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>
|
||||
@@ -187,31 +199,31 @@
|
||||
</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> -->
|
||||
<!-- <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> -->
|
||||
<!-- <div class="o_kanban_record_bottom"> -->
|
||||
<!-- <field name="product_sn_id"/> -->
|
||||
<!-- <span> | </span> -->
|
||||
<!-- <field name="product_id"/> -->
|
||||
<!-- </div> -->
|
||||
<!-- </div> -->
|
||||
<!-- </t> -->
|
||||
</templates>
|
||||
</kanban>
|
||||
</field>
|
||||
@@ -225,7 +237,7 @@
|
||||
<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_id" select="multi" icon="fa-filter"/> -->
|
||||
<field name="location_id" string="所属库区" icon="fa-filter"/>
|
||||
<field name="shelf_id" string="货架"/>
|
||||
<!-- <field name="location_status" icon="fa-filter"/> -->
|
||||
@@ -239,7 +251,7 @@
|
||||
<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">[('check_state','=','enable')]</field> -->
|
||||
<!-- <field name="domain">[('check_state','=','enable')]</field> -->
|
||||
</record>
|
||||
|
||||
<!-- <record id="example_action" model="ir.actions.act_window"> -->
|
||||
|
||||
Reference in New Issue
Block a user