Skip to Content
Menu
This question has been flagged
1 Reply
2015 Views
class SalesmanCommission(models.Model):
_name = 'salesman.commission'
_rec_name = 'partner_id'

@api.depends('commission_line.commission')
def _compute_commission(self):
for rec in self:
# return '250'
rec.update({'commission': sum(rec.commission_line.mapped('commission'))})
print self.commission

partner_id = fields.Many2one('res.users', string='SalesMan')
commission_line = fields.One2many('salesman.commission.line', 'line_id', 'Commission Line')
commission = fields.Monetary(compute='_compute_commission', string='Commission', readonly=True)
currency_id = fields.Many2one('res.currency', default=lambda self: self.env.user.company_id.currency_id.id)



class SalesmancommissionLine(models.Model):
_name = 'salesman.commission.line'

order_id = fields.Many2one('sale.order', 'Order')
commission = fields.Monetary('Commission')
currency_id = fields.Many2one('res.currency', default=lambda self: self.env.user.company_id.currency_id.id)
date = fields.Date('Date')
line_id = fields.Many2one('salesman.commission', string='Line Id')


<record model="ir.ui.view" id="view_salesman_commission_pivot">
<field name="name">salesman.commission.pivot</field>
<field name="model">salesman.commission</field>
<field name="arch" type="xml">
<pivot string="Salesman Commission Line">
<field name="commission" type="measure"/>
</pivot>
</field>

</record> 


while in sale module amount_total  is also compute but it is working in pivot 

can anyone help, thanks.


Avatar
Discard
Best Answer

Hi,

Use store=True attribute in commission,

commission = fields.Monetary(compute='_compute_commission', store=True, string='Commission', readonly=True)

Thanks

Avatar
Discard
Author

by using store it has stuck to 100 because previously I passed 100 as default just to check whether it is because of compute or not.. it is working fine on default but not in compute

Related Posts Replies Views Activity
1
Jul 24
24
2
Mar 24
486
2
Aug 23
987
0
Mar 20
981
1
Dec 19
3596