~vauxoo/addons-vauxoo/7.0-user_story_fix1-kty

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# -*- encoding: utf-8 -*-
###########################################################################
#    Module Writen to OpenERP, Open Source Management Solution
#
#    Copyright (c) 2012 Vauxoo - http://www.vauxoo.com
#    All Rights Reserved.
#    info@vauxoo.com
############################################################################
#    Coded by: fernandoL (fernando_ld@vauxoo.com)
############################################################################
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as
#    published by the Free Software Foundation, either version 3 of the
#    License, or (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from openerp.tools.translate import _

from openerp.osv import osv, fields
import decimal_precision as dp


class account_move_line(osv.Model):
    _inherit = "account.move.line"

    """
    """

    _columns = {
        'production_id': fields.many2one('mrp.production', 'Production ID'),
        'stock_move_id': fields.many2one('stock.move', 'Stock move ID'),
    }


class account_move(osv.Model):
    _inherit = "account.move"

    """
    """

    _columns = {
        'production_id': fields.many2one('mrp.production', 'Production ID'),
        'stock_move_id': fields.many2one('stock.move', 'Stock move ID'),
    }


class stock_move(osv.Model):
    _inherit = "stock.move"

    """
    """

    def _create_account_move_line(self, cr, uid, move, src_account_id,
        dest_account_id, reference_amount, reference_currency_id,
        context=None):
        res = super(stock_move, self)._create_account_move_line(
            cr, uid, move, src_account_id, dest_account_id, reference_amount,
            reference_currency_id, context=context)
        cr.execute(
            'SELECT production_id FROM mrp_production_move_ids\
            WHERE move_id = %s', (move.id,))
        result = cr.dictfetchall()
        for line in res:
            line[2]['stock_move_id'] = move.id
            line[2]['production_id'] = move.production_id and\
                move.production_id.id or (
                    result and result[0]['production_id'] or False)
        return res

    def action_consume(self, cr, uid, ids, product_qty,
                       location_id=False, context=None):
        account_move_line_pool = self.pool.get('account.move.line')
        res = super(stock_move, self).action_consume(
            cr, uid, ids, product_qty, location_id=location_id,
            context=context)
        for move_id in res:
            cr.execute(
                'SELECT production_id FROM mrp_production_move_ids\
                WHERE move_id = %s', (move_id,))
            result = cr.dictfetchall()
            account_move_line_id = account_move_line_pool.search(
                cr, uid, [('stock_move_id', '=', move_id)])
            if result and account_move_line_id:
                account_move_line_pool.write(cr, uid, account_move_line_id, {
                    'production_id': result[0]['production_id']})
        return res