Odoo Help


how to add a record from a recordset to another recordset

Marco Guerrieri
on 2/26/15, 6:31 AM 1,520 views

Hi all,

I'm working for the first time in Odoo, and I need to add a record from a recordset to an another recordset.

I have a purchase_order with some order_line, and I want to copy all the order_line in the order_line of a sale_order


class sale_order(osv.osv):

_inherit = "sale.order"

_columns = {
        'commessa' : fields.char('Commessa', copy=False),

def fill_order(self, cr, uid, ids, context=None):
        this = self.browse(cr, uid, ids, context=context)

        purchase_obj = self.pool.get('purchase.order')
        purchase_ids = purchase_obj.search(cr, uid, [('commessa','=',this._commessa)])

        for purchase_line in purchase_ids:
            purchase = purchase_obj.browse(cr, uid,  purchase_line, context=context)

            for order_line in purchase.order_line:
                #now I want to copy all the line from purchase_order to this sale_order


Someon can help me?



| 6 5 7
Lodz, Poland

On 2/26/15, 8:55 AM

Records can not be added (they have different fields). You will need to fill out every time a new record sale.order.line and call create().

Marco Guerrieri
On 2/26/15, 9:35 AM

Ok, so i need for each purchase_order do something like

                    'name': order_line.name,
                    'product_uom': order_line.product_uom,
                    'write_uid': order_line.write_uid,
                    'price_unit': order_line.price_unit,
                    'product_uom_qty': order_line.product_qty,
                    'company_id': order_line.company_id,
                    'order_partner_id': order_line.partner_id,
                    'order_id': order_line.order_id,
                    'write_date': order_line.write_date,
                    'product_id': order_line.product_id,
                sale_order_line = self.pool.get('sale.order.line')
                sale_order_line.create(self, cr, uid, values, context=None)

obviously this won't work, because I haven't understand the right way to use the ORM (I wanna cry, they gave me 5 days for create a big module for odoo and I never worked with this platform neither with python -_- )




sale_order_line = self.pool.get('sale.order.line')
sale_order_line_id = sale_order_line.create(cr, uid, values)

worked! Thanks a lot!

try this: sale_order_line.create(cr, uid, values, context=context) ... and if xxx_id then like this ... 'product_id': order_line.product_id.id

on 2/26/15, 10:08 AM

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.


Odoo Training Center

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

Test it now

Question tools

1 follower(s)


Asked: 2/26/15, 6:31 AM
Seen: 1520 times
Last updated: 3/16/15, 8:10 AM