Hello guys!
We are in Odoo 10. I have created a button on each sale order line. We want to duplicate the sale order line in the same sale order when the button is clicked. See image below, the new duplicate icon at the right.
I think that we have to retrieve all the values of the current clicked line and after create the new line.
My skills are too limited to achieve this kind of thing.
COuld you guide me just a little please?
This is not really what we want to achieve, but this would give me a great beginning to achieve the rest.
Our actual code (empty!!!)
def dup_line(self):
_logger.error("dup_line BEGIN")
_logger.error(" self :: %s", str(self))
return True
In image :
EDIT #1
I have now this code for my button :
@api.one
def dup_line(self):
self.copy()
But I get this error :
The operation cannot be completed, probably due to the following:
- deletion: you may be trying to delete a record while other records still reference it- creation/update: a mandatory field is not correctly set
[object with reference: order_id - order.id]
EDIT #2
It is clear that the problem is the order_id field.
With this code, I can easily see the self.order_id in the debug. But the copy() function doesn't include the order_id field.
@api.one
def dup_line(self):
logger.error(" self.order_id :: %s", str(self.order_id))
self.copy()