Skip to Content
Menu
This question has been flagged
1 Reply
3059 Views

Hello,


Any ideas on how to copy a purchase order line ?

I'm trying firstly to create an object vals and using create method but always got following errors like :

[object with reference: Purchase Order - purchase.order]

I tried :

self.copy(default={'product_id': self.product_id})

but no effect too.


What I'm trying to do is when I pass a value in the colum free unit of a purchase order line, this line should duplicate and takes custom values that I set programmatically.

I use an onchange method on free_unit for this.

Avatar
Discard
Author Best Answer

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

Avatar
Discard
Related Posts Replies Views Activity
0
Apr 15
2603
0
Mar 24
279
0
Mar 24
224
0
Apr 21
1827
1
Mar 15
8311