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']