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.

1

Ovetride the create invoice button (_prepare_invoice) in active sale order in new api

By
NIKHIL KRISHNAN
on 7/14/16, 5:09 AM 500 views

create 2 new fields in sale order and invoice lines as  “Order Type” and “Staff”.  When Creating Customer Invoice, pass the value of “Order Type”, “Staff” from SO to the corresponding fields in all invoice lines..

class SaleOrderForm(models.Model):
     _inherit = "sale.order"
     order_type = fields.Many2one('account.analytic.account', string='Order Type)
     staff = fields.Many2one('account.analytic.account', string='Staff', required=True)

     def _prepare_invoice(self, cr, uid, order, lines, context=None):
            self.pool.get('account.invoice.line').write(cr, uid, lines, {'order_type': order.order_type.id, 'staff': order.staff.id})
        return super(so_form, self)._prepare_invoice(cr, uid, order, lines, context=None)

This is a working code. but i just need it in new api. please help me.. Thanks in advance.

I don't no value of lines, ids invoice_line [1,2,3,4] or object invoice_line (account.invoice.line(1,2,3,4))?

Miftah
on 7/14/16, 6:20 AM
1
kampeons
On 7/15/16, 6:45 AM

Try this, It will work..


@api.modeldef _prepare_invoice(self, order, lines):
 print "****************Invoice Gen*****************"
print order.order_type.name
print lines
res = super(so_form, self)._prepare_invoice(order, lines)
if lines:
    for i in lines:
        self.env['account.invoice.line'].search([('id', '=', i)]).write({'order_type': order.order_type.id, 'staff':order.staff.id})
return res

Thanks Cybrosys..!!

its working..!

NIKHIL KRISHNAN
on 7/15/16, 6:50 AM
1
Miftah
On 7/14/16, 6:14 AM

Try this :

@api.multi
def _prepare_invoice(self, order, lines):
    self.env['account.invoice.line'].write(self._cr, self._uid, lines, {'order_type': order.order_type.id, 'staff': order.staff.id})
 return super(so_form, self)._prepare_invoice(order, lines)

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: 7/14/16, 5:09 AM
Seen: 500 times
Last updated: 7/15/16, 6:49 AM