Odoo Help

Welcome!

This community 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.

0

how to add a record from a recordset to another recordset

By
Marco Guerrieri
on 2/26/15, 6:31 AM 873 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?

1

zbik

--zbik--
5941
| 6 4 7
Lodz, Poland
--zbik--


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

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

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!

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

zbik
on 2/26/15, 10:08 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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