~unifield-team/unifield-wm/us-826

« back to all changes in this revision

Viewing changes to analytic_distribution_supply/stock.py

UF-675 [ADD] Copy analytic distribution from PO to PO generated invoice and shipment generated invoice

- add link between invoice line and po line for invoice that come from a shipment
- copy distribution from po to invoice

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
# -*- coding: utf-8 -*-
 
3
##############################################################################
 
4
#
 
5
#    OpenERP, Open Source Management Solution
 
6
#    Copyright (C) 2011 TeMPO Consulting, MSF. All Rights Reserved
 
7
#    Developer: Olivier DOSSMANN
 
8
#
 
9
#    This program is free software: you can redistribute it and/or modify
 
10
#    it under the terms of the GNU Affero General Public License as
 
11
#    published by the Free Software Foundation, either version 3 of the
 
12
#    License, or (at your option) any later version.
 
13
#
 
14
#    This program is distributed in the hope that it will be useful,
 
15
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
#    GNU Affero General Public License for more details.
 
18
#
 
19
#    You should have received a copy of the GNU Affero General Public License
 
20
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
21
#
 
22
##############################################################################
 
23
 
 
24
from osv import osv
 
25
 
 
26
class stock_picking(osv.osv):
 
27
    _name = 'stock.picking'
 
28
    _inherit = 'stock.picking'
 
29
 
 
30
    def _invoice_line_hook(self, cr, uid, move_line, invoice_line_id):
 
31
        """
 
32
        Create a link between invoice_line and purchase_order_line. This piece of information is available on move_line.order_line_id
 
33
        """
 
34
        if invoice_line_id and move_line:
 
35
            self.pool.get('account.invoice.line').write(cr, uid, [invoice_line_id], 
 
36
                {'order_line_id': move_line.purchase_line_id and move_line.purchase_line_id.id or False})
 
37
        return super(stock_picking, self)._invoice_line_hook(cr, uid, move_line, invoice_line_id)
 
38
 
 
39
    def _invoice_hook(self, cr, uid, picking, invoice_id):
 
40
        """
 
41
        Create a link between invoice and purchase_order.
 
42
        Copy analytic distribution from purchase order to invoice (or from commitment voucher if exists)
 
43
        """
 
44
        if invoice_id and picking:
 
45
            po_id = picking.purchase_id and picking.purchase_id.id or False
 
46
            if po_id:
 
47
                self.pool.get('purchase.order').write(cr, uid, [po_id], {'invoice_ids': [(4, invoice_id)]})
 
48
            # Copy analytic distribution from purchase order or commitment voucher (if exists)
 
49
            self.pool.get('account.invoice').fetch_analytic_distribution(cr, uid, [invoice_id])
 
50
        return super(stock_picking, self)._invoice_hook(cr, uid, picking, invoice_id)
 
51
 
 
52
stock_picking()
 
53
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: