Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Registering entries in a one2many field.

By
Arjun Khode
on 3/22/15, 7:45 AM 412 views

Hi,I am making an investor module.  I have defined a one2many relationship between two fields:record_id and account_ids.

I actually use 2 buttons to register payments through account_voucher.view_vendor_receipt_form. Buttons are called 'receive investment and return investment'

Now, every time I make a payment entry, I want it to show in my account_ids one2many field list. account_ids is a list of payment entries made to a investment record. Currently, the entries fall in journal entries, but I want them to fall in account_ids too so that each 'record' (this is not the same as XML record, its just a python class) gets multiple payment entries in it. Currently my module shows a blank list of account_ids even after registering a payment through that record. It needs to show the entry in the list. Can someone help me out with this?

Here is my code

PYTHON:

class record(orm.Model):

_name="record"

_columns={

'investment_id':fields.many2one('investment.model','Name of Investment'),

'investor_id':fields.many2one('res.partner','Investor Name'),

'start_date':fields.date('Start Date'),

#'end_date':fields.date('End Date'),

'amount':fields.float('Amount Invested'),

'account_ids':fields.one2many('account.move','record_id',string="Payments"),

#'status_paid':fields.boolean('Total Amount Paid'),

#'status_returned':fields.boolean('Total Amount Returned'),

'done':fields.boolean('Mark As Done',invisible=True),

'roi':fields.float('Rate of Interest in fraction'),

'monthly_interest':fields.float('Cumulative Monthly Interest'),

'returns':fields.function(_amount_returns, digits_compute=dp.get_precision('Account'), string='Amount to be returned',

store={

'record': (lambda self, cr, uid, ids, c={}: ids, ['amount', 'roi'], 10),

},),


class account_move(osv.Model):

_inherit="account.move"

_columns={

'record_id':fields.many2one('record','Record'),

}

BUTTONS CODE:


<record id="register_payment_button_action" model="ir.actions.act_window">

<field name="name">Register Payment</field>

<field name="res_model">account.voucher</field>

<field name="view_type">form</field>

<field name="view_mode">form</field>

<field name="domain">[('journal_id.type', 'in', ['bank', 'cash']), ('type','=','receipt')]</field>

<field name="context">{'type':'receipt'}</field>

<field name="view_id" ref="account_voucher.view_vendor_receipt_form"/>

<!-- <field name="view_id" ref="account_voucher.view_vendor_receipt_dialog_form"/> -->

<field name="target">new</field>

</record>

<record id="pay_investor_button_action" model="ir.actions.act_window">

<field name="name">Pay Investor</field>

<field name="res_model">account.voucher</field>

<field name="view_type">form</field>

<field name="view_mode">form</field>

<field name="domain">[('journal_id.type', 'out', ['bank', 'cash']), ('type','=','receipt')]</field>

<field name="context">{'type':'receipt'}</field>

<field name="view_id" ref="account_voucher.view_vendor_receipt_form"/>

<field name="target">new</field>

</record>

<record id="record_form_view" model="ir.ui.view">

<field name="name">record.form.view</field>

<field name="view_type">form</field>

<field name="model">record</field>

<field name="arch" type="xml">

<form string="Record">

<group>

<field name="investment_id" colspan="1" />

<field name="investor_id" domain="[('is_investor','=',True)]"/>

<field name="start_date"/>

<!-- <field name="end_date"/> -->

<field name="roi"/>

<field name="amount"/>

<field name="returns"/>

<field name="account_ids"/>

<!-- <button name="action_compute_returns" string="Compute Returns" type="object"/> -->

<button name="%(register_payment_button_action)d" context="{'default_amount': amount,'default_partner_id': investor_id,'default_reference':investment_id}" string="Receive Investment" col="1" type="action"/>

<button name="%(pay_investor_button_action)d" context="{'default_amount': (returns * -1),'default_partner_id': investor_id'}" string="Return Investment" col="2" type="action"/>

<button name="mark_as_done" string="Mark as Done" col="3" type="object"/>

</group>

</form>

</field>

</record>

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 3/22/15, 7:45 AM
Seen: 412 times
Last updated: 3/22/15, 7:49 AM