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

How to count the total number of record and reflect the value it in a button-box.

By
Paramita
on 3/15/16, 1:21 PM 638 views

Here is my .py file

class Associateaccounts_respartner(models.Model):
 _inherit = 'res.partner'
@api.multi
 def associate_count():
 # I need to count how many associate account is there based on one particular contact

  associate_count = fields.Integer(compute="associate_count", string='# of Associate', store='true')
 associate_id = fields.One2many('sale.associateaccounts', 'associate_partner_id', string='Associate Accounts')
here is my .xml file
<openerp>    
<data>
<record id="count_associateaccounts_respartner" model="ir.ui.view">
<field name="inherit_id" ref="base.view_partner_form"/>
 <field name="model">res.partner</field>
 <field name="arch" type="xml">
<div name="button_box" position="inside">
 <button class="oe_stat_button" type="action" name="%(associateaccounts.associateaccounts_action)d" attrs="{'invisible': [('customer', '=', False)]}" icon="fa-star">
<field string="Associates" name="associate_count" widget="statinfo"/>
 </button>
</div>
</field>
</record>
</data>
</openerp>
1
Damien Bouvy (dbo)
On 3/16/16, 5:22 PM

Hello,

You can have a look at addons/sale_service/models/timesheet.py in Odoo 9.0 to have an example of counting fields & functions. Unless you want to do searches, group bys, etc. the store on the count field is not strictly necessary (but why not, if you ensure that all the dependencies of the computed field are ok).


BTW, usually one2many fields end with 's', so you can distinguish them more easily. For example, "associate_ids" in your case.


I guess your function should look something like:

@api.multi
def associate_account(self):
     for partner in self:
         partner.associate_count = len(partner.associate_ids)

0
Paramita
On 3/16/16, 5:48 PM
@api.multidef _associate_count(self): 
 for partner in self:
 partner.associate_count = self.env['sale.associateaccounts'].search_count([('partner_id', '=', partner.id)]) 

associate_count = fields.Integer(compute="_associate_count", string='# of Associate', store=True)

associate_id = fields.One2many('sale.associateaccounts', 'associate_partner_id', string='Associate Accounts')

Thanks for your help but it's not working for me.Instead of that I write down the above code but still no luck.Can anybody help?

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/15/16, 1:21 PM
Seen: 638 times
Last updated: 3/16/16, 5:48 PM