Pular para o conteúdo
Menu
Esta pergunta foi sinalizada
2 Respostas
40648 Visualizações

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>
Avatar
Cancelar
Melhor resposta

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)

Avatar
Cancelar
Autor Melhor resposta
@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?
Avatar
Cancelar
Publicações relacionadas Respostas Visualizações Atividade
2
out. 23
5449
3
set. 23
2339
0
mai. 23
2433
1
mai. 23
1890
1
abr. 23
1686