Odoo Help

1

How to enable a Button.

By
Kapil More
on 4/15/15, 3:04 AM 666 views


Hi,

I am creating one of the module for Investor inside of Builder's ERP and the problem occured while creating the buttons in my Odoo8. Buttons are created but they are disabled; doesn't shows any functionality.

Here is my code,

investor.py

class investor_record(orm.Model):

_name="invest.record"

def button_monthly_interest(self, cr, uid, ids, context=None):

print("Hello Function Started !")

context = context or {}

res = {}

''''''

print("Function Name- Monthly Interest Button-")

for value in self.browse(cr, uid, ids, context=context):

print("For Loop Starts !")

result1 = relativedelta.relativedelta(datetime.today(),datetime.strptime(value.start_date,"%Y-%m-%d"))

print("Monthly Interest")

value.return_amount=((value.roi or 0.0)*(result1.month or 1)*value.amount)

print(value.return_amount)

print("Months")

print(result1.months)

value.returns = (value.amount or 0.0) * (1 + (value.roi or 0.0)*(result1.months or 1))

value.return_amount=value.returns

print("Amount to be Returned!")

print(value.returns)

print(value.return_amount)

return res

def _amount_returns(self, cr, uid, ids, field, arg, context=None):

print("Function for Amount Returns !")

context = context or {}

res = {}

''''''

def monthdelta(d1, d2):

print("Function for Month delta !")

delta = 0

while True:

mdays = monthrange(d1.year, d1.month)[1]

d1 += timedelta(days=mdays)

if d1 <= d2:

delta += 1

else:

break

return delta

for cal in self.browse(self, uid, ids, context=context):

print("For loop for Calculation !")

result2 = relativedelta.relativedelta(datetime.today(),datetime.strptime(cal.start_date,"%Y-%m-%d"))

print("Monthly Interest (Return Amount)!")

cal.return_amount=((cal.roi or 0.0)*(result2.months or 1)*cal.amount)

print(cal.return_amount)

res[cal.id] = (cal.amount or 0.0) * (1 + (cal.roi or 0.0)*(result2.months or 1))

print("Months")

print(cal.months)

return res

_columns={

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

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

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

'balance':fields.float("Balance"),

'roi':fields.float("Rate of Interest In Fraction"),

'months':fields.float("Months"),

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

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

'return_amount':fields.float("Returned Amount"),

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

'voucher_id':fields.many2one('account.voucher','Voucher'),

'amt':fields.float(compute='_get_voucher_amount',string="Voucher Amount"),

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

store={

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

},),

}

@api.one

@api.depends('voucher_id.amount')

def _get_voucher_amount(self):

print("Vouchers for Amount!")

self.amt=self.voucher_id.amount

class res_partner(osv.Model):

_inherit="res.partner"

_columns={

'is_investor':fields.boolean('Is an Investor'),

'investment_ids':fields.one2many('invest.record','investor_id',string="Investment Records"),

}

class investment_model(osv.Model):

_name="investment.model"

_columns={

'name':fields.char('Name of Investment',size=64),

'investor_ids':fields.one2many('invest.record','investment_id',string="Investor Records"),

}

class account_move(osv.Model):

_inherit="account.move"

_columns={

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

}

----------------------------------------------------------------------------------------------------------------------------------

investor_view.xml

<openerp>

<data>

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

<field name="res_model">res.partner</field>

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

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

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

<!-- <field name="context">{'search_default_investor':1}</field> -->

</record>

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

<field name="res_model">investment.model</field>

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

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

<field name="name">Investment</field>

</record>

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

<field name="model">res.partner</field>

<field name="inherit_id" ref="base.view_partner_form"/>

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

<field name="website" position="after">

<field name="is_investor"/>

</field>

<page name="sales_purchases" position="after" >

<page name="investments" string="Investments">

<field name="investment_ids" />

</page>

</page>

</field>

</record>

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

<field name="model">res.partner</field>

<field name="inherit_id" ref="base.view_partner_tree"/>

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

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

<field name="email" position="after">

<field name="is_investor"/>

</field>

</field>

</record>

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

<field name="model">res.partner</field>

<field name="inherit_id" ref="base.view_res_partner_filter"/>

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

<filter string="Salesperson" position="after">

<filter string="Investor" name="investor" domain="[('is_investor', '=', True)]"/>

</filter>

</field>

</record>

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

<field name="name">Payments</field>

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

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

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

<field name="domain">[('ref','=',context.get('ref'))]</field>

<field name="view_id" ref="account.view_move_tree"/>

<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="vew_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="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','out',['bank','cash']), ('type','=','receipt')]</field>

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

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

<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">invest.record</field>

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

<form string="Record">

<group>

<field name="investor_id" />

<field name="investment_id" />

<field name="start_date" />

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

<field name="amount" />

<field name="roi" />

<field name="return_amount" />

<button name="%(payment_action)d" context="{'ref':investment_id}" domain="[]" string="View Payments" col="2" type="action"/>

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

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

</group>

</form>

</field>

</record>

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

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

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

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

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

<tree string="Records">

<button name="button_monthly_interest" string="Monthly Interest" type="object"/>

<field name="investor_id" />

<field name="investment_id" />

<field name="start_date" />

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

<field name="amount" />

<field name="roi" />

<field name="return_amount" />

</tree>

</field>

</record>

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

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

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

<field name="model">investment.model</field>

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

<form string="Investment">

<group>

<field name="name"/>

<field name="investor_ids"/>

</group>

</form>

</field>

</record>

<menuitem id="investor_menu" name="Investors"/>

<menuitem id="investor_submenu" name="Investor" parent="investor_menu" />

<menuitem id="investor_leaf" name="Investors" parent="investor_submenu" action="investor_action"/>

<menuitem id="investment_submenu" name="Investment" parent="investor_menu" />

<menuitem id="investment_leaf" name="Investments" parent="investment_submenu" action="investment_action" />

</data>

</openerp>

0

Bole

--Bole--
2425
| 5 4 6
Zagreb | Karlovac, Croatia
--Bole--

there is only 10 kind of people the ones that understand binary ... and others

Bole
On 4/15/15, 9:34 AM

ur buttons are of type=action, so if you want it to do something, you should declare specific action in xml file,Othervise, if you want them to triger a class method they should be of type="object", and name="name_of_class_method" . if you dont specify type in button declaration then button is workflow trigger (and it should exist in workflow with same naem as button name).

About This Community

This platform 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.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 4/15/15, 3:04 AM
Seen: 666 times
Last updated: 5/15/15, 2:03 AM