使用python代码自动注册付款会引发错误

2024-09-23 20:27:41 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我用来登记付款的代码:

Payment1 = self.env['account.payment'].with_context(default_invoice_ids=[(4, SaleInvoice.id, False)])
payment = Payment1.create({
    'payment_date': SaleInvoice.date,
    'payment_method_id': 1,
    'payment_type': 'inbound',
    'partner_type': 'customer',
    'communication': SaleInvoice.name,
    'partner_id': SaleInvoice.partner_id.id,
    'amount': paymentAmount,
    'journal_id': default_journal_id.id,
    'company_id': SaleInvoice.company_id.id,
    'currency_id': self.env.company and self.env.company.currency_id and self.env.company.currency_id.id,
    'payment_difference_handling': 'reconcile',
    # 'writeoff_account_id': self.diff_income_account.id,
})
payment.post()

它抛出了一个错误

Error: Odoo Server Error

res = self._obj.execute(query, params)   ValueError: <class 'psycopg2.IntegrityError'>: "new row for relation "account_move_line" violates check constraint "account_move_line_check_accountable_required_fields"

DETAIL:  Failing row contains (32465, 7210, null, null, null, null, null, null, 20, null, null, null, 10, Write-Off, 1.000, null, 0.00, 1056.04, 0.00, null, 0.0, null, null, null, f, 2021-04-19, null, 414, null, null, null, 25, null, null, null, null, null, t, null, null, null, null, null, null, null, null, null, 2, 2021-04-21 05:55:09.266162, 2, 2021-04-21 05:55:09.266162, null, null, null, null, null, null).   " while evaluating   'model.paymentSync()'

Tags: selfenviddefaultpartnerdatetypeaccount
1条回答
网友
1楼 · 发布于 2024-09-23 20:27:41

我已经为这个错误找了4个小时了。因为同样的事情也发生在我身上。在这种情况下,当发票有未偿债务且需要结算时,它使用核销账户id字段 只需发送相关对象account.account的id即可

payment = Payment1.create({
   'writeoff_account_id': self.env['account.account'].browse("you id").id,
})

相关问题 更多 >