From c898e02860bd358ecd2f00a7da7df6b9ed66e56e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=B0=A7?= Date: Wed, 14 May 2025 17:02:04 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=88=B6=E9=80=A0?= =?UTF-8?q?=E7=94=B3=E8=AF=B7=E5=AD=97=E6=AE=B5=E6=9C=AA=E5=A4=8D=E5=88=B6?= =?UTF-8?q?=E5=88=B0=E6=88=90=E5=93=81=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jikimo_purchase_request/models/product_template.py | 6 +++++- .../models/product_template.py | 4 ++++ sf_manufacturing/models/sale_order.py | 6 +++--- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/jikimo_purchase_request/models/product_template.py b/jikimo_purchase_request/models/product_template.py index 623c0981..c4f2a589 100644 --- a/jikimo_purchase_request/models/product_template.py +++ b/jikimo_purchase_request/models/product_template.py @@ -13,7 +13,11 @@ class ProductTemplate(models.Model): template_id.purchase_request = product_id.purchase_request return template_id + +class ProdcutProduct(models.Model): + _inherit = 'product.product' + def copy_template(self, product_template_id): """ 复制成品模板时,复制采购申请 """ - super(ProductTemplate, self).copy_template(product_template_id) + super(ProdcutProduct, self).copy_template(product_template_id) self.purchase_request = product_template_id.purchase_request diff --git a/jikimo_sale_multiple_supply_methods/models/product_template.py b/jikimo_sale_multiple_supply_methods/models/product_template.py index cd730998..85190cab 100644 --- a/jikimo_sale_multiple_supply_methods/models/product_template.py +++ b/jikimo_sale_multiple_supply_methods/models/product_template.py @@ -6,6 +6,10 @@ class ProductTemplate(models.Model): is_manual_processing = fields.Boolean(string='人工线下加工') is_customer_provided = fields.Boolean(string='客供料') + +class ProductProduct(models.Model): + _inherit = 'product.product' + def copy_template(self, product_template_id): if not isinstance(product_template_id, ProductTemplate): raise ValueError('%s必须是ProductTemplate类型' % product_template_id) diff --git a/sf_manufacturing/models/sale_order.py b/sf_manufacturing/models/sale_order.py index bec19018..8251a78d 100644 --- a/sf_manufacturing/models/sale_order.py +++ b/sf_manufacturing/models/sale_order.py @@ -56,10 +56,10 @@ class SaleOrder(models.Model): 'jikimo_sale_multiple_supply_methods.product_template_manual_processing').sudo() # 复制成品模板上的属性 - line.product_id.product_tmpl_id.copy_template(product_template_id) + line.product_id.copy_template(product_template_id) # 将模板上的single_manufacturing属性复制到成品上 - line.product_id.single_manufacturing = product_template_id.single_manufacturing - line.product_id.tracking = product_template_id.tracking + # line.product_id.single_manufacturing = product_template_id.single_manufacturing + # line.product_id.tracking = product_template_id.tracking order_id = self product = line.product_id From f6d8cb6267366cc5e5bb36f6ac90e83c5c75fef6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=B0=A7?= Date: Thu, 15 May 2025 08:45:02 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E7=BC=96=E7=A8=8B=E5=8D=95=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E9=9B=B6=E4=BB=B6=E5=9B=BE=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_base/commons/common.py | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/sf_base/commons/common.py b/sf_base/commons/common.py index 2dbb4795..579125f0 100644 --- a/sf_base/commons/common.py +++ b/sf_base/commons/common.py @@ -103,12 +103,19 @@ class PrintingUtils(models.AbstractModel): self.send_to_printer(host, port, zpl_code) - def add_qr_code_to_pdf(self, pdf_path:str, content:str, buttom_text:Optional[str]=False): + def add_qr_code_to_pdf( + self, + pdf_path:str, + content:str, + qr_code_buttom_text:Optional[str]=False, + buttom_text:Optional[str]=False, + ): """ 在PDF文件中添加二维码 :param pdf_path: PDF文件路径 :param content: 二维码内容 - :param buttom_text: 二维码下方文字 + :param qr_code_buttom_text: 二维码下方文字 + :param buttom_text: 正文下方文字 :return: 是否成功 """ if not os.path.exists(pdf_path): @@ -156,8 +163,9 @@ class PrintingUtils(models.AbstractModel): existing_pdf = PdfFileReader(original_file) output = PdfFileWriter() - # 处理第一页 - page = existing_pdf.getPage(0) + # 处理最后一页 + last_page = existing_pdf.getNumPages() - 1 + page = existing_pdf.getPage(last_page) # 获取页面尺寸 page_width = float(page.mediaBox.getWidth()) page_height = float(page.mediaBox.getHeight()) @@ -179,13 +187,21 @@ class PrintingUtils(models.AbstractModel): qr_y = margin + 20 # 将二维码向上移动一点,为文字留出空间 c.drawImage(qr_temp_path, page_width - qr_size - margin, qr_y, width=qr_size, height=qr_size) - if buttom_text: + if qr_code_buttom_text: # 在二维码下方绘制文字 - text = buttom_text + text = qr_code_buttom_text text_width = c.stringWidth(text, "SimSun" if font_found else "Helvetica", 10) # 准确计算文字宽度 text_x = page_width - qr_size - margin + (qr_size - text_width) / 2 # 文字居中对齐 text_y = margin + 20 # 文字位置靠近底部 c.drawString(text_x, text_y, text) + + if buttom_text: + # 在下方中间添加文字 + text = button_text + text_width = c.stringWidth(text, "SimSun" if font_found else "Helvetica", 10) # 准确计算文字宽度 + text_x = (page_width - text_width) / 2 # 文字居中对齐 + text_y = margin + 20 # 文字位置靠近底部 + c.drawString(text_x, text_y, text) c.save() @@ -196,11 +212,12 @@ class PrintingUtils(models.AbstractModel): # 合并原始页面和二维码页面 page.mergePage(qr_page) - output.addPage(page) # 添加剩余的页面 - for i in range(1, existing_pdf.getNumPages()): + for i in range(0, last_page): output.addPage(existing_pdf.getPage(i)) + + output.addPage(page) # 保存最终的PDF到一个临时文件 final_temp_path = pdf_path + '.tmp'