~vauxoo/addons-vauxoo/6.0-trunk

« back to all changes in this revision

Viewing changes to mrp_request_return/mrp.py

  • Committer: Gabriela (Vauxoo)
  • Date: 2012-01-02 16:24:49 UTC
  • Revision ID: gabrielaquilarque97@gmail.com-20120102162449-lhxnrtif2ud36du2

[ADD] Added new module invoice_so.

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
 
from openerp.osv import osv, fields
27
 
from openerp.tools.translate import _
28
 
 
29
 
 
30
 
class mrp_production(osv.Model):
31
 
    _inherit = 'mrp.production'
32
 
 
33
 
    _columns = {
34
 
        'picking_ids': fields.one2many('stock.picking', 'production_id',
35
 
            'Picking')
36
 
    }
37
 
 
38
 
    def action_finished_consume(self, cr, uid, ids, context=None):
39
 
        if context is None:
40
 
            context = {}
41
 
 
42
 
        stock_picking = self.pool.get('stock.picking')
43
 
        mrp_production2 = self.pool.get('mrp.production')
44
 
        stock_move = self.pool.get('stock.move')
45
 
        production = self.pool.get('mrp.production').browse(
46
 
            cr, uid, ids, context=context)[0]
47
 
 
48
 
        for wizard_moves in self.browse(cr, uid, ids, context=context):
49
 
            context['type'] = 'return'
50
 
            pick_id_return = mrp_production2._make_production_internal_shipment2(
51
 
                cr, uid, production, context=context)
52
 
            stock_picking.write(cr, uid, pick_id_return, {
53
 
                                'state': 'draft',
54
 
                                'auto_picking': False,
55
 
                                'production_id': production.id})
56
 
            for wiz_move2 in wizard_moves.move_lines:
57
 
                if wiz_move2.product_qty > 0.0:
58
 
                    shipment_move_id = mrp_production2._make_production_internal_shipment_line2(
59
 
                        cr, uid, production, wiz_move2, pick_id_return,
60
 
                        parent_move_id=False, destination_location_id=False)
61
 
                    stock_move.write(cr, uid, shipment_move_id, {
62
 
                                     'state': 'draft'})
63
 
        res = super(mrp_production, self).action_finished_consume(
64
 
            cr, uid, ids, context=context)
65
 
        return res
66
 
 
67
 
    def _make_production_internal_shipment_line2(self, cr, uid, production,
68
 
                                                production_line, shipment_id,
69
 
                                                parent_move_id,
70
 
                                                destination_location_id=False,
71
 
                                                context=None):
72
 
        stock_move = self.pool.get('stock.move')
73
 
        date_planned = production.date_planned
74
 
        if production_line.product_id.type not in ('product', 'consu'):
75
 
            return False
76
 
        move_name = _('PROD: %s') % production.name
77
 
        source_location_id = production.location_src_id.id
78
 
 
79
 
        if not destination_location_id:
80
 
            destination_location_id = source_location_id
81
 
        return stock_move.create(cr, uid, {
82
 
            'name': move_name,
83
 
            'picking_id': shipment_id,
84
 
            'product_id': production_line.product_id.id,
85
 
            'product_qty': production_line.product_qty,
86
 
            'product_uom': production_line.product_uom.id,
87
 
            'product_uos_qty': production_line.product_uos and
88
 
                                production_line.product_uos_qty or False,
89
 
            'product_uos': production_line.product_uos and
90
 
                            production_line.product_uos.id or False,
91
 
            'date': date_planned,
92
 
            'move_dest_id': parent_move_id,
93
 
            'location_id': source_location_id,
94
 
            'location_dest_id': destination_location_id,
95
 
            'state': 'waiting',
96
 
            'company_id': production.company_id.id,
97
 
        })
98
 
 
99
 
    def _make_production_internal_shipment2(self, cr, uid, production,
100
 
                                            context=None):
101
 
        ir_sequence = self.pool.get('ir.sequence')
102
 
        stock_picking = self.pool.get('stock.picking')
103
 
        routing_loc = None
104
 
        pick_type = 'internal'
105
 
        address_id = False
106
 
 
107
 
        # Take routing address as a Shipment Address.
108
 
        # If usage of routing location is a internal, make outgoing shipment
109
 
        # otherwise internal shipment
110
 
        if production.bom_id.routing_id and\
111
 
        production.bom_id.routing_id.location_id:
112
 
            routing_loc = production.bom_id.routing_id.location_id
113
 
            if routing_loc.usage != 'internal':
114
 
                pick_type = 'out'
115
 
            address_id = routing_loc.address_id and\
116
 
                        routing_loc.address_id.id or False
117
 
 
118
 
        # Take next Sequence number of shipment base on type
119
 
        pick_name = ir_sequence.get(cr, uid, 'stock.picking')
120
 
        picking_id = stock_picking.create(cr, uid, {
121
 
            'name': pick_name + '-' + context.get('type', ''),
122
 
            'origin': (production.origin or '').split(':')[0]\
123
 
                        + ':' + production.name,
124
 
            'type': pick_type,
125
 
            'state': 'draft',
126
 
            'address_id': address_id,
127
 
            'company_id': production.company_id.id,
128
 
        })
129
 
        return picking_id
130
 
 
131
 
    def copy(self, cr, uid, id, default=None, context=None):
132
 
        if default is None:
133
 
            default = {}
134
 
        default.update({
135
 
            'picking_ids': []
136
 
        })
137
 
        return super(mrp_production, self).copy(cr, uid, id, default, context)
138
 
 
139
 
 
140
 
class stock_picking(osv.Model):
141
 
    _inherit = 'stock.picking'
142
 
 
143
 
    _columns = {
144
 
        'production_id': fields.many2one('mrp.production', 'Production')
145
 
    }
146
 
mrp_production()