This question has been flagged
3 Replies
7123 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?

Avatar
Discard
Best Answer

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().

Avatar
Discard
Best Answer

Hey Did you find a solution to copy sale order lines to a different recordset?

Avatar
Discard
Author Best Answer

Ok, so i need for each purchase_order do something like

values={
                    '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 -_- )

 

 

EDIT:

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

worked! Thanks a lot!

Avatar
Discard

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