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

Hello All,

I have added a button(Re-new) for product type service in inventory module and invoice is already created for that service. Now i want to Re-new(button) this service for next 2 years. So, i want create duplicate sale order on that button with full of data. So, how can i use copy function for this button?

My Coding structure like below:

@api.one
def dup_line(self)
         self.copy()
<button name="dup_line" type="object" string="Re-New" class="oe_highlight"/>

Thanks in advance

Avatar
Discard
Best Answer

Hi,

self.copy is enough for taking a copy of the current record. On clicking the button a new record , which is duplicate of current record will be created.

Thanks

Avatar
Discard

If i want to open duplicate sale order on other other model, then what should i do?

I have customer id(sale order id) on that model.

Didn't understand, are you looking to take copy of the sale order from other model ?

Yes..!!!!!!

try something like this , self.env['model_name'].search([('id', '=', 5)]).copy()

Thanks @Niyas,

self.env['operation.process'].search([('id', '=',self.pro_customer_id)]).copy()

Then i getting :

ValueError: Expected singleton: operation.process()

try this, self.env['operation.process'].search([('id', '=',self.pro_customer_id)], limit=1).copy()

this will return only one record, for your case we are getting multiple results in search either you have to use ensure_one or iterate the record over the for loop

Hello @Niyas,

still getting this error

File "/opt/odoo10/odoo/odoo/models.py", line 4388, in copy

self.ensure_one()

File "/opt/odoo10/odoo/odoo/models.py", line 4822, in ensure_one

raise ValueError("Expected singleton: %s" % self)

ValueError: Expected singleton: operation.process()

for code:-

@api.one

def dup_line(self):

print "Copyyyyyyyyyyyyyyy"

self.env['operation.process'].search([('id', '=',self.pro_customer_id)], limit=1).copy()

Related Posts Replies Views Activity
2
Aug 22
10382
2
May 21
7137
2
Mar 24
10330
5
Sep 20
5184
1
Dec 19
8415