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 change a function and pass a new value from a custom field ? [Odoo v8]

By
PopUp House
on 2/29/16, 9:58 AM 352 views

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.

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/29/16, 9:58 AM
Seen: 352 times
Last updated: 2/29/16, 10:08 AM