~serpent-consulting-services/openerp-usa/fix-shipping_api_ups_cc

« back to all changes in this revision

Viewing changes to mrp_disassemble/mrp_disassemble.py

  • Committer: npgllc
  • Date: 2012-08-02 17:13:27 UTC
  • Revision ID: npgllc-20120802171327-2xgyyjjb5d1kx26y
Removed all the 6.0 compatible modules

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf-8 -*-
2
 
##############################################################################
3
 
#
4
 
#    OpenERP, Open Source Management Solution
5
 
#    Copyright (C) 2011 NovaPoint Group LLC (<http://www.novapointgroup.com>)
6
 
#    Copyright (C) 2004-2010 OpenERP SA (<http://www.openerp.com>)
7
 
#
8
 
#    This program is free software: you can redistribute it and/or modify
9
 
#    it under the terms of the GNU General Public License as published by
10
 
#    the Free Software Foundation, either version 3 of the License, or
11
 
#    (at your option) any later version.
12
 
#
13
 
#    This program is distributed in the hope that it will be useful,
14
 
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 
#    GNU General Public License for more details.
17
 
#
18
 
#    You should have received a copy of the GNU General Public License
19
 
#    along with this program.  If not, see <http://www.gnu.org/licenses/>
20
 
#
21
 
##############################################################################
22
 
 
23
 
 
24
 
from osv import fields
25
 
from osv import osv
26
 
 
27
 
class mrp_subproduct(osv.osv):
28
 
    _name = 'mrp.subproduct'
29
 
    _description = 'Sub Product'
30
 
    _columns={
31
 
        'product_id': fields.many2one('product.product', 'Product', required=True),
32
 
        'product_qty': fields.float('Product Qty', required=True),
33
 
        'product_uom': fields.many2one('product.uom', 'Product UOM', required=True),
34
 
        'subproduct_type': fields.selection([('fixed','Fixed'),('variable','Variable')], 'Quantity Type', required=True),
35
 
        'bom_id': fields.many2one('mrp.bom', 'BoM'),
36
 
    }
37
 
    _defaults={
38
 
        'subproduct_type': lambda *args: 'fixed'
39
 
    }
40
 
 
41
 
    def onchange_product_id(self, cr, uid, ids, product_id, context=None):
42
 
        """ Changes UoM if product_id changes.
43
 
        @param product_id: Changed product_id
44
 
        @return: Dictionary of changed values
45
 
        """
46
 
        if product_id:
47
 
            prod = self.pool.get('product.product').browse(cr, uid, product_id, context=context)
48
 
            v = {'product_uom': prod.uom_id.id}
49
 
            return {'value': v}
50
 
        return {}
51
 
 
52
 
mrp_subproduct()
53
 
 
54
 
class mrp_bom(osv.osv):
55
 
    _name = 'mrp.bom'
56
 
    _description = 'Bill of Material'
57
 
    _inherit='mrp.bom'
58
 
 
59
 
    _columns={
60
 
        'sub_products':fields.one2many('mrp.subproduct', 'bom_id', 'sub_products'),
61
 
    }
62
 
mrp_bom()
63
 
 
64
 
class mrp_production(osv.osv):
65
 
    _description = 'Production'
66
 
    _inherit= 'mrp.production'
67
 
 
68
 
    def action_confirm(self, cr, uid, ids):
69
 
        """ Confirms production order and calculates quantity based on subproduct_type.
70
 
        @return: Newly generated picking Id.
71
 
        """
72
 
        picking_id = super(mrp_production,self).action_confirm(cr, uid, ids)
73
 
        for production in self.browse(cr, uid, ids):
74
 
            source = production.product_id.product_tmpl_id.property_stock_production.id
75
 
            if not production.bom_id:
76
 
                continue
77
 
            for sub_product in production.bom_id.sub_products:
78
 
                qty1 = sub_product.product_qty
79
 
                qty2 = production.product_uos and production.product_uos_qty or False
80
 
                if sub_product.subproduct_type == 'variable':
81
 
                    if production.product_qty:
82
 
                        qty1 *= production.product_qty / (production.bom_id.product_qty or 1.0)
83
 
                    if production.product_uos_qty:
84
 
                        qty2 *= production.product_uos_qty / (production.bom_id.product_uos_qty or 1.0)
85
 
                data = {
86
 
                    'name': 'PROD:'+production.name,
87
 
                    'date': production.date_planned,
88
 
                    'product_id': sub_product.product_id.id,
89
 
                    'product_qty': qty1,
90
 
                    'product_uom': sub_product.product_uom.id,
91
 
                    'product_uos_qty': qty2,
92
 
                    'product_uos': production.product_uos and production.product_uos.id or False,
93
 
                    'location_id': source,
94
 
                    'location_dest_id': production.location_dest_id.id,
95
 
                    'move_dest_id': production.move_prod_id.id,
96
 
                    'state': 'waiting',
97
 
                    'production_id': production.id
98
 
                }
99
 
                self.pool.get('stock.move').create(cr, uid, data)
100
 
        return picking_id
101
 
 
102
 
mrp_production()
103
 
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: