I'm new in Odoo and Phyton. I've just develop a module to extend CRM, adding products in opportunities.
I used function fields to calculate price vs. quantity on opportunities lines (products). Now I want to sumarize all lines and put on opportunity's planned_revenue field. But I don't know what to put in this FOR statment. This line rises an error: for line in x_crm_lead.crm_lead_line: "crm_lead.py", line 13, in _amount_all AttributeError: type object 'x_crm_lead' has no attribute 'crm_lead_line'
There is my two classes:
class x_crm_lead(osv.Model):
_name = 'crm.lead'
_description = 'CRM Lead Extended'
_inherit = 'crm.lead'
def _amount_all(self, cr, uid, ids, field_name, arg, context=None):
res = {}
for lead in self.browse(cr, uid, ids, context=context):
res[lead.id] = {}
val = 0.0
for line in x_crm_lead.crm_lead_line:
val += line.price_subtotal
res[line.id]= val
return res
_columns = {
'planned_revenue': fields.function(_amount_all,string='Receita Esperada',type='float',store=True),
'crm_lead_line': fields.one2many('crm.lead.line','crm_lead_id','Produto da Oportunidade')
}
class crm_lead_line(osv.Model):
_name = 'crm.lead.line'
_description = 'CRM Lead Line'
def _amount_line(self, cr, uid, ids, name, arg, context=None):
res = {}
for record in self.browse(cr, uid, ids, context):
res[record.id] = float(record.price_unit) * float(record.quantity)
return res
_columns = {
'crm_lead_id': fields.many2one('crm.lead','Oportunidade',ondelete='cascade'),
'product_id': fields.many2one('product.product','Produto'),
'description': fields.text('Descricao'),
'quantity': fields.float('Quantidade',digits=(12,2)),
'price_unit': fields.float('Preco Unitario',digits=(12,2)),
'price_subtotal': fields.function(_amount_line,string='Subtotal',type='float',store=True),
}
Thank you in advance!