[MERGE] merged the dev branch: conversion of oldstyle wizard (a la partial picking), that includes the removal of 2 unused wizards (mrp/wizard/mrp_track_prod.py and stock/wizard/stock_split_move.py)
bzr revid: qdp-launchpad@openerp.com-20110315122147-0lj9n4v7cmxjrpkz
This commit is contained in:
@@ -1,129 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
# 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/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from osv import osv, fields
|
||||
|
||||
class mrp_track_move(osv.osv_memory):
|
||||
_name = 'mrp.production.track'
|
||||
_description = 'Production Track'
|
||||
|
||||
def view_init(self, cr, uid, fields_list, context=None):
|
||||
""" Creates view dynamically and adding fields at runtime.
|
||||
@param self: The object pointer.
|
||||
@param cr: A database cursor
|
||||
@param uid: ID of the user currently logged in
|
||||
@param context: A standard dictionary
|
||||
@return: New arch of view with new columns.
|
||||
"""
|
||||
res = super(mrp_track_move, self).view_init(cr, uid, fields_list, context=context)
|
||||
record_id = context and context.get('active_id', False) or False
|
||||
if record_id:
|
||||
prod_obj = self.pool.get('mrp.production')
|
||||
try:
|
||||
prod = prod_obj.browse(cr, uid, record_id, context=context)
|
||||
for m in [line for line in prod.move_created_ids]:
|
||||
if 'track%s'%(m.id) not in self._columns:
|
||||
self._columns['track%s'%(m.id)] = fields.boolean(string=m.product_id.name)
|
||||
except:
|
||||
return res
|
||||
return res
|
||||
|
||||
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
|
||||
""" Changes the view dynamically
|
||||
@param self: The object pointer.
|
||||
@param cr: A database cursor
|
||||
@param uid: ID of the user currently logged in
|
||||
@param context: A standard dictionary
|
||||
@return: New arch of view.
|
||||
"""
|
||||
if context is None:
|
||||
context = {}
|
||||
res = super(mrp_track_move, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar,submenu=False)
|
||||
record_id = context and context.get('active_id', False) or False
|
||||
active_model = context.get('active_model')
|
||||
|
||||
if not record_id or (active_model and active_model != 'mrp.production'):
|
||||
return res
|
||||
|
||||
prod_obj = self.pool.get('mrp.production')
|
||||
prod = prod_obj.browse(cr, uid, record_id, context=context)
|
||||
if prod.state != 'done':
|
||||
res['arch'] = '''<form string="Track lines">
|
||||
<label colspan="4" string="You can not split an unfinished production Output." />
|
||||
<group col="2" colspan="4">
|
||||
<button icon='gtk-cancel' special="cancel"
|
||||
string="Exit" />
|
||||
</group>
|
||||
</form>
|
||||
'''
|
||||
else:
|
||||
arch_lst = ['<form string="Track lines">', '<label colspan="4" string="The field on each line says whether this lot should be tracked or not." />']
|
||||
for m in [line for line in prod.move_created_ids]:
|
||||
quantity = m.product_qty
|
||||
res['fields']['track%s' %m.id] = {'string' : m.product_id.name, 'type' : 'boolean', 'default' : lambda x,y,z: False}
|
||||
arch_lst.append('<field name="track%s" />\n<newline />' %m.id)
|
||||
arch_lst.append('<group col="2" colspan="4">')
|
||||
arch_lst.append('<button icon=\'gtk-cancel\' special="cancel" string="Cancel" />')
|
||||
arch_lst.append('<button name="track_lines" string="Track" colspan="1" type="object" icon="gtk-ok" />')
|
||||
arch_lst.append('</group>')
|
||||
arch_lst.append('</form>')
|
||||
res['arch'] = '\n'.join(arch_lst)
|
||||
|
||||
return res
|
||||
|
||||
def track_lines(self, cr, uid, ids, context=None):
|
||||
""" Tracks Finished products and splits products to finish lines.
|
||||
@param self: The object pointer.
|
||||
@param cr: A database cursor
|
||||
@param uid: ID of the user currently logged in
|
||||
@param ids: List of IDs selected
|
||||
@param context: A standard dictionary
|
||||
@return:
|
||||
"""
|
||||
if context is None:
|
||||
context = {}
|
||||
record_id = context and context.get('active_id', False) or False
|
||||
assert record_id, 'Active ID not found'
|
||||
data = self.read(cr, uid, ids[0])
|
||||
prod_obj = self.pool.get('mrp.production')
|
||||
prod = prod_obj.browse(cr, uid, record_id, context=context)
|
||||
if not prod.move_created_ids and prod.state != 'done':
|
||||
return {}
|
||||
prodlot_obj = self.pool.get('stock.production.lot')
|
||||
move_obj = self.pool.get('stock.move')
|
||||
move_ids = [m.id for m in [line for line in prod.move_created_ids]]
|
||||
for idx, move in enumerate(move_obj.browse(cr, uid, move_ids, context=context)):
|
||||
if data['track%s' %move.id]:
|
||||
for idx in range(int(move.product_qty)):
|
||||
update_val = {'product_qty': 1}
|
||||
if idx:
|
||||
current_move = move_obj.copy(cr, uid, move.id, {'state': move.state, 'production_id': move.production_id.id})
|
||||
else:
|
||||
current_move = move.id
|
||||
new_prodlot = prodlot_obj.create(cr, uid, {'name': 'PRODUCTION:%d:LOT:%d' % (record_id, idx+1), 'product_id': move.product_id.id})
|
||||
update_val['prodlot_id'] = new_prodlot
|
||||
move_obj.write(cr, uid, [current_move], update_val)
|
||||
return {'type': 'ir.actions.act_window_close'}
|
||||
|
||||
mrp_track_move()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<!-- Track Production -->
|
||||
|
||||
<act_window name="Track Production"
|
||||
res_model="mrp.production.track"
|
||||
src_model="mrp.production"
|
||||
view_mode="form"
|
||||
target="new"
|
||||
key2="client_action_multi"
|
||||
id="act_production_track"/>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
@@ -374,7 +374,9 @@
|
||||
I click on Return Picking button.
|
||||
-
|
||||
!record {model: pos.return, id: pos_return_0}:
|
||||
{}
|
||||
pos_moves_ids:
|
||||
- product_id: product_product_hppaviliondesktoppcs0
|
||||
quantity: 5.0
|
||||
-
|
||||
I Return the product.
|
||||
-
|
||||
|
||||
@@ -24,9 +24,25 @@ from osv import osv,fields
|
||||
from tools.translate import _
|
||||
import time
|
||||
|
||||
class pos_return_memory(osv.osv_memory):
|
||||
_name = "pos.return.memory"
|
||||
_rec_name = 'product_id'
|
||||
_columns = {
|
||||
'product_id' : fields.many2one('product.product', string="Product", required=True),
|
||||
'quantity' : fields.float("Quantity", required=True),
|
||||
'pos_moves_id' : fields.many2one('pos.return', string="Move"),
|
||||
'line_id': fields.integer('Line Id'),
|
||||
}
|
||||
|
||||
pos_return_memory()
|
||||
|
||||
|
||||
class pos_return(osv.osv_memory):
|
||||
_name = 'pos.return'
|
||||
_description = 'Point of sale return'
|
||||
_columns = {
|
||||
'pos_moves_ids' : fields.one2many('pos.return.memory', 'pos_moves_id', 'Moves'),
|
||||
}
|
||||
|
||||
def default_get(self, cr, uid, fields, context=None):
|
||||
"""
|
||||
@@ -41,98 +57,22 @@ class pos_return(osv.osv_memory):
|
||||
@return: A dictionary which of fields with values.
|
||||
|
||||
"""
|
||||
|
||||
res = super(pos_return, self).default_get(cr, uid, fields, context=context)
|
||||
order_obj = self.pool.get('pos.order')
|
||||
if context is None:
|
||||
context={}
|
||||
active_ids = context.get('active_ids')
|
||||
result=[]
|
||||
for order in order_obj.browse(cr, uid, active_ids, context=context):
|
||||
for line in order.lines:
|
||||
if 'return%s'%(line.id) in fields:
|
||||
res['return%s'%(line.id)] = line.qty
|
||||
result.append({
|
||||
'product_id' : line.product_id.id,
|
||||
'quantity' : line.qty,
|
||||
'line_id':line.id
|
||||
})
|
||||
res.update({'pos_moves_ids': result})
|
||||
return res
|
||||
|
||||
def view_init(self, cr, uid, fields_list, context=None):
|
||||
"""
|
||||
Creates view dynamically and adding fields at runtime.
|
||||
@param self: The object pointer.
|
||||
@param cr: A database cursor
|
||||
@param uid: ID of the user currently logged in
|
||||
@param context: A standard dictionary
|
||||
@return: New arch of view with new columns.
|
||||
"""
|
||||
res = super(pos_return, self).view_init(cr, uid, fields_list, context=context)
|
||||
order_obj=self.pool.get('pos.order')
|
||||
if context is None:
|
||||
context={}
|
||||
|
||||
active_ids=context.get('active_ids')
|
||||
for order in order_obj.browse(cr, uid, active_ids, context=context):
|
||||
for line in order.lines:
|
||||
if 'return%s'%(line.id) not in self._columns:
|
||||
self._columns['return%s'%(line.id)] = fields.float("Quantity")
|
||||
|
||||
return res
|
||||
|
||||
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False,submenu=False):
|
||||
|
||||
"""
|
||||
Changes the view dynamically
|
||||
|
||||
@param self: The object pointer.
|
||||
@param cr: A database cursor
|
||||
@param uid: ID of the user currently logged in
|
||||
@param context: A standard dictionary
|
||||
|
||||
@return: New arch of view.
|
||||
|
||||
"""
|
||||
result = super(pos_return, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar,submenu)
|
||||
if context is None:
|
||||
context={}
|
||||
active_model = context.get('active_model')
|
||||
if not active_model and active_model != 'pos.order':
|
||||
return result
|
||||
order_obj = self.pool.get('pos.order')
|
||||
active_id = context.get('active_id', False)
|
||||
if active_id:
|
||||
_moves_arch_lst="""<?xml version="1.0"?>
|
||||
<form string="Return lines">
|
||||
<label string="Quantities you enter, match to products that will return to the stock." colspan="4"/>"""
|
||||
_line_fields = result['fields']
|
||||
order=order_obj.browse(cr, uid, active_id, context=context)
|
||||
for line in order.lines:
|
||||
quantity=line.qty
|
||||
_line_fields.update({
|
||||
'return%s'%(line.id) : {
|
||||
'string': line.product_id.name,
|
||||
'type' : 'float',
|
||||
'required': True,
|
||||
'default':quantity
|
||||
},
|
||||
})
|
||||
_moves_arch_lst += """
|
||||
<field name="return%s"/>
|
||||
<newline/>
|
||||
"""%(line.id)
|
||||
|
||||
_moves_arch_lst+="""
|
||||
<newline/>
|
||||
<separator colspan="4"/>
|
||||
<button icon='gtk-cancel' special="cancel"
|
||||
string="Cancel" />
|
||||
<button icon='gtk-ok' name= "create_returns"
|
||||
string="Return with Exchange" type="object"/>
|
||||
<button icon='gtk-ok' name="create_returns2"
|
||||
string="Refund Without Exchange" type="object"/>
|
||||
</form>"""
|
||||
|
||||
result['arch'] = _moves_arch_lst
|
||||
result['fields'] = _line_fields
|
||||
return result
|
||||
|
||||
|
||||
def create_returns(self, cr, uid, data, context=None):
|
||||
"""
|
||||
@param self: The object pointer.
|
||||
@@ -145,23 +85,15 @@ class pos_return(osv.osv_memory):
|
||||
"""
|
||||
if context is None:
|
||||
context = {}
|
||||
current_rec = self.read(cr, uid, data[0], context=context)
|
||||
current_rec = self.browse(cr, uid, data, context=context)[0]
|
||||
order_obj =self.pool.get('pos.order')
|
||||
line_obj = self.pool.get('pos.order.line')
|
||||
pos_current = order_obj.browse(cr, uid, context.get('active_id'), context=context)
|
||||
pos_line_ids = pos_current.lines
|
||||
if pos_line_ids:
|
||||
for pos_line in pos_line_ids:
|
||||
line_field = "return"+str(pos_line.id)
|
||||
pos_list = current_rec.keys()
|
||||
newline_vals = {}
|
||||
if line_field in pos_list :
|
||||
less_qty = current_rec.get(line_field)
|
||||
pos_cur_line = line_obj.browse(cr, uid, pos_line.id, context=context)
|
||||
qty = pos_cur_line.qty
|
||||
qty = qty - less_qty
|
||||
newline_vals.update({'qty':qty})
|
||||
line_obj.write(cr, uid, pos_line.id, newline_vals, context=context)
|
||||
for pos_line in pos_current.lines:
|
||||
for record in current_rec.pos_moves_ids:
|
||||
if pos_line.id == record.line_id:
|
||||
less_qty = record.quantity
|
||||
line_obj.write(cr, uid, pos_line.id, {'qty':pos_line.qty - less_qty}, context=context)
|
||||
return {
|
||||
'name': _('Add Product'),
|
||||
'view_type': 'form',
|
||||
@@ -174,6 +106,7 @@ class pos_return(osv.osv_memory):
|
||||
'type': 'ir.actions.act_window',
|
||||
}
|
||||
def create_returns2(self, cr, uid, ids, context=None):
|
||||
|
||||
if context is None:
|
||||
context = {}
|
||||
active_id = context.get('active_id', False)
|
||||
@@ -187,18 +120,16 @@ class pos_return(osv.osv_memory):
|
||||
wf_service = netsvc.LocalService("workflow")
|
||||
#Todo :Need to clean the code
|
||||
if active_id:
|
||||
data = self.read(cr, uid, ids)[0]
|
||||
data = self.browse(cr, uid, ids, context=context)[0]
|
||||
date_cur = time.strftime('%Y-%m-%d %H:%M:%S')
|
||||
|
||||
for order_id in order_obj.browse(cr, uid, [active_id], context=context):
|
||||
prop_ids = property_obj.search(cr, uid,[('name', '=', 'property_stock_customer')])
|
||||
val = property_obj.browse(cr, uid, prop_ids[0], context=context).value_reference
|
||||
stock_dest_id = property_obj.get(cr, uid, 'property_stock_customer', 'res.partner', context=context).id
|
||||
cr.execute("SELECT s.id FROM stock_location s, stock_warehouse w "
|
||||
"WHERE w.lot_stock_id=s.id AND w.id=%s ",
|
||||
(order_id.shop_id.warehouse_id.id,))
|
||||
res = cr.fetchone()
|
||||
location_id = res and res[0] or None
|
||||
stock_dest_id = val.id
|
||||
new_picking = picking_obj.copy(cr, uid, order_id.picking_id.id, {'name':'%s (return)' % order_id.name,
|
||||
'move_lines': [],
|
||||
'state':'draft',
|
||||
@@ -212,25 +143,23 @@ class pos_return(osv.osv_memory):
|
||||
account_def = property_obj.get(cr, uid, 'property_account_payable', 'res.partner', context=context)
|
||||
amount = 0.0
|
||||
for line in order_id.lines:
|
||||
if line.id:
|
||||
try:
|
||||
qty = data['return%s' %line.id]
|
||||
for record in data.pos_moves_ids:
|
||||
if line.id == record.line_id:
|
||||
qty = record.quantity
|
||||
amount += qty * line.price_unit
|
||||
except :
|
||||
qty = line.qty
|
||||
stock_move_obj.create(cr, uid, {
|
||||
'product_qty': qty ,
|
||||
'product_uos_qty': uom_obj._compute_qty(cr, uid, qty ,line.product_id.uom_id.id),
|
||||
'picking_id': new_picking,
|
||||
'product_uom': line.product_id.uom_id.id,
|
||||
'location_id': location_id,
|
||||
'product_id': line.product_id.id,
|
||||
'location_dest_id': stock_dest_id,
|
||||
'name': '%s (return)' %order_id.name,
|
||||
'date': date_cur
|
||||
})
|
||||
if qty != 0.0:
|
||||
line_obj.copy(cr, uid, line.id, {'qty': -qty, 'order_id': new_order})
|
||||
stock_move_obj.create(cr, uid, {
|
||||
'product_qty': qty ,
|
||||
'product_uos_qty': uom_obj._compute_qty(cr, uid, qty ,line.product_id.uom_id.id),
|
||||
'picking_id': new_picking,
|
||||
'product_uom': line.product_id.uom_id.id,
|
||||
'location_id': location_id,
|
||||
'product_id': line.product_id.id,
|
||||
'location_dest_id': stock_dest_id,
|
||||
'name': '%s (return)' %order_id.name,
|
||||
'date': date_cur
|
||||
})
|
||||
if qty != 0.0:
|
||||
line_obj.copy(cr, uid, line.id, {'qty': -qty, 'order_id': new_order})
|
||||
statementl_obj.create(cr, uid, {
|
||||
'name': 'Refund %s'%order_id.name,
|
||||
'statement_id': order_id.statement_ids[0].statement_id.id,
|
||||
@@ -290,15 +219,12 @@ class add_product(osv.osv_memory):
|
||||
for order_id in order_obj.browse(cr, uid, [active_id], context=context):
|
||||
prod=data['product_id']
|
||||
qty=data['quantity']
|
||||
prop_ids = property_obj.search(cr, uid, [('name', '=', 'property_stock_customer')])
|
||||
val = property_obj.browse(cr, uid, prop_ids[0]).value_reference
|
||||
stock_dest_id = property_obj.get(cr, uid, 'property_stock_customer', 'res.partner', context=context).id
|
||||
cr.execute("SELECT s.id FROM stock_location s, stock_warehouse w "
|
||||
"WHERE w.lot_stock_id=s.id AND w.id=%s ",
|
||||
(order_id.shop_id.warehouse_id.id,))
|
||||
res=cr.fetchone()
|
||||
location_id=res and res[0] or None
|
||||
stock_dest_id = val.id
|
||||
|
||||
prod_id=prod_obj.browse(cr, uid, prod, context=context)
|
||||
new_picking=picking_obj.create(cr, uid, {
|
||||
'name':'%s (Added)' %order_id.name,
|
||||
@@ -357,14 +283,12 @@ class add_product(osv.osv_memory):
|
||||
order_obj.add_product(cr, uid, active_ids[0], self_data['product_id'], self_data['quantity'], context=context)
|
||||
|
||||
for order_id in order_obj.browse(cr, uid, active_ids, context=context):
|
||||
prop_ids =property_obj.search(cr, uid, [('name', '=', 'property_stock_customer')])
|
||||
val = property_obj.browse(cr, uid, prop_ids[0]).value_reference
|
||||
stock_dest_id = property_obj.get(cr, uid, 'property_stock_customer', 'res.partner', context=context).id
|
||||
cr.execute("SELECT s.id FROM stock_location s, stock_warehouse w "
|
||||
" WHERE w.lot_stock_id=s.id AND w.id=%s ",
|
||||
(order_id.shop_id.warehouse_id.id,))
|
||||
res=cr.fetchone()
|
||||
location_id=res and res[0] or None
|
||||
stock_dest_id = val.id
|
||||
|
||||
order_obj.write(cr,uid,[order_id.id],{'type_rec':'Exchange'})
|
||||
if order_id.invoice_id:
|
||||
|
||||
@@ -1,13 +1,58 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<record id="action_view_pos_return" model="ir.actions.act_window">
|
||||
<field name="name">Return lines</field>
|
||||
<field name="res_model">pos.return</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
<data>
|
||||
<record id="pos_return_form" model="ir.ui.view">
|
||||
<field name="name">pos.return</field>
|
||||
<field name="model">pos.return</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Return lines">
|
||||
<label string=" Enter the quantities which you want to return." colspan="4"/>
|
||||
<separator colspan="4"/>
|
||||
<field name="pos_moves_ids" colspan="4" nolabel="1" mode="tree,form" width="550" height="200" >
|
||||
</field>
|
||||
<newline/>
|
||||
<separator colspan="4"/>
|
||||
<button icon='gtk-cancel' special="cancel" string="Cancel" />
|
||||
<button icon='gtk-ok' name= "create_returns" string="Return With Exchange" type="object"/>
|
||||
<button icon='gtk-ok' name="create_returns2" string="Refund Without Exchange" type="object"/>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_view_pos_return" model="ir.actions.act_window">
|
||||
<field name="name">Return lines</field>
|
||||
<field name="res_model">pos.return</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
|
||||
<record id="pos_return_tree_in" model="ir.ui.view">
|
||||
<field name="name">pos.return.memory</field>
|
||||
<field name="model">pos.return.memory</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree editable="bottom" string="Return Product">
|
||||
<field name="product_id" />
|
||||
<field name="quantity" />
|
||||
<field name="line_id" invisible="1"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="pos_return_form_in" model="ir.ui.view">
|
||||
<field name="name">pos.return.memory</field>
|
||||
<field name="model">pos.return.memory</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form>
|
||||
<field name="product_id" />
|
||||
<field name="quantity" />
|
||||
<field name="line_id" invisible="1"/>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
</data>
|
||||
</openerp>
|
||||
|
||||
@@ -691,7 +691,7 @@ class stock_picking(osv.osv):
|
||||
if res:
|
||||
picking_obj = self.browse(cr, uid, res, context=context)
|
||||
for move in picking_obj.move_lines:
|
||||
move_obj.write(cr, uid, [move.id], {'tracking_id': False,'prodlot_id':False})
|
||||
move_obj.write(cr, uid, [move.id], {'tracking_id': False,'prodlot_id':False, 'move_history_ids2': [(6, 0, [])], 'move_history_ids': [(6, 0, [])]})
|
||||
return res
|
||||
|
||||
def onchange_partner_in(self, cr, uid, context=None, partner_id=None):
|
||||
@@ -1623,6 +1623,7 @@ class stock_move(osv.osv):
|
||||
if default is None:
|
||||
default = {}
|
||||
default = default.copy()
|
||||
default.update({'move_history_ids2': [], 'move_history_ids': []})
|
||||
return super(stock_move, self).copy(cr, uid, id, default, context=context)
|
||||
|
||||
def _auto_init(self, cursor, context=None):
|
||||
|
||||
@@ -68,7 +68,7 @@ class stock_partial_picking(osv.osv_memory):
|
||||
if m.state in ('done', 'cancel'):
|
||||
continue
|
||||
result.append(self.__create_partial_picking_memory(m, pick_type))
|
||||
|
||||
|
||||
if 'product_moves_in' in fields:
|
||||
res.update({'product_moves_in': result})
|
||||
if 'product_moves_out' in fields:
|
||||
|
||||
@@ -25,9 +25,26 @@ import time
|
||||
from osv import osv,fields
|
||||
from tools.translate import _
|
||||
|
||||
class stock_return_picking_memory(osv.osv_memory):
|
||||
_name = "stock.return.picking.memory"
|
||||
_rec_name = 'product_id'
|
||||
_columns = {
|
||||
'product_id' : fields.many2one('product.product', string="Product", required=True),
|
||||
'quantity' : fields.float("Quantity", required=True),
|
||||
'wizard_id' : fields.many2one('stock.return.picking', string="Wizard"),
|
||||
'move_id' : fields.many2one('stock.move', "Move"),
|
||||
}
|
||||
|
||||
stock_return_picking_memory()
|
||||
|
||||
|
||||
class stock_return_picking(osv.osv_memory):
|
||||
_name = 'stock.return.picking'
|
||||
_description = 'Return Picking'
|
||||
_columns = {
|
||||
'product_return_moves' : fields.one2many('stock.return.picking.memory', 'wizard_id', 'Moves'),
|
||||
'invoice_state': fields.selection([('2binvoiced', 'To be refunded/invoiced'), ('none', 'No invoicing')], 'Invoicing',required=True),
|
||||
}
|
||||
|
||||
def default_get(self, cr, uid, fields, context=None):
|
||||
"""
|
||||
@@ -39,6 +56,7 @@ class stock_return_picking(osv.osv_memory):
|
||||
@param context: A standard dictionary
|
||||
@return: A dictionary with default values for all field in ``fields``
|
||||
"""
|
||||
result1 = []
|
||||
if context is None:
|
||||
context = {}
|
||||
res = super(stock_return_picking, self).default_get(cr, uid, fields, context=context)
|
||||
@@ -48,13 +66,16 @@ class stock_return_picking(osv.osv_memory):
|
||||
if pick:
|
||||
if 'invoice_state' in fields:
|
||||
if pick.invoice_state=='invoiced':
|
||||
res['invoice_state'] = '2binvoiced'
|
||||
res.update({'invoice_state': '2binvoiced'})
|
||||
else:
|
||||
res['invoice_state'] = 'none'
|
||||
res.update({'invoice_state': 'none'})
|
||||
return_history = self.get_return_history(cr, uid, record_id, context)
|
||||
for line in pick.move_lines:
|
||||
return_id = 'return%s'%(line.id)
|
||||
if return_id in fields:
|
||||
res[return_id] = line.product_qty
|
||||
qty = line.product_qty - return_history[line.id]
|
||||
if qty > 0:
|
||||
result1.append({'product_id': line.product_id.id, 'quantity': qty,'move_id':line.id})
|
||||
if 'product_return_moves' in fields:
|
||||
res.update({'product_return_moves': result1})
|
||||
return res
|
||||
|
||||
def view_init(self, cr, uid, fields_list, context=None):
|
||||
@@ -75,62 +96,34 @@ class stock_return_picking(osv.osv_memory):
|
||||
pick = pick_obj.browse(cr, uid, record_id, context=context)
|
||||
if pick.state not in ['done','confirmed','assigned']:
|
||||
raise osv.except_osv(_('Warning !'), _("You may only return pickings that are Confirmed, Available or Done!"))
|
||||
return_history = {}
|
||||
valid_lines = 0
|
||||
for m in [line for line in pick.move_lines]:
|
||||
if m.state == 'done':
|
||||
return_history[m.id] = 0
|
||||
for rec in m.move_history_ids2:
|
||||
return_history[m.id] += (rec.product_qty * rec.product_uom.factor)
|
||||
if m.product_qty * m.product_uom.factor >= return_history[m.id]:
|
||||
return_history = self.get_return_history(cr, uid, record_id, context)
|
||||
for m in pick.move_lines:
|
||||
if m.product_qty * m.product_uom.factor > return_history[m.id]:
|
||||
valid_lines += 1
|
||||
if 'return%s'%(m.id) not in self._columns:
|
||||
self._columns['return%s'%(m.id)] = fields.float(string=m.name, required=True)
|
||||
if 'invoice_state' not in self._columns:
|
||||
self._columns['invoice_state'] = fields.selection([('2binvoiced', 'To be refunded/invoiced'), ('none', 'No invoicing')], string='Invoicing', required=True)
|
||||
if not valid_lines:
|
||||
raise osv.except_osv(_('Warning !'), _("There are no products to return (only lines in Done state and not fully returned yet can be returned)!"))
|
||||
return res
|
||||
|
||||
def fields_view_get(self, cr, uid, view_id=None, view_type='form',
|
||||
context=None, toolbar=False, submenu=False):
|
||||
"""
|
||||
Changes the view dynamically
|
||||
|
||||
def get_return_history(self, cr, uid, pick_id, context=None):
|
||||
"""
|
||||
Get return_history.
|
||||
@param self: The object pointer.
|
||||
@param cr: A database cursor
|
||||
@param uid: ID of the user currently logged in
|
||||
@param pick_id: Picking id
|
||||
@param context: A standard dictionary
|
||||
@return: New arch of view.
|
||||
@return: A dictionary which of values.
|
||||
"""
|
||||
res = super(stock_return_picking, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar,submenu=False)
|
||||
record_id = context and context.get('active_id', False)
|
||||
active_model = context.get('active_model')
|
||||
if active_model != 'stock.picking':
|
||||
return res
|
||||
if record_id:
|
||||
pick_obj = self.pool.get('stock.picking')
|
||||
pick = pick_obj.browse(cr, uid, record_id)
|
||||
return_history = {}
|
||||
res['fields'].clear()
|
||||
arch_lst=['<?xml version="1.0"?>', '<form string="%s">' % _('Return lines'), '<label string="%s" colspan="4"/>' % _('Provide the quantities of the returned products.')]
|
||||
for m in pick.move_lines:
|
||||
pick_obj = self.pool.get('stock.picking')
|
||||
pick = pick_obj.browse(cr, uid, pick_id, context=context)
|
||||
return_history = {}
|
||||
for m in pick.move_lines:
|
||||
if m.state == 'done':
|
||||
return_history[m.id] = 0
|
||||
for rec in m.move_history_ids2:
|
||||
return_history[m.id] += rec.product_qty
|
||||
quantity = m.product_qty
|
||||
if m.state=='done' and quantity > return_history[m.id]:
|
||||
arch_lst.append('<field name="return%s"/>\n<newline/>' % (m.id,))
|
||||
res['fields']['return%s' % m.id]={'string':m.name, 'type':'float', 'required':True}
|
||||
res.setdefault('returns', []).append(m.id)
|
||||
arch_lst.append('<field name="invoice_state"/>\n<newline/>')
|
||||
res['fields']['invoice_state']={'string':_('Invoicing'), 'type':'selection','required':True, 'selection':[('2binvoiced', _('To be refunded/invoiced')), ('none', _('No invoicing'))]}
|
||||
arch_lst.append('<group col="2" colspan="4">')
|
||||
arch_lst.append('<button icon="gtk-cancel" special="cancel" string="Cancel" />')
|
||||
arch_lst.append('<button name="create_returns" string="Return" colspan="1" type="object" icon="gtk-apply" />')
|
||||
arch_lst.append('</group>')
|
||||
arch_lst.append('</form>')
|
||||
res['arch'] = '\n'.join(arch_lst)
|
||||
return res
|
||||
return_history[m.id] += (rec.product_qty * rec.product_uom.factor)
|
||||
return return_history
|
||||
|
||||
def create_returns(self, cr, uid, ids, context=None):
|
||||
"""
|
||||
@@ -148,48 +141,49 @@ class stock_return_picking(osv.osv_memory):
|
||||
move_obj = self.pool.get('stock.move')
|
||||
pick_obj = self.pool.get('stock.picking')
|
||||
uom_obj = self.pool.get('product.uom')
|
||||
data_obj = self.pool.get('stock.return.picking.memory')
|
||||
wf_service = netsvc.LocalService("workflow")
|
||||
|
||||
pick = pick_obj.browse(cr, uid, record_id, context=context)
|
||||
data = self.read(cr, uid, ids[0], context=context)
|
||||
new_picking = None
|
||||
date_cur = time.strftime('%Y-%m-%d %H:%M:%S')
|
||||
|
||||
set_invoice_state_to_none = True
|
||||
returned_lines = 0
|
||||
for move in pick.move_lines:
|
||||
if not new_picking:
|
||||
if pick.type=='out':
|
||||
new_type = 'in'
|
||||
elif pick.type=='in':
|
||||
new_type = 'out'
|
||||
else:
|
||||
new_type = 'internal'
|
||||
new_picking = pick_obj.copy(cr, uid, pick.id, {'name':'%s-return' % pick.name,
|
||||
'move_lines':[], 'state':'draft', 'type':new_type,
|
||||
'date':date_cur, 'invoice_state':data['invoice_state'],})
|
||||
|
||||
# Create new picking for returned products
|
||||
if pick.type=='out':
|
||||
new_type = 'in'
|
||||
elif pick.type=='in':
|
||||
new_type = 'out'
|
||||
else:
|
||||
new_type = 'internal'
|
||||
new_picking = pick_obj.copy(cr, uid, pick.id, {'name':'%s-return' % pick.name,
|
||||
'move_lines':[], 'state':'draft', 'type':new_type,
|
||||
'date':date_cur, 'invoice_state':data['invoice_state'],})
|
||||
|
||||
val_id = data['product_return_moves']
|
||||
for v in val_id:
|
||||
data_get = data_obj.read(cr, uid, v)
|
||||
mov_id = data_get['move_id']
|
||||
new_qty = data_get['quantity']
|
||||
move = move_obj.browse(cr, uid, mov_id, context=context)
|
||||
new_location=move.location_dest_id.id
|
||||
if move.state=='done':
|
||||
new_qty = data['return%s' % move.id]
|
||||
returned_qty = move.product_qty
|
||||
|
||||
for rec in move.move_history_ids2:
|
||||
returned_qty -= rec.product_qty
|
||||
|
||||
if returned_qty != new_qty:
|
||||
set_invoice_state_to_none = False
|
||||
|
||||
if new_qty:
|
||||
returned_lines += 1
|
||||
new_move=move_obj.copy(cr, uid, move.id, {
|
||||
'product_qty': new_qty,
|
||||
'product_uos_qty': uom_obj._compute_qty(cr, uid, move.product_uom.id,
|
||||
new_qty, move.product_uos.id),
|
||||
'picking_id':new_picking, 'state':'draft',
|
||||
'location_id':new_location, 'location_dest_id':move.location_id.id,
|
||||
'date':date_cur,})
|
||||
move_obj.write(cr, uid, [move.id], {'move_history_ids2':[(4,new_move)]})
|
||||
returned_qty = move.product_qty
|
||||
for rec in move.move_history_ids2:
|
||||
returned_qty -= rec.product_qty
|
||||
|
||||
if returned_qty != new_qty:
|
||||
set_invoice_state_to_none = False
|
||||
if new_qty:
|
||||
returned_lines += 1
|
||||
new_move=move_obj.copy(cr, uid, move.id, {
|
||||
'product_qty': new_qty,
|
||||
'product_uos_qty': uom_obj._compute_qty(cr, uid, move.product_uom.id,
|
||||
new_qty, move.product_uos.id),
|
||||
'picking_id':new_picking, 'state':'draft',
|
||||
'location_id':new_location, 'location_dest_id':move.location_id.id,
|
||||
'date':date_cur,})
|
||||
move_obj.write(cr, uid, [move.id], {'move_history_ids2':[(4,new_move)]})
|
||||
if not returned_lines:
|
||||
raise osv.except_osv(_('Warning !'), _("Please specify at least one non-zero quantity!"))
|
||||
|
||||
|
||||
@@ -9,5 +9,50 @@
|
||||
key2="client_action_multi"
|
||||
multi="True"
|
||||
id="act_stock_return_picking"/>
|
||||
</data>
|
||||
|
||||
<record id="stock_return_memory_tree_in" model="ir.ui.view">
|
||||
<field name="name">stock.return.picking.memory.tree</field>
|
||||
<field name="model">stock.return.picking.memory</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree editable="bottom" string="Product Moves">
|
||||
<field name="product_id" />
|
||||
<field name="quantity" />
|
||||
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="stock_return_memory_form_in" model="ir.ui.view">
|
||||
<field name="name">stock.return.picking.memory.from</field>
|
||||
<field name="model">stock.return.picking.memory</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form>
|
||||
<field name="product_id" />
|
||||
<field name="quantity" />
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_stock_return_picking_form" model="ir.ui.view">
|
||||
<field name="name">Return lines</field>
|
||||
<field name="model">stock.return.picking</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Return lines">
|
||||
<label string="Provide the quantities of the returned products." colspan="4"/>
|
||||
<separator string="" colspan="4"/>
|
||||
<field name="product_return_moves" nolabel="1" colspan="6"/>
|
||||
<field name="invoice_state" />
|
||||
<separator string="" colspan="4" />
|
||||
<group col="2" colspan="4">
|
||||
<button special="cancel" string="_Cancel" icon="gtk-cancel"/>
|
||||
<button name="create_returns" string="Return" colspan="1" type="object" icon="gtk-apply" />
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
|
||||
@@ -1,124 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
# 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/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from osv import osv, fields
|
||||
|
||||
class stock_split_move_line(osv.osv_memory):
|
||||
_name = 'stock.move.line.split'
|
||||
_description = "Split Moves"
|
||||
|
||||
def default_get(self, cr, uid, fields, context=None):
|
||||
""" To get default values for the object.
|
||||
@param self: The object pointer.
|
||||
@param cr: A database cursor
|
||||
@param uid: ID of the user currently logged in
|
||||
@param fields: List of fields for which we want default values
|
||||
@param context: A standard dictionary
|
||||
@return: A dictionary which of fields with values.
|
||||
"""
|
||||
if context is None:
|
||||
context = {}
|
||||
res = super(stock_split_move_line, self).default_get(cr, uid, fields, context=context)
|
||||
record_id = context and context.get('active_id', False) or False
|
||||
pick_obj = self.pool.get('stock.picking')
|
||||
pick = pick_obj.browse(cr, uid, record_id, context=context)
|
||||
for m in [line for line in pick.move_lines]:
|
||||
res['move%s'%(m.id)] = m.product_qty
|
||||
return res
|
||||
|
||||
def view_init(self, cr, uid, fields_list, context=None):
|
||||
""" Creates view dynamically and adding fields at runtime.
|
||||
@param self: The object pointer.
|
||||
@param cr: A database cursor
|
||||
@param uid: ID of the user currently logged in
|
||||
@param context: A standard dictionary
|
||||
@return: New arch of view with new columns.
|
||||
"""
|
||||
res = super(stock_split_move_line, self).view_init(cr, uid, fields_list, context=context)
|
||||
record_id = context and context.get('active_id', False) or False
|
||||
if record_id:
|
||||
pick_obj = self.pool.get('stock.picking')
|
||||
try:
|
||||
pick = pick_obj.browse(cr, uid, record_id, context=context)
|
||||
for m in [line for line in pick.move_lines]:
|
||||
if 'move%s' % m.id not in self._columns:
|
||||
self._columns['move%s' % m.id] = fields.float(string=m.product_id.name)
|
||||
except:
|
||||
return res
|
||||
return res
|
||||
|
||||
def fields_view_get(self, cr, uid, view_id=None, view_type='form',
|
||||
context=None, toolbar=False, submenu=False):
|
||||
""" Changes the view dynamically
|
||||
@param self: The object pointer.
|
||||
@param cr: A database cursor
|
||||
@param uid: ID of the user currently logged in
|
||||
@param context: A standard dictionary
|
||||
@return: New arch of view.
|
||||
"""
|
||||
res = super(stock_split_move_line, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar,submenu=False)
|
||||
record_id = context and context.get('active_id', False) or False
|
||||
assert record_id,'Active ID not found'
|
||||
pick_obj = self.pool.get('stock.picking')
|
||||
pick = pick_obj.browse(cr, uid, record_id, context=context)
|
||||
arch_lst = ['<?xml version="1.0"?>', '<form string="Split lines">', '<label string="Indicate here the quantity of the new line. A quantity of zero will not split the line." colspan="4"/>']
|
||||
for m in [line for line in pick.move_lines]:
|
||||
quantity = m.product_qty
|
||||
arch_lst.append('<field name="move%s" />\n<newline />' % (m.id,))
|
||||
res['fields']['move%s' % m.id] = {'string' : m.product_id.name, 'type' : 'float', 'required' : True}
|
||||
arch_lst.append('<group col="2" colspan="4">')
|
||||
arch_lst.append('<button icon="gtk-cancel" special="cancel" string="Cancel" />')
|
||||
arch_lst.append('<button name="split_lines" string="Split" colspan="1" type="object" icon="gtk-apply" />')
|
||||
arch_lst.append('</group>')
|
||||
arch_lst.append('</form>')
|
||||
res['arch'] = '\n'.join(arch_lst)
|
||||
return res
|
||||
|
||||
def split_lines(self, cr, uid, ids, context=None):
|
||||
""" Splits moves in quantity given in the wizard.
|
||||
@param self: The object pointer.
|
||||
@param cr: A database cursor
|
||||
@param uid: ID of the user currently logged in
|
||||
@param ids: List of ids selected
|
||||
@param context: A standard dictionary
|
||||
@return: A dictionary which of fields with values.
|
||||
"""
|
||||
if context is None:
|
||||
context = {}
|
||||
move_obj = self.pool.get('stock.move')
|
||||
record_id = context and context.get('active_id', False) or False
|
||||
pick_obj = self.pool.get('stock.picking')
|
||||
pick = pick_obj.browse(cr, uid, record_id, context=context)
|
||||
data = self.read(cr, uid, ids[0])
|
||||
for move in pick.move_lines:
|
||||
quantity = data['move%s' % move.id]
|
||||
if 0 < quantity < move.product_qty:
|
||||
new_qty = move.product_qty - quantity
|
||||
new_uos_qty = new_qty / move.product_qty * move.product_uos_qty
|
||||
new_obj = move_obj.copy(cr, uid, move.id, {'product_qty' : new_qty, 'product_uos_qty': new_uos_qty, 'state':move.state})
|
||||
uos_qty = quantity / move.product_qty * move.product_uos_qty
|
||||
move_obj.write(cr, uid, [move.id], {'product_qty' : quantity, 'product_uos_qty': uos_qty})
|
||||
return {'type': 'ir.actions.act_window_close'}
|
||||
|
||||
stock_split_move_line()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<!-- Split Moves -->
|
||||
|
||||
<record id="act_split_moves" model="ir.actions.act_window">
|
||||
<field name="name">Split Moves</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">stock.move.line.split</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
Reference in New Issue
Block a user