Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
40620 Widoki

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>
Awatar
Odrzuć
Najlepsza odpowiedź

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)

Awatar
Odrzuć
Autor Najlepsza odpowiedź
@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?
Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
2
paź 23
5438
3
wrz 23
2325
0
maj 23
2428
1
maj 23
1884
1
kwi 23
1678