Accept Merge Request #914: (feature/制造代码优化 -> develop)
Merge Request: odoo标签打印及去除odoo相关标识 Created By: @马广威 Accepted By: @马广威 URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/914?initial=true
This commit is contained in:
@@ -10,9 +10,9 @@
|
||||
""",
|
||||
'category': 'sf',
|
||||
'website': 'https://www.sf.jikimo.com',
|
||||
'depends': ['web', 'purchase'],
|
||||
'depends': ['web', 'purchase', 'base_setup'],
|
||||
'data': [
|
||||
|
||||
'views/bye_odoo.xml',
|
||||
],
|
||||
'demo': [
|
||||
],
|
||||
@@ -23,6 +23,8 @@
|
||||
'web.assets_backend': [
|
||||
'jikimo_frontend/static/src/fields/custom_many2many_checkboxes/*',
|
||||
'jikimo_frontend/static/src/fields/Many2OneRadioField/*',
|
||||
# 移除odoo相关标识
|
||||
'jikimo_frontend/static/src/bye_odoo/*',
|
||||
'jikimo_frontend/static/src/scss/custom_style.scss',
|
||||
# 'jikimo_frontend/static/src/views/list_nums/list_nbCols.js',
|
||||
'jikimo_frontend/static/src/views/list_nums/list_nums.xml',
|
||||
|
||||
23
jikimo_frontend/data/demo_data.xml
Normal file
23
jikimo_frontend/data/demo_data.xml
Normal file
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<data>
|
||||
<record id="partner_demo_company" model="res.partner">
|
||||
<field name="name">JKM</field>
|
||||
<field name="street">B-25</field>
|
||||
<field name="city">USA</field>
|
||||
<!-- Use the correct reference or actual ID for the country -->
|
||||
<field name="country_id" ref="base.bd"/>
|
||||
<field name="zip">1229</field>
|
||||
<field name="phone">+8801-712901764</field>
|
||||
<field name="email">info@kolpolok.com</field>
|
||||
<field name="website">www.kolpoloktechnologies.com</field>
|
||||
</record>
|
||||
|
||||
<record id="demo_company" model="res.company">
|
||||
<field name="name">Custom</field>
|
||||
<field name="logo" type="base64" file="kolpolok_custom_title_and_favicon/static/src/img/favicon.ico"/>
|
||||
<field name="favicon" type="base64" file="kolpolok_custom_title_and_favicon/static/src/img/favicon.ico"/>
|
||||
<field name="partner_id" ref="partner_demo_company"/>
|
||||
</record>
|
||||
</data>
|
||||
</odoo>
|
||||
16
jikimo_frontend/static/src/bye_odoo/extended_user_menu.js
Normal file
16
jikimo_frontend/static/src/bye_odoo/extended_user_menu.js
Normal file
@@ -0,0 +1,16 @@
|
||||
/** @odoo-module **/
|
||||
import { UserMenu } from "@web/webclient/user_menu/user_menu";
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
import { registry } from "@web/core/registry";
|
||||
const userMenuRegistry = registry.category("user_menuitems");
|
||||
|
||||
|
||||
patch(UserMenu.prototype, "legion_hide_odoo.UserMenu", {
|
||||
setup() {
|
||||
this._super.apply(this, arguments);
|
||||
userMenuRegistry.remove("documentation");
|
||||
userMenuRegistry.remove("support");
|
||||
userMenuRegistry.remove("odoo_account");
|
||||
},
|
||||
|
||||
});
|
||||
11
jikimo_frontend/static/src/bye_odoo/favicon.js
Normal file
11
jikimo_frontend/static/src/bye_odoo/favicon.js
Normal file
@@ -0,0 +1,11 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { WebClient } from "@web/webclient/webclient";
|
||||
import { patch } from "web.utils";
|
||||
|
||||
patch(WebClient.prototype, "kolpolok_custom_title_and_favicon.WebClient", {
|
||||
setup() {
|
||||
this._super();
|
||||
this.title.setParts({ zopenerp: "JIKIMO" });
|
||||
},
|
||||
});
|
||||
BIN
jikimo_frontend/static/src/img/favicon.ico
Normal file
BIN
jikimo_frontend/static/src/img/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.0 KiB |
BIN
jikimo_frontend/static/src/img/jikimo-logo.ico
Normal file
BIN
jikimo_frontend/static/src/img/jikimo-logo.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.9 KiB |
BIN
jikimo_frontend/static/src/img/jikimo.ico
Normal file
BIN
jikimo_frontend/static/src/img/jikimo.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.1 KiB |
35
jikimo_frontend/views/bye_odoo.xml
Normal file
35
jikimo_frontend/views/bye_odoo.xml
Normal file
@@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<data>
|
||||
|
||||
<!-- 修改页面头部图标及文字 -->
|
||||
<template id="favicon_icon" inherit_id="web.layout" name="Web layout">
|
||||
<!-- change the title with reliance partner -->
|
||||
<xpath expr="//head//title" position="before">
|
||||
<title t-esc="'JIKIMO'"/>
|
||||
</xpath>
|
||||
<!-- change the default favicon icon with -->
|
||||
<xpath expr="//head//link[@rel='shortcut icon']" position="replace">
|
||||
<link type="image/x-icon" rel="shortcut icon" href="/jikimo_frontend/static/src/img/jikimo-logo.ico"/>
|
||||
</xpath>
|
||||
</template>
|
||||
|
||||
<!-- hide 登录页面 powerd by odoo 及管理数据库 -->
|
||||
<template id="login_page_layout" inherit_id="web.login_layout" name="Login Page Layout">
|
||||
<xpath expr="//div[@class='card-body']//div[last()]" position="replace"></xpath>
|
||||
</template>
|
||||
|
||||
<!-- 隐藏odoo版本信息 -->
|
||||
<record id="jikimo_res_config_settings_view_form" model="ir.ui.view">
|
||||
<field name="name">jikimo.res.config.settings.view.form.inherit.base.setup</field>
|
||||
<field name="model">res.config.settings</field>
|
||||
<field name="inherit_id" ref="base_setup.res_config_settings_view_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//div[@id='about']" position="replace">
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
</data>
|
||||
</odoo>
|
||||
@@ -24,6 +24,7 @@
|
||||
'views/tool_menu.xml',
|
||||
'views/menu_fixture_view.xml',
|
||||
'views/change_base_view.xml',
|
||||
'views/Printer.xml',
|
||||
|
||||
],
|
||||
'demo': [
|
||||
|
||||
28
sf_base/commons/Printer.py
Normal file
28
sf_base/commons/Printer.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from odoo import models, fields
|
||||
|
||||
|
||||
class Printer(models.Model):
|
||||
_name = 'printer'
|
||||
_description = 'Printer'
|
||||
|
||||
name = fields.Char(string='名称', required=True)
|
||||
ip_address = fields.Char(string='IP 地址', required=True)
|
||||
port = fields.Integer(string='端口', default=9100)
|
||||
|
||||
|
||||
class TableStyle(models.Model):
|
||||
_name = 'table.style'
|
||||
_description = '标签样式'
|
||||
|
||||
name = fields.Char(string='名称', required=True)
|
||||
# todo
|
||||
|
||||
|
||||
class PrinterConfiguration(models.Model):
|
||||
_name = 'printer.configuration'
|
||||
_description = 'Printer Configuration'
|
||||
|
||||
name = fields.Char(string='名称', required=True)
|
||||
printer_id = fields.Many2one('printer', string='打印机')
|
||||
model = fields.Many2one('ir.model', string='模型名称')
|
||||
# # 其他相关字段...
|
||||
@@ -1 +1,2 @@
|
||||
from . import common
|
||||
from . import Printer
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import time, datetime
|
||||
import hashlib
|
||||
from odoo import models
|
||||
|
||||
import socket
|
||||
|
||||
class Common(models.Model):
|
||||
_name = 'sf.sync.common'
|
||||
@@ -29,3 +29,66 @@ class Common(models.Model):
|
||||
d = dt + datetime.timedelta(hours=8)
|
||||
nTime = d.strftime("%Y-%m-%d %H:%M:%S")
|
||||
return nTime
|
||||
|
||||
|
||||
class PrintingUtils(models.AbstractModel):
|
||||
_name = 'printing.utils'
|
||||
_description = 'Utility class for printing functionalities'
|
||||
|
||||
def generate_zpl_code(self, code):
|
||||
# 实现生成ZPL代码的逻辑
|
||||
# 初始化ZPL代码字符串
|
||||
zpl_code = "^XA\n"
|
||||
zpl_code += "^CW1,E:SIMSUN.TTF^FS\n"
|
||||
zpl_code += "^CI28\n"
|
||||
|
||||
# 设置二维码位置
|
||||
zpl_code += "^FO50,50\n" # 调整二维码位置,使其与资产编号在同一行
|
||||
zpl_code += f"^BQN,2,6^FDLM,B0093{code}^FS\n"
|
||||
|
||||
# 设置资产编号文本位置
|
||||
zpl_code += "^FO300,60\n" # 资产编号文本的位置,与二维码在同一行
|
||||
zpl_code += "^A1N,45,45^FD编码名称: ^FS\n"
|
||||
|
||||
# 设置{code}文本位置
|
||||
# 假设{code}文本需要位于资产编号和二维码下方,中间位置
|
||||
# 设置{code}文本位置并启用自动换行
|
||||
zpl_code += "^FO300,120\n" # {code}文本的起始位置
|
||||
zpl_code += "^FB400,4,0,L,0\n" # 定义一个宽度为500点的文本框,最多4行,左对齐
|
||||
zpl_code += f"^A1N,40,40^FD{code}^FS\n"
|
||||
|
||||
# 在{code}文本框周围绘制线框
|
||||
# 假设线框的外部尺寸为宽度500点,高度200点
|
||||
# zpl_code += "^FO300,110^GB500,200,2^FS\n" # 绘制线框,边框粗细为2点
|
||||
|
||||
zpl_code += "^PQ1,0,1,Y\n"
|
||||
zpl_code += "^XZ\n"
|
||||
return zpl_code
|
||||
|
||||
def send_to_printer(self, host, port, zpl_code):
|
||||
|
||||
# 实现发送ZPL代码到打印机的逻辑
|
||||
# 将ZPL代码转换为字节串
|
||||
print('zpl_code', zpl_code)
|
||||
zpl_bytes = zpl_code.encode('utf-8')
|
||||
print(zpl_bytes)
|
||||
|
||||
# 创建socket对象
|
||||
mysocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
try:
|
||||
mysocket.connect((host, port)) # 连接到打印机
|
||||
mysocket.send(zpl_bytes) # 发送ZPL代码
|
||||
print("ZPL code sent to printer successfully.")
|
||||
except Exception as e:
|
||||
print(f"Error with the connection: {e}")
|
||||
finally:
|
||||
mysocket.close() # 关闭连接
|
||||
|
||||
def print_qr_code(self, lot_name, host, port):
|
||||
# 实现打印二维码的逻辑
|
||||
# 这里需要传入 lot_name 参数,因为我们不能直接访问 self.lot_id.name
|
||||
zpl_code = self.generate_zpl_code(lot_name)
|
||||
# 发送ZPL代码到打印机
|
||||
# host = "192.168.50.110" # 可以作为参数传入,或者在此配置
|
||||
# port = 9100 # 可以作为参数传入,或者在此配置
|
||||
self.send_to_printer(host, port, zpl_code)
|
||||
|
||||
@@ -188,3 +188,7 @@ access_sf_machine_brand_tags_group_sale_director,sf_machine_brand_tags_group_sal
|
||||
access_sf_machine_brand_tags_group_plan_director,sf_machine_brand_tags_group_plan_director,model_sf_machine_brand_tags,sf_base.group_plan_director,1,0,0,0
|
||||
access_sf_machine_brand_tags_group_purchase,sf_machine_brand_tags_group_purchase,model_sf_machine_brand_tags,sf_base.group_purchase,1,0,0,0
|
||||
access_sf_machine_brand_tags_group_purchase_director,sf_machine_brand_tags_group_purchase_director,model_sf_machine_brand_tags,sf_base.group_purchase_director,1,0,0,0
|
||||
|
||||
|
||||
access_printer,printer,model_printer,base.group_user,1,1,1,1
|
||||
access_printer_configuration,printer.configuration,model_printer_configuration,base.group_user,1,1,1,1
|
||||
|
112
sf_base/views/Printer.xml
Normal file
112
sf_base/views/Printer.xml
Normal file
@@ -0,0 +1,112 @@
|
||||
<odoo>
|
||||
<data>
|
||||
|
||||
<record id="view_printer_tree" model="ir.ui.view">
|
||||
<field name="name">printer.tree</field>
|
||||
<field name="model">printer</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Printer">
|
||||
<field name="name"/>
|
||||
<field name="ip_address"/>
|
||||
<field name="port"/>
|
||||
<!-- 其他字段... -->
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_printer_form" model="ir.ui.view">
|
||||
<field name="name">printer.form</field>
|
||||
<field name="model">printer</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Printer">
|
||||
<sheet>
|
||||
<group>
|
||||
<field name="name"/>
|
||||
<field name="ip_address"/>
|
||||
<field name="port"/>
|
||||
</group>
|
||||
</sheet>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_printer_configuration_tree" model="ir.ui.view">
|
||||
<field name="name">printer.configuration.tree</field>
|
||||
<field name="model">printer.configuration</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Printer Configuration">
|
||||
<field name="name"/>
|
||||
<field name="printer_id"/>
|
||||
<field name="model"/>
|
||||
<!-- 其他字段... -->
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_printer_configuration_form" model="ir.ui.view">
|
||||
<field name="name">printer.configuration.form</field>
|
||||
<field name="model">printer.configuration</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Printer Configuration">
|
||||
<sheet>
|
||||
<group>
|
||||
<field name="name"/>
|
||||
<field name="printer_id"/>
|
||||
<field name="model"/>
|
||||
<!-- 其他字段... -->
|
||||
</group>
|
||||
</sheet>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- 其他视图... -->
|
||||
|
||||
<record id="action_printer" model="ir.actions.act_window">
|
||||
<field name="name">打印机</field>
|
||||
<field name="res_model">printer</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
</record>
|
||||
|
||||
<!-- Action to open the printer configuration list -->
|
||||
<record id="action_printer_configuration" model="ir.actions.act_window">
|
||||
<field name="name">打印配置</field>
|
||||
<field name="res_model">printer.configuration</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
</record>
|
||||
|
||||
<!-- Add a menu item for the printer configuration -->
|
||||
<!-- <record id="menu_printer_configuration" model="ir.ui.menu"> -->
|
||||
<!-- <field name="name">打印配置</field> -->
|
||||
<!-- <field name="action" ref="action_printer_configuration"/> -->
|
||||
<!-- <field name="parent_id" ref="base.menu_administration"/> -->
|
||||
<!-- </record> -->
|
||||
|
||||
<!-- <record id="menu_printer" model="ir.ui.menu"> -->
|
||||
<!-- <field name="name">打印机</field> -->
|
||||
<!-- <field name="action" ref="action_printer"/> -->
|
||||
<!-- <field name="parent_id" ref="menu_printer"/> -->
|
||||
<!-- </record> -->
|
||||
|
||||
<menuitem
|
||||
id="printer_main_menu"
|
||||
name="打印配置"
|
||||
sequence="10"
|
||||
parent="base.menu_administration"/>
|
||||
|
||||
<menuitem
|
||||
id="menu_printer"
|
||||
name="打印机"
|
||||
action="action_printer"
|
||||
sequence="1"
|
||||
parent="printer_main_menu"/>
|
||||
|
||||
<menuitem
|
||||
id="menu_printer_configuration"
|
||||
name="打印配置"
|
||||
action="action_printer_configuration"
|
||||
sequence="2"
|
||||
parent="printer_main_menu"/>
|
||||
|
||||
</data>
|
||||
</odoo>
|
||||
@@ -219,7 +219,8 @@ class StockRule(models.Model):
|
||||
|
||||
|
||||
class ProductionLot(models.Model):
|
||||
_inherit = 'stock.lot'
|
||||
_name = 'stock.lot'
|
||||
_inherit = ['stock.lot', 'printing.utils']
|
||||
|
||||
@api.model
|
||||
def generate_lot_names1(self, display_name, first_lot, count):
|
||||
@@ -307,36 +308,53 @@ class ProductionLot(models.Model):
|
||||
|
||||
record.qr_code_image = encoded_image
|
||||
|
||||
def print_qr_code(self):
|
||||
self.ensure_one() # 确保这个方法只为一个记录调用
|
||||
# if not self.lot_id:
|
||||
# raise UserError("没有找到序列号。")
|
||||
# 假设_lot_qr_code方法已经生成了二维码并保存在字段中
|
||||
def print_single_method(self):
|
||||
|
||||
self.ensure_one()
|
||||
qr_code_data = self.qr_code_image
|
||||
if not qr_code_data:
|
||||
raise UserError("没有找到二维码数据。")
|
||||
lot_name = self.name
|
||||
# host = "192.168.50.110" # 可以根据实际情况修改
|
||||
# port = 9100 # 可以根据实际情况修改
|
||||
|
||||
# 生成下载链接或直接触发下载
|
||||
# 此处的实现依赖于你的具体需求,以下是触发下载的一种示例
|
||||
attachment = self.env['ir.attachment'].sudo().create({
|
||||
'datas': self.qr_code_image,
|
||||
'type': 'binary',
|
||||
'description': '二维码图片',
|
||||
'name': self.name + '.png',
|
||||
# 'res_id': invoice.id,
|
||||
# 'res_model': 'stock.picking',
|
||||
'public': True,
|
||||
'mimetype': 'application/x-png',
|
||||
# 'model_name': 'stock.picking',
|
||||
})
|
||||
# 返回附件的下载链接
|
||||
download_url = '/web/content/%s?download=true' % attachment.id
|
||||
base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url')
|
||||
return {
|
||||
'type': 'ir.actions.act_url',
|
||||
'url': str(base_url) + download_url,
|
||||
'target': 'self',
|
||||
}
|
||||
# 获取默认打印机配置
|
||||
printer_config = self.env['printer.configuration'].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(lot_name, host, port)
|
||||
|
||||
# self.ensure_one() # 确保这个方法只为一个记录调用
|
||||
# # if not self.lot_id:
|
||||
# # raise UserError("没有找到序列号。")
|
||||
# # 假设_lot_qr_code方法已经生成了二维码并保存在字段中
|
||||
# qr_code_data = self.qr_code_image
|
||||
# if not qr_code_data:
|
||||
# raise UserError("没有找到二维码数据。")
|
||||
#
|
||||
# # 生成下载链接或直接触发下载
|
||||
# # 此处的实现依赖于你的具体需求,以下是触发下载的一种示例
|
||||
# attachment = self.env['ir.attachment'].sudo().create({
|
||||
# 'datas': self.qr_code_image,
|
||||
# 'type': 'binary',
|
||||
# 'description': '二维码图片',
|
||||
# 'name': self.name + '.png',
|
||||
# # 'res_id': invoice.id,
|
||||
# # 'res_model': 'stock.picking',
|
||||
# 'public': True,
|
||||
# 'mimetype': 'application/x-png',
|
||||
# # 'model_name': 'stock.picking',
|
||||
# })
|
||||
# # 返回附件的下载链接
|
||||
# download_url = '/web/content/%s?download=true' % attachment.id
|
||||
# base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url')
|
||||
# return {
|
||||
# 'type': 'ir.actions.act_url',
|
||||
# 'url': str(base_url) + download_url,
|
||||
# 'target': 'self',
|
||||
# }
|
||||
|
||||
|
||||
class StockPicking(models.Model):
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
</xpath>
|
||||
<xpath expr="//sheet" position="before">
|
||||
<header>
|
||||
<button string="打印二维码" name="print_qr_code" type="object" class="btn-primary"/>
|
||||
<button string="打印二维码" name="print_single_method" type="object" class="btn-primary"/>
|
||||
</header>
|
||||
</xpath>
|
||||
</field>
|
||||
|
||||
@@ -9,7 +9,7 @@ import requests
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.osv import expression
|
||||
from odoo.exceptions import UserError
|
||||
from odoo.exceptions import UserError, ValidationError
|
||||
|
||||
|
||||
class SfLocation(models.Model):
|
||||
@@ -388,7 +388,6 @@ class ShelfLocation(models.Model):
|
||||
record.product_id = False
|
||||
# record.location_status = '空闲'
|
||||
|
||||
|
||||
# 调取获取货位信息接口
|
||||
def get_sf_shelf_location_info(self):
|
||||
# sf_sync_config = self.env['res.config.settings'].get_values()
|
||||
@@ -414,7 +413,8 @@ class ShelfLocation(models.Model):
|
||||
|
||||
|
||||
class Sf_stock_move_line(models.Model):
|
||||
_inherit = 'stock.move.line'
|
||||
_name = 'stock.move.line'
|
||||
_inherit = ['stock.move.line', 'printing.utils']
|
||||
|
||||
current_location_id = fields.Many2one(
|
||||
'sf.shelf.location', string='当前货位', compute='_compute_current_location_id', store=True)
|
||||
@@ -465,36 +465,127 @@ class Sf_stock_move_line(models.Model):
|
||||
else:
|
||||
record.lot_qr_code = False
|
||||
|
||||
def print_qr_code(self):
|
||||
self.ensure_one() # 确保这个方法只为一个记录调用
|
||||
# if not self.lot_id:
|
||||
# raise UserError("没有找到序列号。")
|
||||
# 假设_lot_qr_code方法已经生成了二维码并保存在字段中
|
||||
def print_single_method(self):
|
||||
self.ensure_one()
|
||||
qr_code_data = self.lot_qr_code
|
||||
if not qr_code_data:
|
||||
raise UserError("没有找到二维码数据。")
|
||||
lot_name = self.lot_name
|
||||
# host = "192.168.50.110" # 可以根据实际情况修改
|
||||
# port = 9100 # 可以根据实际情况修改
|
||||
|
||||
# 生成下载链接或直接触发下载
|
||||
# 此处的实现依赖于你的具体需求,以下是触发下载的一种示例
|
||||
attachment = self.env['ir.attachment'].sudo().create({
|
||||
'datas': self.lot_qr_code,
|
||||
'type': 'binary',
|
||||
'description': '二维码图片',
|
||||
'name': self.lot_name + '.png',
|
||||
# 'res_id': invoice.id,
|
||||
# 'res_model': 'stock.picking',
|
||||
'public': True,
|
||||
'mimetype': 'application/x-png',
|
||||
# 'model_name': 'stock.picking',
|
||||
})
|
||||
# 返回附件的下载链接
|
||||
download_url = '/web/content/%s?download=true' % attachment.id
|
||||
base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url')
|
||||
return {
|
||||
'type': 'ir.actions.act_url',
|
||||
'url': str(base_url) + download_url,
|
||||
'target': 'self',
|
||||
# 获取默认打印机配置
|
||||
printer_config = self.env['printer.configuration'].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(lot_name, host, port)
|
||||
|
||||
# 返回当前wizard页面
|
||||
# base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url')
|
||||
# return {
|
||||
# 'type': 'ir.actions.act_url',
|
||||
# 'url': str(base_url) + download_url,
|
||||
# 'target': 'self',
|
||||
# }
|
||||
# 获取当前wizard的视图ID或其他标识信息
|
||||
view_id = self.env.context.get('view_id')
|
||||
# 构造返回wizard页面的action字典
|
||||
action = {
|
||||
'type': 'ir.actions.act_window',
|
||||
'name': '返回 Wizard',
|
||||
'res_model': 'stock.move', # 替换为你的wizard模型名称
|
||||
'view_mode': 'form',
|
||||
'view_id': view_id, # 如果需要基于特定的视图返回
|
||||
'target': 'new', # 如果需要在新的窗口或标签页打开
|
||||
'res_id': self.id, # 如果你想要返回当前记录的视图
|
||||
}
|
||||
return action
|
||||
|
||||
# def generate_zpl_code(self, code):
|
||||
# # 初始化ZPL代码字符串
|
||||
# zpl_code = "^XA\n"
|
||||
# zpl_code += "^CW1,E:SIMSUN.TTF^FS\n"
|
||||
# zpl_code += "^CI28\n"
|
||||
#
|
||||
# # 设置二维码位置
|
||||
# zpl_code += "^FO50,50\n" # 调整二维码位置,使其与资产编号在同一行
|
||||
# zpl_code += f"^BQN,2,6^FDLM,B0093{code}^FS\n"
|
||||
#
|
||||
# # 设置资产编号文本位置
|
||||
# zpl_code += "^FO300,60\n" # 资产编号文本的位置,与二维码在同一行
|
||||
# zpl_code += "^A1N,45,45^FD编码名称: ^FS\n"
|
||||
#
|
||||
# # 设置{code}文本位置
|
||||
# # 假设{code}文本需要位于资产编号和二维码下方,中间位置
|
||||
# # 设置{code}文本位置并启用自动换行
|
||||
# zpl_code += "^FO300,120\n" # {code}文本的起始位置
|
||||
# zpl_code += "^FB500,4,0,L,0\n" # 定义一个宽度为500点的文本框,最多4行,左对齐
|
||||
# zpl_code += f"^A1N,40,40^FD{code}^FS\n"
|
||||
#
|
||||
# # 在{code}文本框周围绘制线框
|
||||
# # 假设线框的外部尺寸为宽度500点,高度200点
|
||||
# # zpl_code += "^FO300,110^GB500,200,2^FS\n" # 绘制线框,边框粗细为2点
|
||||
#
|
||||
# zpl_code += "^PQ1,0,1,Y\n"
|
||||
# zpl_code += "^XZ\n"
|
||||
# return zpl_code
|
||||
#
|
||||
# def send_to_printer(self, host, port, zpl_code):
|
||||
# # 将ZPL代码转换为字节串
|
||||
# print('zpl_code', zpl_code)
|
||||
# zpl_bytes = zpl_code.encode('utf-8')
|
||||
# print(zpl_bytes)
|
||||
#
|
||||
# # 创建socket对象
|
||||
# mysocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
# try:
|
||||
# mysocket.connect((host, port)) # 连接到打印机
|
||||
# mysocket.send(zpl_bytes) # 发送ZPL代码
|
||||
# print("ZPL code sent to printer successfully.")
|
||||
# except Exception as e:
|
||||
# print(f"Error with the connection: {e}")
|
||||
# finally:
|
||||
# mysocket.close() # 关闭连接
|
||||
#
|
||||
# def print_qr_code(self):
|
||||
# self.ensure_one() # 确保这个方法只为一个记录调用
|
||||
# # if not self.lot_id:
|
||||
# # raise UserError("没有找到序列号。")
|
||||
# # 假设_lot_qr_code方法已经生成了二维码并保存在字段中
|
||||
# qr_code_data = self.lot_qr_code
|
||||
# if not qr_code_data:
|
||||
# raise UserError("没有找到二维码数据。")
|
||||
# # 生成ZPL代码
|
||||
# zpl_code = self.generate_zpl_code(self.lot_id.name)
|
||||
# # 设置打印机的IP地址和端口号
|
||||
# host = "192.168.50.110"
|
||||
# port = 9100
|
||||
# # 发送ZPL代码到打印机
|
||||
# self.send_to_printer(host, port, zpl_code)
|
||||
#
|
||||
# # # 生成下载链接或直接触发下载
|
||||
# # # 此处的实现依赖于你的具体需求,以下是触发下载的一种示例
|
||||
# # attachment = self.env['ir.attachment'].sudo().create({
|
||||
# # 'datas': self.lot_qr_code,
|
||||
# # 'type': 'binary',
|
||||
# # 'description': '二维码图片',
|
||||
# # 'name': self.lot_name + '.png',
|
||||
# # # 'res_id': invoice.id,
|
||||
# # # 'res_model': 'stock.picking',
|
||||
# # 'public': True,
|
||||
# # 'mimetype': 'application/x-png',
|
||||
# # # 'model_name': 'stock.picking',
|
||||
# # })
|
||||
# # # 返回附件的下载链接
|
||||
# # download_url = '/web/content/%s?download=true' % attachment.id
|
||||
# # base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url')
|
||||
# # return {
|
||||
# # 'type': 'ir.actions.act_url',
|
||||
# # 'url': str(base_url) + download_url,
|
||||
# # 'target': 'self',
|
||||
# # }
|
||||
|
||||
# # # 定义一个方法,用于根据序列号生成二维码
|
||||
# # @api.depends('lot_id')
|
||||
@@ -630,6 +721,17 @@ class Sf_stock_move_line(models.Model):
|
||||
class SfStockPicking(models.Model):
|
||||
_inherit = 'stock.picking'
|
||||
|
||||
check_in = fields.Char(string='查询是否为入库单', compute='_check_is_in')
|
||||
|
||||
@api.depends('name')
|
||||
def _check_is_in(self):
|
||||
"""
|
||||
判断是否为出库单
|
||||
"""
|
||||
if self.name:
|
||||
is_check_in = self.name.split('/')
|
||||
self.check_in = is_check_in[1]
|
||||
|
||||
def button_validate(self):
|
||||
"""
|
||||
重写验证方法,当验证时意味着调拨单已经完成,已经移动到了目标货位,所以需要将当前货位的状态改为空闲
|
||||
@@ -642,6 +744,20 @@ class SfStockPicking(models.Model):
|
||||
line.current_location_id.location_status = '空闲'
|
||||
return res
|
||||
|
||||
# def print_all_barcode(self):
|
||||
# """
|
||||
# 打印所有编码
|
||||
# """
|
||||
# print('================')
|
||||
# for record in self.move_ids_without_package:
|
||||
# print('record', record)
|
||||
# print('record.move_line_ids', record.move_line_ids)
|
||||
#
|
||||
# # record.move_line_ids.print_qr_code()
|
||||
#
|
||||
# print('record.move_line_ids.lot_id', record.move_line_ids.lot_id)
|
||||
# print('record.move_line_ids.lot_id.name', record.move_line_ids.lot_id.name)
|
||||
|
||||
|
||||
class SfProcurementGroup(models.Model):
|
||||
_inherit = 'procurement.group'
|
||||
@@ -815,7 +931,8 @@ class SfStockScrap(models.Model):
|
||||
|
||||
|
||||
class CustomStockMove(models.Model):
|
||||
_inherit = 'stock.move'
|
||||
_name = 'stock.move'
|
||||
_inherit = ['stock.move', 'printing.utils']
|
||||
|
||||
def action_assign_serial_show_details(self):
|
||||
# 首先执行原有逻辑
|
||||
@@ -844,3 +961,31 @@ class CustomStockMove(models.Model):
|
||||
binary_data = buffer.getvalue()
|
||||
data = base64.b64encode(binary_data).decode() # 确保返回的是字符串形式的数据
|
||||
return data
|
||||
|
||||
def print_all_barcode(self):
|
||||
"""
|
||||
打印所有编码
|
||||
"""
|
||||
print('================')
|
||||
for record in self.move_line_ids:
|
||||
print('record', record)
|
||||
if not record.lot_name:
|
||||
continue
|
||||
record.ensure_one()
|
||||
# qr_code_data = record.lot_qr_code
|
||||
# if not qr_code_data:
|
||||
# raise UserError("没有找到二维码数据。")
|
||||
lot_name = record.lot_name
|
||||
# todo 待控制
|
||||
if not lot_name:
|
||||
raise ValidationError("请先分配序列号")
|
||||
# host = "192.168.50.110" # 可以根据实际情况修改
|
||||
# port = 9100 # 可以根据实际情况修改
|
||||
|
||||
# 获取默认打印机配置
|
||||
printer_config = self.env['printer.configuration'].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
|
||||
record.print_qr_code(lot_name, host, port)
|
||||
|
||||
@@ -65,7 +65,7 @@
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='product_uom_id']" position="after">
|
||||
<field name="lot_qr_code" widget="image"/>
|
||||
<button name="print_qr_code" string="打印编码" type="object" class="oe_highlight"/>
|
||||
<button name="print_single_method" string="打印编码" type="object" class="oe_highlight"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
@@ -103,6 +103,11 @@
|
||||
groups="sf_warehouse.group_sf_stock_user" data-hotkey="k"/>
|
||||
</xpath>
|
||||
|
||||
<!-- <xpath expr="//form//sheet//notebook//page//field[@name='move_ids_without_package']" position="before"> -->
|
||||
<!-- <field name="check_in" invisible="True"/> -->
|
||||
<!-- <button name="print_all_barcode" string="打印所有编码" type="object" attrs="{'invisible': [('check_in', '!=', 'IN')]}"/> -->
|
||||
<!-- </xpath> -->
|
||||
|
||||
</field>
|
||||
</record>
|
||||
|
||||
@@ -135,5 +140,19 @@
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="sf_view_stock_move_operations" model="ir.ui.view">
|
||||
<field name="name">sf.stock.move.operations.form</field>
|
||||
<field name="model">stock.move</field>
|
||||
<field name="inherit_id" ref="stock.view_stock_move_operations"/>
|
||||
<field name="arch" type="xml">
|
||||
<!-- <xpath expr="//form//field[@name='move_line_ids']" position="before"> -->
|
||||
<!-- <button name="print_all_barcode" type="object" string="打印所有编码"/> -->
|
||||
<!-- </xpath> -->
|
||||
<xpath expr="//form//field[@name='product_id']" position="before">
|
||||
<button name="print_all_barcode" type="object" string="打印所有编码" class="oe_highlight"/> -->
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</odoo>
|
||||
|
||||
Reference in New Issue
Block a user