Odoo Help

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

--Damien Bouvy (dbo)--
2000
| 1 0 1
Grand-Rosière, Belgium
--Damien Bouvy (dbo)--

Damien is a core developer part of Odoo's R&D department. He has developed numerous features on Odoo, including: the subscription application, the billing processes of Odoo Online, refactoring of quotation templates, payment acquirers, etc.

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?

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