Skip to Content
Menu
This question has been flagged
1 Reply
8616 Views

Hallo, I'm implementing Odoo for a business where they need to register payment automatically, given these values:

  • payment date = invoice date

  • paid amount = invoice total amount

  • payment type = bank

I tried with the following code, but it fails with an error 

ValueError: "" while evaluating action_register_payment() 

It's likely I'm missing something about creating the voucher, which is a part that actually I don't know.

Code

In the invoice view: added a button 

<button name="invoice_paid" states="open" string="Invoice paid" class="oe_highlight" groups="base.group_user" />

that calls a transition by its signal

<record id="open_to_paid" model="workflow.transition">
<field name="act_from" ref="account.act_open"/>
<field name="act_to" ref="account.act_paid"/>
<field name="signal">invoice_paid</field>
</record>

the action of the act_paid activity has been improved

<record id="account.act_paid" model="workflow.activity">
<field name="action">action_register_payment()
confirm_paid()</field>
</record>

 and finally the action_register_payment():

def action_register_payment(self):
for inv in self:
journal_pool = self.env['account.journal']
journal_id = journal_pool.search([('company_id','=',inv.company_id.id), ('code','=','BNK2')])[0].id
journal = journal_pool.browse(journal_id)
account_id = journal.default_debit_account_id.id
vals = {
'currency_id': inv.currency_id.id,
'partner_id': inv.partner_id.id,
'amount': inv.amount_total,
'reference': inv.name,
'name': inv.number,
'type': 'payment',
'date': inv.date_invoice,
'period_id': inv.period_id.id,
'journal_id': journal_id,
'account_id': account_id,
'writeoff_amount': 0.0,
'paid': True,
'narration': 'Automatically set to paid'
}
id = voucher_pool.create(vals)
voucher_id = voucher_pool.browse(id)
voucher_id.signal_workflow('proforma_voucher')
voucher_pool = self.env['account.voucher']

Avatar
Discard
Best Answer

Hi, 

The error seems to be coming form create method. Put an ipdb statement before 

id = voucher_pool.create(vals)

Could you paste the stack trace? 


Avatar
Discard
Author

I have installed Odoo via apt-get: do I need to launch it from terminal to get the trace of ipdb? If so, how can I launch Odoo manually?

Hi Raffaele, You need a manual start. I you can't then there is an alternative way to debug Print values thought logger.info(val) before voucher code create. Connect database through erppeek (pip install erppeek). $erppeek -d $voucher_obj = model('account.voucher') $voucher_obj.create(vals) Check the error message. Retry creating voucher until you get it right.

Related Posts Replies Views Activity
1
Dec 22
1014
0
Mar 15
2738
0
Mar 16
2887
0
Mar 15
3878
0
Mar 15
3016