Hey so I've tried the following code :
# Free unit
@api.onchange('free_unit')
def onchange_free_unit(self):
if self.free_unit > 0:
# looking for the id
search_ids = self.env['purchase.order'].search([])
last_id = search_ids and max(search_ids)
print last_id.id + 1
print self._origin.order_id.id
# check if the order line is saved
if last_id.id == self._origin.order_id.id:
print 'same !!!! \n'
new_line = {
'order_id': self._origin.order_id.id,
'product_id': self.product_id.id,
'name': self.name,
'product_qty': self.product_qty,
'date_planned': self.date_planned,
'date_ok': self.date_ok,
'product_uom': 1,
'price_unit': self.price_unit,
'taxes_id': self.taxes_id,
'cascade_bool': True,
}
print "new_line", new_line
self.create(new_line)
if not self._origin.order_id.id:
print 'not same !!! \n'
new_line = {
'order_id': last_id.id + 1,
'product_id': self.product_id.id,
'name': self.name,
'product_qty': self.product_qty,
'date_planned': self.date_planned,
'date_ok': self.date_ok,
'product_uom': 1,
'price_unit': self.price_unit,
'taxes_id': self.taxes_id,
'cascade_bool': True,
}
print "new_line", new_line
self.create(new_line)
So I'm trying to retreive the order_id to put it in the object. But it seems like it's impossible to do it in draft mode. I mean when the object is not saved.
I can do it when the object is saved and edit mode, but not in my purchase order before.
Any ideas ?? Or is it impossible ?
Thanks