1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
21 from osv import fields, osv
22 from service import web_services
23 from tools.translate import _
28 class stock_partial_picking(osv.osv_memory):
29 _name = "stock.partial.picking"
30 _description = "Partial Picking"
32 'date': fields.datetime('Date', required=True),
35 def view_init(self, cr, uid, fields_list, context=None):
36 res = super(stock_partial_picking, self).view_init(cr, uid, fields_list, context=context)
37 pick_obj = self.pool.get('stock.picking')
41 for pick in pick_obj.browse(cr, uid, context.get('active_ids', [])):
42 for m in pick.move_lines:
43 if m.state in ('done', 'cancel'):
45 if 'move%s_product_id'%(m.id) not in self._columns:
46 self._columns['move%s_product_id'%(m.id)] = fields.many2one('product.product',string="Product")
47 if 'move%s_product_qty'%(m.id) not in self._columns:
48 self._columns['move%s_product_qty'%(m.id)] = fields.float("Quantity")
49 if 'move%s_product_uom'%(m.id) not in self._columns:
50 self._columns['move%s_product_uom'%(m.id)] = fields.many2one('product.uom',string="Product UOM")
52 if (m.product_id.cost_method == 'average'):
53 if 'move%s_product_price'%(m.id) not in self._columns:
54 self._columns['move%s_product_price'%(m.id)] = fields.float("Price")
55 if 'move%s_product_currency'%(m.id) not in self._columns:
56 self._columns['move%s_product_currency'%(m.id)] = fields.many2one('res.currency',string="Currency")
59 def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False,submenu=False):
60 result = super(stock_partial_picking, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar,submenu)
61 pick_obj = self.pool.get('stock.picking')
62 picking_ids = context.get('active_ids', False)
63 _moves_arch_lst = """<form string="Deliver Products">
64 <separator colspan="4" string="Delivery Information"/>
65 <field name="date" colspan="4" />
66 <separator colspan="4" string="Move Detail"/>
68 _moves_fields = result['fields']
69 if picking_ids and view_type in ['form']:
70 for pick in pick_obj.browse(cr, uid, picking_ids, context):
71 for m in pick.move_lines:
72 if m.state in ('done', 'cancel'):
74 _moves_fields.update({
75 'move%s_product_id'%(m.id) : {
76 'string': _('Product'),
78 'relation': 'product.product',
82 'move%s_product_qty'%(m.id) : {
83 'string': _('Quantity'),
87 'move%s_product_uom'%(m.id) : {
88 'string': _('Product UOM'),
90 'relation': 'product.uom',
96 _moves_arch_lst += """
97 <group colspan="4" col="10">
98 <field name="move%s_product_id" nolabel="1"/>
99 <field name="move%s_product_qty" string="Qty" />
100 <field name="move%s_product_uom" nolabel="1" />
101 """%(m.id, m.id, m.id)
102 if (m.product_id.cost_method == 'average'):
103 _moves_fields.update({
104 'move%s_product_price'%(m.id) : {
105 'string': _('Price'),
108 'move%s_product_currency'%(m.id): {
109 'string': _('Currency'),
112 'relation': 'res.currency',
115 _moves_arch_lst += """
116 <field name="move%s_product_price" />
117 <field name="move%s_product_currency" nolabel="1"/>
119 _moves_arch_lst += """
122 _moves_arch_lst += """
123 <separator string="" colspan="4" />
124 <label string="" colspan="2"/>
125 <group col="2" colspan="2">
126 <button icon='gtk-cancel' special="cancel"
128 <button name="do_partial" string="_Deliver"
129 colspan="1" type="object" icon="gtk-apply" />
132 result['arch'] = _moves_arch_lst
133 result['fields'] = _moves_fields
136 def default_get(self, cr, uid, fields, context=None):
137 """ To get default values for the object.
138 @param self: The object pointer.
139 @param cr: A database cursor
140 @param uid: ID of the user currently logged in
141 @param fields: List of fields for which we want default values
142 @param context: A standard dictionary
143 @return: A dictionary which of fields with values.
146 res = super(stock_partial_picking, self).default_get(cr, uid, fields, context=context)
147 pick_obj = self.pool.get('stock.picking')
152 res.update({'date': time.strftime('%Y-%m-%d %H:%M:%S')})
153 for pick in pick_obj.browse(cr, uid, context.get('active_ids', [])):
154 for m in pick.move_lines:
155 if m.state in ('done', 'cancel'):
157 if 'move%s_product_id'%(m.id) in fields:
158 res['move%s_product_id'%(m.id)] = m.product_id.id
159 if 'move%s_product_qty'%(m.id) in fields:
160 res['move%s_product_qty'%(m.id)] = m.product_qty
161 if 'move%s_product_uom'%(m.id) in fields:
162 res['move%s_product_uom'%(m.id)] = m.product_uom.id
164 if (m.product_id.cost_method == 'average'):
167 if (pick.type == 'in'):
168 if hasattr(m, 'purchase_line_id') and m.purchase_line_id:
169 price = m.purchase_line_id.price_unit
170 if hasattr(pick, 'purchase_id') and pick.purchase_id:
171 currency = pick.purchase_id.pricelist_id.currency_id.id
172 if (pick.type == 'out'):
173 if hasattr(m, 'sale_line_id') and m.sale_line_id:
174 price = m.sale_line_id.price_unit
175 if hasattr(pick, 'sale_id') and pick.sale_id:
176 currency = pick.sale_id.pricelist_id.currency_id.id
177 if 'move%s_product_price'%(m.id) in fields:
178 res['move%s_product_price'%(m.id)] = price
179 if 'move%s_product_currency'%(m.id) in fields:
180 res['move%s_product_currency'%(m.id)] = currency
183 def do_partial(self, cr, uid, ids, context):
184 """ Makes partial moves and pickings done.
185 @param self: The object pointer.
186 @param cr: A database cursor
187 @param uid: ID of the user currently logged in
188 @param fields: List of fields for which we want default values
189 @param context: A standard dictionary
190 @return: A dictionary which of fields with values.
192 pick_obj = self.pool.get('stock.picking')
193 picking_ids = context.get('active_ids', False)
194 partial = self.browse(cr, uid, ids[0], context)
196 'delivery_date' : partial.date
198 for pick in pick_obj.browse(cr, uid, picking_ids):
199 for m in pick.move_lines:
200 if m.state in ('done', 'cancel'):
202 partial_datas['move%s'%(m.id)] = {
203 'product_id' : getattr(partial, 'move%s_product_id'%(m.id)).id,
204 'product_qty' : getattr(partial, 'move%s_product_qty'%(m.id)),
205 'product_uom' : getattr(partial, 'move%s_product_uom'%(m.id)).id
208 if (m.product_id.cost_method == 'average'):
209 partial_datas['move%s'%(m.id)].update({
210 'product_price' : getattr(partial, 'move%s_product_price'%(m.id)),
211 'product_currency': getattr(partial, 'move%s_product_currency'%(m.id)).id
213 res = pick_obj.do_partial(cr, uid, picking_ids, partial_datas, context=context)
216 stock_partial_picking()
220 #_moves_arch_end = '''<?xml version="1.0"?>
221 #<form string="Picking result">
222 # <label string="The picking has been successfully made !" colspan="4"/>
223 # <field name="back_order_notification" colspan="4" nolabel="1"/>
226 #_moves_fields_end = {
227 # 'back_order_notification': {'string':'Back Order' ,'type':'text', 'readonly':True}
229 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: