You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Odoo POS:如何更换验证后自动下载的PDF发票模板

更换Odoo POS验证后自动下载的PDF发票模板

方法一:系统配置直接修改(部分Odoo版本支持)

  • 进入销售 > 点单 > POS配置,打开当前使用的POS配置项
  • 查看是否存在发票模板字段,直接选择已安装的目标模板,保存后即可生效

方法二:自定义模块适配(通用方案)

如果系统无配置选项,需通过自定义模块修改逻辑:

1. 后台Python代码重写

创建自定义模块,在模型中覆盖POS订单验证时的发票生成方法,指定目标模板:

from odoo import models, api

class PosOrder(models.Model):
    _inherit = 'pos.order'

    def action_pos_order_invoice(self):
        res = super().action_pos_order_invoice()
        # 替换为你的目标模板外部ID,格式为"模块名.模板XML ID"
        target_template = self.env.ref('your_module.your_report_template')
        if res.get('report_type') == 'qweb-pdf':
            res['report_id'] = target_template.id
        return res

2. 前端JS逻辑调整(针对前端触发下载场景)

若POS在前端直接启动发票下载,需修改POS的JS代码:

odoo.define('your_module.pos_custom_invoice', function(require) {
    "use strict";

    var models = require('point_of_sale.models');
    var _super_order = models.Order.prototype;

    models.Order = models.Order.extend({
        finalize_validation: function() {
            _super_order.finalize_validation.apply(this, arguments);
            // 仅当POS配置允许发票时生效
            if (this.pos.config.iface_invoice && this.invoice) {
                // 替换为目标模板的实际ID
                const template_id = 123;
                this.pos.chrome.do_action('account.account_invoices', {
                    additional_context: {
                        active_ids: [this.invoice.id],
                        report_id: template_id,
                    },
                });
            }
        },
    });
});

3. 模块部署

  • 在模块的__manifest__.py中添加依赖:'depends': ['point_of_sale', 'account']
  • 安装该自定义模块,重启Odoo服务后生效

注意事项

  • 确保目标PDF模板已正确关联account.move(发票)模型,且模板语法无错误
  • 修改代码前建议在测试环境验证,或备份系统数据

内容的提问来源于stack exchange,提问作者Hassan Yousuf

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.07 23:55:17