Odoo 13 POS关闭会话触发SQL非空约束错误求助
Odoo 13关闭POS会话时account.payment必填字段错误解决方法
关闭Odoo 13的POS会话时,提示Payments(account.payment)模型的Payment Method(payment_method_id)字段为必填项,日志报错内容如下:
2023-05-16 14:11:39,382 1484292 ERROR Gofresh_Live odoo.sql_db: bad query: INSERT INTO "account_payment" ("id", "create_uid", "create_date", "write_uid", "write_date", "amount", "communication", "currency_id", "journal_id", "move_name", "name", "partner_id", "partner_type", "payment_date", "payment_difference_handling", "payment_method_id", "payment_type", "state", "writeoff_label") VALUES (nextval('account_payment_id_seq'), 2, (now() at time zone 'UTC'), 2, (now() at time zone 'UTC'), '2.300', 'POS/06001', 96, 7, NULL, 'POS/06001', NULL, 'supplier', '2023-05-16', 'open', NULL, 'outbound', 'reconciled', 'Write-Off') RETURNING id ERROR: null value in column "payment_method_id" violates not-null constraint DETAIL: Failing row contains (3325, POS/06001, null, null, null, reconciled, outbound, null, supplier, null, 2.300, 96, 2023-05-16, POS/06001, 7, open, null, Write-Off, null, null, 2, 2023-05-16 14:11:35.362199, 2, 2023-05-16 14:11:35.362199, null, null). 2023-05-16 14:11:39,386 1484292 WARNING Gofresh_Live odoo.http: ('The operation cannot be completed:\n- Create/update: a mandatory field is not set.\n- Delete: another model requires the record being deleted. If possible, archive it instead.\n\nModel: Payments (account.payment), Field: Payment Method (payment_method_id)', None)
解决步骤
检查POS对应日记账的支付方式配置
进入会计 > 配置 > 银行日记账,找到日志中journal_id=7对应的日记账,切换到支付方式选项卡,确认已关联有效的支付方法,且设置了默认支付方式。若缺失,添加对应支付方式并保存。验证account.payment字段约束
若使用了自定义模块,检查模块代码是否将payment_method_id强制设为必填,如有需要调整逻辑;若为原生Odoo问题,升级到Odoo 13.0的最新补丁版本,修复已知的字段约束bug。手动修复异常支付记录
- 进入
销售 > POS > 会话,定位无法关闭的目标会话,查看关联订单与支付记录。 - 开启开发者模式,进入
会计 > 支付,查找日志中id=3325的支付记录(若未创建成功,可通过数据库直接插入或修改),手动设置payment_method_id为合适的支付方式ID(可从日记账关联的支付方式中选取)。 - 重新尝试关闭POS会话。
- 进入
检查POS配置的支付方式
进入销售 > 配置 > POS,打开对应POS配置的支付方式选项卡,确保所有启用的支付方式都正确关联到日记账,无配置缺失。
内容的提问来源于stack exchange,提问作者Hassan Yousuf
相关产品推荐
相关产品推荐

