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
    • Approvals
    • 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
    • Estate 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

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
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

smart button v10

Subscribe

Get notified when there's activity on this post

This question has been flagged
viewssearchbuttons
2 Replies
8590 Views
Avatar
Dominic Anyanna

hello 

am developing a module that manages members of an association and their loans . and i wanted to create a smart button that shows all loans linked to a member . i have created the button but when i click on it it does not show a list of the loans . would appreciate any guidance i can get .


members model 




from odoo import models, fields, api

class ranchy_members(models.Model):
_name = 'members.ranchy'
_rec_name = 'member_firstname'

member_id = fields.Id
member_firstname = fields.Char(string="Name")
member_lastname = fields.Char(string="Name of father/husband")
member_addresss = fields.Char(string="Residential Address")
add_permanent = fields.Char(string="Pemanent Address")
business_addresss = fields.Char(string="Business Address")
member_phone = fields.Char(string="phone number")
member_pic = fields.Binary("image", help="select image here")
member_age = fields.Char(string="Age")
marital_status = fields.Selection(
[('Single','Single'), ('married','married'),('divorced','Divorced'),('widow','widow')],
'Marital status')
education = fields.Selection(
[('none','None'), ('primary','Primary'),('secondary','Secondary'),('tertiary','Tertiary')],
'Formal Education')
next_kin = fields.Char(string="Next of Kin Name")
kin_phone = fields.Char(string="Next of Kin Phone")
memberof = fields.Many2one('corps.ranchy',string="name of group")
business_type = fields.Char(string="Type of Business")
business_period = fields.Char(string="How long in business")
average_income = fields.Char(string="Average monthly income")
loan_ids = fields.One2many('ranchy.loans', 'member_ids', string='Loans')
loan_id = fields.Many2one('ranchy.loans', compute='_compute_loan_id', string='Current Loan', help='Latest loan of member')
loan_count = fields.Integer(compute='_compute_loan_count', string='Loans')

def _compute_loan_id(self):
""" get the lastest loan """
Loan = self.env['ranchy.loans']
for member in self:
member.loan_id = Loan.search([('member_ids', '=', member.id)], order='date_start desc', limit=1)

def _compute_loan_count(self):
# read_group as sudo, since contract count is displayed on form view
loan_data = self.env['ranchy.loans'].sudo().read_group([('member_ids', 'in', self.ids)], ['member_ids'], ['member_ids'])
result = dict((data['member_ids'][0], data['member_ids_count']) for data in loan_data)
for member in self:
member.loan_count = result.get(member.id, 0)
loans model

class ranchy_loans(models.Model):
_name = 'ranchy.loans'
_inherit = ['mail.thread', 'ir.needaction_mixin']

state = fields.Selection([
('new', 'New Apllication'),
('awaiting', 'awaiting approval'),
('approve', 'awaiting disbursement'),
('disburse', 'disbursed/repayment'),
('paid', 'paid'),
],track_visibility='onchange',default='new')
#This function is triggered when the user clicks on the button 'Set to concept'
@api.one
def concept_progressbar(self):
self.write({
'state': 'awaiting',
})
#This function is triggered when the user clicks on the button 'Set to started'
@api.one
def approved_progressbar(self):
self.write({
'state': 'approve'
})
#This function is triggered when the user clicks on the button 'In progress'
@api.one
def disburse_progressbar(self):
self.write({
'state': 'disburse'
})
#This function is triggered when the user clicks on the button 'Done'
@api.one
def paid_progressbar(self):
self.write({
'state': 'paid',
})
loan_id = fields.Id
currency_id = fields.Many2one(
'res.currency', string='Currency')
total_repayments = fields.Monetary(
'Total Repayments',
# optional: currency_field='currency_id',
)
amount_disburse = fields.Monetary(
'Amount',
# optional: currency_field='currency_id',
)
amount_applied = fields.Monetary(
'Amount applied for',
# optional: currency_field='currency_id',
)
amount_approved = fields.Monetary(
'Amount approved',
# optional: currency_field='currency_id',
)
amount_balance = fields.Monetary(
'Balance',
# optional: currency_field='currency_id',
)
last_loan = fields.Monetary(
'last loan recieved amount',
# optional: currency_field='currency_id',
)
date_payed = fields.Date('Date loan was fully paid')
date_disburse = fields.Date('Date')
member_ids = fields.Many2one(
'members.ranchy', string='Member',
# optional:
ondelete='restrict',
context={},
domain=[],
)
stage = fields.Selection(
[('1st','First'), ('2nd','Second'),('3rd','third')],
'Stage')
installments = fields.Selection(
[('23','23'), ('20','20'),('18','18')],
'number of installments')
date_firstinstall = fields.Date('Date of first installment')
date_finalinstall = fields.Date('Date of last installment')
any_family = fields.Boolean('Is any family member of yours registered with the group')
if_true = fields.Char('If true mention name')
or_reg = fields.Boolean('Or registered in any other group of ranchi empowerment centre')
indebted = fields.Boolean('Are you indebted to any otherMFB/MFI')
if_true2 = fields.Char('If true Name')
if_true3 = fields.Char('Outstanding Balance')
view
<?xml version="1.0"?>
<odoo>
<data>


<act_window id="ranchy.action_window" res_model="members.ranchy" name="ranchy" view_mode="tree,form"/>



<menuitem action="ranchy.action_window" name="ranchy" id="ranchy.menu_root" groups="base.group_user" sequence ="450"/>
<menuitem action="ranchy.action_window" name="Members" id="ranchy.members" parent="ranchy.menu_root" sequence="1"/>


<record id= "ranchy_members_template_form_view" model= "ir.ui.view">
<field name="priority" eval="15"/>
<field name="model">members.ranchy</field >
<field name="arch" type= "xml">


<form>
<sheet>
<button type="action" class="oe_right oe_stat_button"
icon="fa-pencil-square-o" align="right" name="%(action_all_loans)d" >
<field name="loan_count" widget="statinfo"/>
</button>
<group>
<field name="member_pic" widget='image' />
<field name="member_firstname"/>
<field name="member_lastname"/>
</group>
<notebook>
<page string="Contact Information">
<group>
<field name="member_addresss"/>
<field name="add_permanent"/>
<field name="business_addresss"/>
<field name="member_phone"/>
</group>
</page>
<page string="Member Data">
<group>
<field name="member_age"/>
<field name="marital_status"/>
<field name="education"/>
<field name="next_kin"/>
<field name="kin_phone"/>
</group>
</page>
<page string="union and Business Information">
<group>
<field name="memberof"/>
<field name="business_type"/>
<field name="business_period"/>
<field name="average_income"/>

</group>
</page>
</notebook>
</sheet>

</form>

</field>
</record>

<record model="ir.actions.act_window" id="action_all_loans">
<field name="name">All Loans</field>
<field name="model">ranchy.loans</field>
<field name="view_mode">tree,form,search</field>
<field name="context">{'search_default_member_ids': [active_id],'default_member_ids': active_id}</field>
<field name="domain">[('loan_ids', '=', active_id)]</field>
</record>


<record id="loans_all_members" model="ir.ui.view">
<field name="name">All Loans</field>

<field name="model">ranchy.loans</field>
<field name="arch" type="xml">
<tree string="Payments">


</tree>
</field>
</record>



<record id="action_all_members_form"
model="ir.actions.act_window.view">
<field name="act_window_id" ref="action_all_loans"/>
<field name="view_id" ref="loans_all_members" />
<field name="view_mode">tree</field>
<field name="sequence">10</field>
</record>
     
0
Avatar
Discard
Avatar
Annadurai
Best Answer

Hello,

use store = True in computed fields.

3
Avatar
Discard
Avatar
Bréndou Serge Eric
Best Answer

Hello! I think your problem is in the definition of your action 'action_to_all_loans': the domain is not correct it should be [('member_ids','=',active_id)] because according to your definition member_ids is the inverse field of the One2many relation.

And I think you dont need to add 'search_default_member_ids': [active_id]  in the context if you are already applying a domain on member_ids....




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
Open View from Button Solved
views buttons
Avatar
Avatar
Avatar
2
Dec 23
19166
Button click and get data from other thirdparty api
views buttons
Avatar
Avatar
1
Jul 17
5096
Search in subtree
views search
Avatar
Avatar
Avatar
3
Mar 15
4936
How to switch to a other view after clicking a button Solved
views buttons odoo8
Avatar
Avatar
3
Jun 21
10138
Text in custom filter condition select dropdown control V12
views search 12
Avatar
Avatar
2
Aug 20
4746
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 ภาษาไทย 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