Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Artificial Intelligence
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Property Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

How to enable a Button.

Subscribe

Get notified when there's activity on this post

This question has been flagged
buttons
1 Reply
6166 Views
Avatar
Kapil More


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>

1
Avatar
Discard
Avatar
DAJ MI 5, Bole
Best Answer

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).

0
Avatar
Discard
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
Custom stat button (eo_stat_button) for a custom field on a partner
buttons
Avatar
Avatar
Avatar
2
Mar 23
12312
Cacher le bouton "créer" d'une liste Solved
buttons
Avatar
Avatar
2
Mar 23
4165
Add class to button from function Solved
buttons
Avatar
Avatar
2
May 22
6605
Bind object btn to model_id action btn?
buttons
Avatar
0
Mar 22
3002
PLEASE HELP - Odoo 12 - How do you replace Create button when you inherit Product.Template
buttons
Avatar
Avatar
1
May 21
5926
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk Slovenščina Español (América Latina) Español Svenska ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now