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
|
# -*- 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/>.
#
##############################################################################
import pooler
import wizard
import netsvc
from tools.translate import _
import tools
import os
from osv import osv, fields
import time
from tools import ustr
class mrp_production(osv.osv):
_inherit = "mrp.production"
"""
"""
def create_production_wizard(self, cr, uid, product, list_produce, context):
""" creates the production order
@param product id to create
@return: True
"""
total_weight = 0
for line in list_produce:
product_obj_data = self.pool.get('product.product').browse(cr, uid, line['product_id'], context=None)
if product_obj_data.weight:
total_weight += (line['product_qty'] * product_obj_data.weight * (product.uom_id.factor / product_obj_data.uom_id.factor))
else:
total_weight += line['product_qty'] * (product.uom_id.factor / product_obj_data.uom_id.factor)
total_weight = total_weight / ((product.weight or 1) * product.uom_id.factor)
default_location_dict = self.product_id_change(cr, uid, [], product.id, context)
if (default_location_dict['value']['location_src_id'] & default_location_dict['value']['location_dest_id']):
production_order_dict = {
'name' : self.pool.get('ir.sequence').get(cr, uid, 'mrp.production'),
'date_planned' : time.strftime('%Y-%m-%d %H:%M:%S'),
'product_id' : product.id,
'product_qty' : total_weight,
'product_uom' : product.uom_id.id,
'location_src_id': default_location_dict['value']['location_src_id'],
'location_dest_id': default_location_dict['value']['location_dest_id'],
'state' : 'draft'
}
new_id = self.create(cr, uid, production_order_dict)
for line in list_produce:
production_scheduled_dict = {
'name': line['name'],
'product_id': line['product_id'],
'product_qty': line['product_qty'],
'product_uom': line['product_uom'],
'production_id': new_id,
}
self.pool.get('mrp.production.product.line').create(cr, uid, production_scheduled_dict)
mrp_pt_planifed_dict = {
'product_id' : product.id,
'quantity' : total_weight,
'production_id' : new_id,
'product_uom' : product.uom_id.id,
}
self.pool.get('mrp.pt.planified').create(cr, uid, mrp_pt_planifed_dict)
else:
raise osv.except_osv(_('Error'), _("The category of the product to produce has not predefined locations "))
return new_id
mrp_production()
|