This question has been flagged

Hello,

I'm trying to pass a new value in an existant function and it's doesn't work.

I create a new module that inherits purchase.order and stock (stock.picking). I create a custom field in each new class. So, now I need to use a existing function in purchase.order to pass my new field value for account.invoice (I get to make this.. example below) and I need to pass this field value in purchase.order to stock.picking.

The function (purchase.order passing to stock.picking and stock.moves):

def action_picking_create(self, cr, uid, ids, context=None):

    for order in self.browse(cr, uid, ids):

        picking_vals = {

            'picking_type_id': order.picking_type_id.id,

            'partner_id': order.partner_id.id,

            'date': order.date_order,

            'origin': order.name,

            'my_new_field': order.my_new_field,

            }

        picking_id = self.pool.get('stock.picking').create(cr, uid, picking_vals, context=context)

        self._create_stock_moves(cr, uid, order, order.order_line, picking_id, context=context)

How can I make this ?

I tried with super(myclass, self).action_picking_create(self, cr, uid, ids, context=context) but I'm a newbie in python.

For another exemple, I found an answer...

My function

 def _prepare_invoice(self, cr, uid, order, line_ids, context=None):

        old_vals = super(myclass, self)._prepare_invoice(cr, uid, order, line_ids, context=context)

        old_vals['my_new_field_x'] = order.my_new_field_x or 'This Work'

        return old_vals

Original function (in purchase.order passing to account_invoice):

def _prepare_invoice(self, cr, uid, order, line_ids, context=None):

        journal_ids = self.pool['account.journal'].search( cr, uid, [('type', '=', 'purchase'), ('company_id', '=', order.company_id.id)], limit=1)

        if not journal_ids:

            raise osv.except_osv(

                _('Error!'),

                _('Define purchase journal for this company: "%s" (id:%d).') % / (order.company_id.name, order.company_id.id))

        return {

            'name': order.partner_ref or order.name,

            'reference': order.partner_ref or order.name,

            'account_id': order.partner_id.property_account_payable.id,

            'type': 'in_invoice',

            'partner_id': order.partner_id.id,

            'currency_id': order.currency_id.id,

            'journal_id': len(journal_ids) and journal_ids[0] or False,

            'invoice_line': [(6, 0, line_ids)],

            'origin': order.name,

            'fiscal_position': order.fiscal_position.id or False,

            'payment_term': order.payment_term_id.id or False,

            'company_id': order.company_id.id,

             }

Thanks for you help.

Avatar
Discard