This question has been flagged
2 Replies
3108 Views

I added a discount field to my purchase orders, I make my purchase invoices based on them, and I need discount passes from purchase orders to purchase invoices. I was looking for the method who reads the lines from purchase orders, and writes it on purchase invoices, but I don't find it. Anyone knows wich function make this operation? Thanks in advice.

Avatar
Discard

purchase/purchase.py - method: _prepare_inv_line(self, cr, uid, account_id, order_line, context=None)

Author

Thanks zbik, it helps to break my mind on the next step ;)

Author Best Answer

zbkik solves my problem. He said:

If your Default invoicing control method = Based on incoming shipments, you see _get_invoice_line_vals in stock_account/stock.py
 

Avatar
Discard
Best Answer

if you are looking for discount on order lines.. take a look here:
https://www.odoo.com/apps/7.0/purchase_discount/

if youre looking for additional discount (on total of invoice) maybe google a bit over partners repositories ... you will find some interesting stuf...

Avatar
Discard
Author

That module is not working for 8.0, i'm doing a new module based on purchase_discount existing addon. It has this code, to do what I want, but it doesn,t work: class purchase_order(orm.Model): def _prepare_inv_line(self, cr, uid, account_id, order_line, context=None): result = super(purchase_order, self)._prepare_inv_line(cr, uid, account_id, order_line, context) result['discount'] = order_line.discount or 0.0 return result class stock_picking(orm.Model): _inherit = 'stock.picking' def _invoice_line_hook(self, cr, uid, move_line, invoice_line_id): if move_line.purchase_line_id: line = {'discount': move_line.purchase_line_id.discount} self.pool.get('account.invoice.line').write(cr, uid, [invoice_line_id], line) return super(stock_picking, self)._invoice_line_hook(cr, uid, move_line, invoice_line_id)

Author

I have new objetcs on my addon inheriting purchase.order and stock.picking, with new functions to _prepare_inv_line from purchase.order and _invoice_line_hook from stock.picking, but them seems not to be called from the invoice process, because the code I have for these methods does nothing. I put a message with raise osv.except_osv into the code, to be sure the functions are called from the make invoice process, but it isn't showed. Because of this, I think odoo 8 uses another functions to the invoice process, but I can find them.

If your Default invoicing control method = Based on incoming shipments, you see _get_invoice_line_vals in stock_account/stock.py

Author

Thanks zbik, it helps to break my mind on the next step ;)