~vauxoo/addons-vauxoo/6.0-trunk

« back to all changes in this revision

Viewing changes to mrp_consume_produce/wizard/mrp_consume_produce.py

  • Committer: Gabriela (Vauxoo)
  • Date: 2012-01-03 00:42:58 UTC
  • Revision ID: gabrielaquilarque97@gmail.com-20120103004258-w881e8vj51secs2q

[IMP] Changed name of modules.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- encoding: utf-8 -*-
2
 
###########################################################################
3
 
#    Module Writen to OpenERP, Open Source Management Solution
4
 
#
5
 
#    Copyright (c) 2012 Vauxoo - http://www.vauxoo.com
6
 
#    All Rights Reserved.
7
 
#    info@vauxoo.com
8
 
############################################################################
9
 
#    Coded by: julio (julio@vauxoo.com)
10
 
############################################################################
11
 
#
12
 
#    This program is free software: you can redistribute it and/or modify
13
 
#    it under the terms of the GNU Affero General Public License as
14
 
#    published by the Free Software Foundation, either version 3 of the
15
 
#    License, or (at your option) any later version.
16
 
#
17
 
#    This program is distributed in the hope that it will be useful,
18
 
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 
#    GNU Affero General Public License for more details.
21
 
#
22
 
#    You should have received a copy of the GNU Affero General Public License
23
 
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
24
 
#
25
 
##############################################################################
26
 
import time
27
 
from openerp.osv import osv, fields
28
 
import decimal_precision as dp
29
 
from openerp.tools.translate import _
30
 
 
31
 
 
32
 
class mrp_consume(osv.TransientModel):
33
 
    _name = 'mrp.consume'
34
 
    _columns = {
35
 
        'consume_line_ids': fields.one2many('mrp.consume.line',
36
 
            'wizard_id', 'Consume')
37
 
    }
38
 
 
39
 
    def action_consume(self, cr, uid, ids, context={}):
40
 
        for production in self.browse(cr, uid, ids, context=context):
41
 
            for raw_product in production.consume_line_ids:
42
 
                context.update({
43
 
                    'product_uom': raw_product.product_uom.id,
44
 
                    'product_uom_move': raw_product.move_id.product_uom.id,
45
 
                    'quantity': raw_product.quantity})
46
 
                raw_product.move_id.action_consume(
47
 
                    raw_product.quantity, raw_product.location_id.id,
48
 
                    context=context)
49
 
        return {}
50
 
 
51
 
    def default_get(self, cr, uid, fields, context=None):
52
 
        if context is None:
53
 
            context = {}
54
 
        res = super(mrp_consume, self).default_get(
55
 
            cr, uid, fields, context=context)
56
 
        mrp_ids = context.get('active_ids', [])
57
 
        if not mrp_ids or (not context.get('active_model') == 'mrp.production') \
58
 
                or len(mrp_ids) != 1:
59
 
            return res
60
 
        mrp_id, = mrp_ids
61
 
        if 'consume_line_ids' in fields:
62
 
            mrp = self.pool.get('mrp.production').browse(
63
 
                cr, uid, mrp_id, context=context)
64
 
            moves = [self._partial_move_for(cr, uid, m)\
65
 
                    for m in mrp.move_lines if m.state\
66
 
                    not in ('done', 'cancel')]
67
 
            res.update(consume_line_ids=moves)
68
 
        return res
69
 
 
70
 
    def _partial_move_for(self, cr, uid, move):
71
 
        partial_move = {
72
 
            'product_id': move.product_id.id,
73
 
            'quantity': move.product_qty,
74
 
            'product_uom': move.product_uom.id,
75
 
            'prodlot_id': move.prodlot_id.id,
76
 
            'move_id': move.id,
77
 
            'location_id': move.location_id.id,
78
 
            'location_dest_id': move.location_dest_id.id,
79
 
        }
80
 
        return partial_move
81
 
 
82
 
 
83
 
class mrp_produce(osv.TransientModel):
84
 
    _name = 'mrp.produce'
85
 
    _columns = {
86
 
        'produce_line_ids': fields.one2many('mrp.consume.line',
87
 
            'wizard2_id', 'Consume')
88
 
    }
89
 
 
90
 
    def default_get(self, cr, uid, fields, context=None):
91
 
        if context is None:
92
 
            context = {}
93
 
        res = super(mrp_produce, self).default_get(
94
 
            cr, uid, fields, context=context)
95
 
        mrp_ids = context.get('active_ids', [])
96
 
        if not mrp_ids or (not context.get('active_model') == 'mrp.production') \
97
 
                or len(mrp_ids) != 1:
98
 
            return res
99
 
        mrp_id, = mrp_ids
100
 
        if 'produce_line_ids' in fields:
101
 
            mrp = self.pool.get('mrp.production').browse(
102
 
                cr, uid, mrp_id, context=context)
103
 
            moves = [self.pool.get('mrp.consume')._partial_move_for(cr, uid, m) \
104
 
                    for m in mrp.move_created_ids if m.state\
105
 
                    not in ('done', 'cancel')]
106
 
            res.update(produce_line_ids=moves)
107
 
        return res
108
 
 
109
 
    def action_produce(self, cr, uid, ids, context={}):
110
 
        for production in self.browse(cr, uid, ids, context=context):
111
 
            for raw_product in production.produce_line_ids:
112
 
                context.update({
113
 
                    'product_uom': raw_product.product_uom.id,
114
 
                    'product_uom_move': raw_product.move_id.product_uom.id,
115
 
                    'quantity': raw_product.quantity})
116
 
                raw_product.move_id.action_consume(
117
 
                    raw_product.quantity, raw_product.location_id.id,
118
 
                    context=context)
119
 
        return {}
120
 
 
121
 
 
122
 
class mrp_consume_line(osv.TransientModel):
123
 
    _name = 'mrp.consume.line'
124
 
    _rec_name = 'product_id'
125
 
    _columns = {
126
 
        'product_id': fields.many2one('product.product', string="Product",
127
 
            required=True),
128
 
        'quantity': fields.float("Quantity",
129
 
            digits_compute=dp.get_precision('Product UoM'), required=True),
130
 
        'product_uom': fields.many2one('product.uom', 'Unit of Measure',
131
 
            required=True,),
132
 
        'location_id': fields.many2one('stock.location', 'Location',
133
 
            required=True),
134
 
        'location_dest_id': fields.many2one('stock.location',
135
 
            'Dest. Location', required=True),
136
 
        'move_id': fields.many2one('stock.move', "Move"),
137
 
        'wizard_id': fields.many2one('mrp.consume', string="Wizard"),
138
 
        'wizard2_id': fields.many2one('mrp.produce', string="Wizard"),
139
 
    }