I create a new model and override its write method, but when I create a new user, my override write is called.
Why happend that?
My class:
class Movimiento(models.Model):
_name = 'gestion_autos.movimiento'
name = fields.Char(string='Nombre')
product_id = fields.Many2one('product.template', string='Producto', required=True)
fecha = fields.Date(string='Fecha', default=fields.Date.today)
price_unit = fields.Float(string='Precio por unidad', required=True, default='1.0')
amount = fields.Float(string='Cantidad', required=True, default='1.0')
price_total = fields.Float(compute='_compute_price_total', string='Precio total',
store=True)
taxi_id = fields.Many2one('gestion_autos.taxi', string='Taxi',
required=True)
credito = fields.Boolean(default=False, string='Credito')
@api.depends('price_unit', 'amount')
def _compute_price_total(self):
for record in self:
if record.price_unit < 0.0:
record.price_unit = 0.0
if record.amount < 0.0:
record.amount = 0.0
record.price_total = record.price_unit * record.amount
class Gasto(Movimiento):
_name = 'gestion_autos.gasto'
partner_id = fields.Many2one('res.partner', string="Proveedor", required=True)
pago_ids = fields.One2many('gestion_autos.pagogasto', 'gasto_id', string="Pago")
@api.onchange('product_id')
def _onchange_product_id(self):
self.price_unit = self.product_id.standard_price
@api.model
def create(self, vals):
_logger.error("gasto - create - self : %r", self)
_logger.error("gasto - create - vals : %r", vals)
gasto_id = super(Gasto, self).create(vals)
if vals.get('credito') == False:
gasto_id.update_pay()
return gasto_id
@api.multi
def write(self, vals):
_logger.error("gasto - write - self : %r", self)
_logger.error("gasto - write - vals : %r", vals)
res = super(Gasto, self).write(vals)
if not res:
return res
pagos = self.env['gestion_autos.pagogasto'].search([('gasto_id.id', 'in', self.ids)])
pagos.unlink()
if vals.get('credito') == False:
self.update_pay()
return True
@api.one
def update_pay(self):
pagogasto_obj = self.env['gestion_autos.pagogasto']
res = pagogasto_obj.create({
'fecha':self.fecha,
'price':self.price_total,
'partner_id':self.partner_id.id,
'gasto_id':self.id,
'referencia':"Fac - %s - %s" % (self.fecha, self.partner_id.name)
})
return True
Output when create a new user:
2015-04-03 23:19:13,210 18132 ERROR newdb openerp.addons.gestion_autos.models.contabilidad: gasto - write - self : gestion_autos.gasto()
2015-04-03 23:19:13,210 18132 ERROR newdb openerp.addons.gestion_autos.models.contabilidad: gasto - write - vals : {'partner_id': 6}
2015-04-03 23:19:13,212 18132 ERROR newdb openerp.addons.gestion_autos.models.contabilidad: gasto - write - self : gestion_autos.gasto()
2015-04-03 23:19:13,212 18132 ERROR newdb openerp.addons.gestion_autos.models.contabilidad: gasto - write - vals : {'partner_id': False}
Please some explanation to that