Odoo Help

0
1 Answer
4
Avatar

Akhil P Sivan

--Akhil P Sivan--

4429
| 5 4 7
Kochi, India
--Akhil P Sivan--

Odoo Developer

email-id : akhilpsivan01@gmail.com

Akhil P Sivan
2/14/17, 1:06 AM

Hi,

You may try like this:

class SaleOrderLine(models.Model):
    _inherit = "sale.order.line"
     

    @api.multi
    def dup_line(self):
         self.copy(default={'order_id':self.order_id.id})

If you want to pass some values to the newly created record, you can pass on the default arguement of copy()

order_id is not copied by default because copy=False attribute set on the field definition, if you check in sale.order.line model.

order_id = fields.Many2one('sale.order', string='Order Reference', required=True, ondelete='cascade', index=True, copy=False)
4 Comments
Pascal Tremblay
2/14/17, 8:02 AM

Thanks for your answer. COuld you explain why the order_id is not already copied with other values? Why do you we have to give it to copy() function?

Pascal Tremblay
2/14/17, 8:12 AM

Your line works well. Thanks for this. But, I have to refresh the sale order to see the new line. Not a problem for the moment.

Akhil P Sivan
2/14/17, 8:13 AM

check updated answer for why its not copied by default

Pascal Tremblay
2/14/17, 8:35 AM

I learn a lot with your answers! Big thanks!

Ask a Question
Writer
Keep Informed
1 follower(s)
About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register
Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now