[IMP]: stock, mrp: Changed logic of track lots, Improvement in functions of split and consume

bzr revid: rpa@openerp.co.in-20100219134455-47etho3p4i67dszw
This commit is contained in:
rpa (Open ERP)
2010-02-19 19:14:55 +05:30
parent 171e22208c
commit 80181ea389
9 changed files with 129 additions and 166 deletions
-1
View File
@@ -60,7 +60,6 @@
'security/ir.model.access.csv',
'mrp_workflow.xml',
'mrp_data.xml',
'wizard/wizard_split_in_lots.xml',
'mrp_view.xml',
'mrp_wizard.xml',
'mrp_report.xml',
+5 -5
View File
@@ -1354,10 +1354,10 @@ class StockMove(osv.osv):
for new in new_move:
production_obj.write(cr, uid, production_ids, {'move_lines': [(4, new)]})
move_obj.action_done(cr, uid, [new])
return new_move
return {}
def split_moves(self, cr, uid, ids, datas, context=None):
new_move = super(StockMove, self).split_moves(cr, uid, ids, datas, context=context)
def consume_moves(self, cr, uid, ids, product_qty, location_id, context=None):
new_move = super(StockMove, self).consume_moves(cr, uid, ids, product_qty, location_id, context=context)
if new_move:
production_obj = self.pool.get('mrp.production')
move_obj = self.pool.get('stock.move')
@@ -1366,8 +1366,8 @@ class StockMove(osv.osv):
production_obj.write(cr, uid, production_ids, {'move_lines': [(4, new_move)]})
return {}
def scrap_moves(self, cr, uid, ids, datas, context=None):
new_move = super(StockMove, self).scrap_moves(cr, uid, ids, datas, context=context)
def scrap_moves(self, cr, uid, ids, product_qty, location_id, context=None):
new_move = super(StockMove, self).scrap_moves(cr, uid, ids, product_qty, location_id, context=context)
if new_move:
production_obj = self.pool.get('mrp.production')
move_obj = self.pool.get('stock.move')
+1 -6
View File
@@ -513,13 +513,8 @@
<field name="state" invisible="1" />
<field name="location_id" readonly="1"/>
<field name="prodlot_id" />
<!-- <button-->
<!-- name="%(stock.track_line)d"-->
<!-- string="Split in production lots"-->
<!-- type="action" icon="gtk-justify-fill"-->
<!-- states="done,cancel" />-->
<button
name="%(mrp.split_in_lots)d"
name="%(stock.track_line)d"
string="Split in production lots"
type="action" icon="gtk-justify-fill"
states="done,cancel" />
-1
View File
@@ -27,7 +27,6 @@ import wizard_workcenter_load
import wizard_track_prod
import wizard_change_production_qty
import make_procurement
import wizard_split_in_lots
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
-56
View File
@@ -1,56 +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 fields, osv
from tools.translate import _
import re
import time
import tools
class spilt_in_lot(osv.osv_memory):
_name = "spilt.in.lot"
_description = "Split in lots"
_columns = {
'product_id': fields.many2one('product.product', 'Product', required=True, select=True),
'line_ids': fields.one2many('track.lines', 'lot_id', 'Lots Number')
}
def _get_product_id(self, cr, uid, context):
move = self.pool.get('stock.move').browse(cr, uid, context['active_id'], context=context)
return move.product_id.id
_defaults = {
'product_id': _get_product_id,
}
spilt_in_lot()
class track_lines(osv.osv_memory):
_name = "track.lines"
_description = "Track lines"
_columns = {
'name': fields.char('Tracking serial', size=64),
'lot_id': fields.many2one('spilt.in.lot', 'Lot')
}
track_lines()
@@ -1,41 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_split_in_lots" model="ir.ui.view">
<field name="name">Split in lots</field>
<field name="model">spilt.in.lot</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Split in lots">
<field name="product_id" colspan="4"/>
<newline/>
<field name="line_ids" colspan="4" nolabel="1">
<tree string="Lots Number" editable="top">
<field name="name" string="Lots"/>
</tree>
<form string="Lots Number">
<field name="name" string="Lots"/>
</form>
</field>
<separator string="" colspan="4" />
<label string="" colspan="2" />
<button icon='gtk-cancel' special="cancel"
string="Cancel" />
<button name="track_lines" string="Ok"
type="object" icon="gtk-ok" />
</form>
</field>
</record>
<record id="split_in_lots" model="ir.actions.act_window">
<field name="name">Split in lots</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">spilt.in.lot</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
</data>
</openerp>
+35 -50
View File
@@ -1493,61 +1493,46 @@ class stock_move(osv.osv):
return super(stock_move, self).unlink(
cr, uid, ids, context=context)
def _track_lines(self, cr, uid, ids, data, context=None):
move_obj = self.pool.get('stock.move').browse(cr, uid, ids)
def _track_lines(self, cr, uid, ids, lines, context=None):
prodlot_obj = self.pool.get('stock.production.lot')
ir_sequence_obj = self.pool.get('ir.sequence')
sequence = ir_sequence_obj.get(cr, uid, 'stock.lot.serial')
if not sequence:
raise wizard.except_wizard(_('Error!'), _('No production sequence defined'))
if data['tracking_prefix']:
sequence=data['tracking_prefix']+'/'+(sequence or '')
move = self.browse(cr, uid, [ids])[0]
quantity=data['quantity']
if quantity <= 0 or move.product_qty == 0:
return {}
uos_qty=quantity/move.product_qty*move.product_uos_qty
quantity_rest = move.product_qty%quantity
uos_qty_rest = quantity_rest/move.product_qty*move.product_uos_qty
update_val = {
'product_qty': quantity,
'product_uos_qty': uos_qty,
}
move_qty = move.product_qty
quantity_rest = move.product_qty
new_move = []
for idx in range(int(move.product_qty//quantity)):
if idx:
current_move = self.copy(cr, uid, move.id, {'state': move.state})
new_move.append(current_move)
else:
current_move = move.id
new_prodlot = prodlot_obj.create(cr, uid, {'name': sequence, 'ref': '%d'%idx}, {'product_id': move.product_id.id})
update_val['prodlot_id'] = new_prodlot
self.write(cr, uid, [current_move], update_val)
for line in lines:
quantity = line['quantity']
sequence = line['tracking_num']
if quantity <= 0 or move_qty == 0:
continue
quantity_rest -= quantity
uos_qty = quantity / move_qty * move.product_uos_qty
uos_qty_rest = quantity_rest / move_qty * move.product_uos_qty
default_val = {
'product_qty': quantity,
'product_uos_qty': uos_qty,
'state': move.state
}
current_move = self.copy(cr, uid, move.id, default_val)
new_move.append(current_move)
new_prodlot = prodlot_obj.create(cr, uid, {'name': sequence,
'ref': '%d'%int(move_qty//quantity)},
{'product_id': move.product_id.id})
self.write(cr, uid, [current_move], {'prodlot_id': new_prodlot})
if quantity_rest > 0:
idx = int(move.product_qty//quantity)
update_val['product_qty']=quantity_rest
update_val['product_uos_qty']=uos_qty_rest
if idx:
current_move = self.copy(cr, uid, move.id, {'state': move.state})
new_move.append(current_move)
else:
current_move = move.id
new_prodlot = prodlot_obj.create(cr, uid, {'name': sequence, 'ref': '%d'%idx}, {'product_id': move.product_id.id})
update_val['prodlot_id'] = new_prodlot
self.write(cr, uid, [current_move], update_val)
new_prodlot = prodlot_obj.create(cr, uid, {'name': sequence + '/', 'ref': '%d' % int(move_qty//quantity)}, {'product_id': move.product_id.id})
update_val= {'prodlot_id': new_prodlot,
'product_qty': quantity_rest,
'product_uos_qty': uos_qty_rest
}
self.write(cr, uid, [move.id], update_val)
return new_move
def split_moves(self, cr, uid, ids, datas, context=None):
def consume_moves(self, cr, uid, ids, product_qty, location_id, context=None):
new_move = None
if not context:
context = {}
qty = datas['product_qty']
qty = product_qty
if qty <= 0:
raise wizard.except_wizard(_('Warning!'), _('Please provide Proper Quantity !'))
@@ -1563,7 +1548,7 @@ class stock_move(osv.osv):
vals = {
'product_qty' : qty,
'product_uos_qty': qty,
'location_id': datas['location_id'],
'location_id': location_id
}
track = move.product_id.track_production
self.write(cr, uid, move.id, vals)
@@ -1579,9 +1564,9 @@ class stock_move(osv.osv):
new_move = self.copy(cr, uid, move.id, default=defaults)
return new_move
def scrap_moves(self, cr, uid, ids, datas, context=None):
def scrap_moves(self, cr, uid, ids, product_qty, location_id, context=None):
new_move = None
qty = datas['product_qty']
qty = product_qty
if qty <= 0:
raise wizard.except_wizard(_('Warning!'), _('Please provide Proper Quantity !'))
@@ -1598,7 +1583,7 @@ class stock_move(osv.osv):
vals = {
'product_qty': qty,
'state': move.state,
'location_dest_id': datas['location_id']
'location_dest_id': location_id
}
self.write(cr, uid, ids, vals)
+39 -2
View File
@@ -20,7 +20,7 @@
</field>
</record>
<record id="track_line" model="ir.actions.act_window">
<record id="track_line_old" model="ir.actions.act_window">
<field name="name">Tracking a move</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">stock.move.track</field>
@@ -49,7 +49,7 @@
<group col="2" colspan="1">
<button icon='gtk-cancel' special="cancel"
string="Cancel" />
<button name="move_consume" string="Ok"
<button name="do_move_consume" string="Ok"
colspan="1" type="object" icon="gtk-ok" />
</group>
</form>
@@ -98,5 +98,42 @@
<field name="target">new</field>
</record>
<record id="view_split_in_lots" model="ir.ui.view">
<field name="name">Split in lots</field>
<field name="model">spilt.in.lot</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Split in lots">
<field name="product_id" colspan="4"/>
<newline/>
<field name="line_ids" colspan="4" nolabel="1">
<tree string="Lots Number" editable="top">
<field name="name" string="Lots"/>
<field name="quantity" />
</tree>
<form string="Lots Number">
<field name="name" string="Lots"/>
<field name="quantity" />
</form>
</field>
<separator string="" colspan="4" />
<label string="" colspan="2" />
<button icon='gtk-cancel' special="cancel"
string="Cancel" />
<button name="split_lot" string="Ok"
type="object" icon="gtk-ok" />
</form>
</field>
</record>
<record id="track_line" model="ir.actions.act_window">
<field name="name">Split in lots</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">spilt.in.lot</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
</data>
</openerp>
+49 -4
View File
@@ -80,10 +80,12 @@ class stock_move_consume(osv.osv_memory):
'location_id': _get_location_id
}
def move_consume(self, cr, uid, ids, context={}):
def do_move_consume(self, cr, uid, ids, context={}):
datas = self.read(cr, uid, ids)[0]
move_obj = self.pool.get('stock.move')
move_obj.split_moves(cr, uid, context['active_id'], datas, context=context)
move_obj.consume_moves(cr, uid, context['active_id'],
datas['product_qty'], datas['location_id'],
context=context)
return {}
stock_move_consume()
@@ -101,7 +103,50 @@ class stock_move_scrap(osv.osv_memory):
def move_scrap(self, cr, uid, ids, context={}):
datas = self.read(cr, uid, ids)[0]
move_obj = self.pool.get('stock.move')
move_obj.scrap_moves(cr, uid, context['active_id'], datas, context=context)
move_obj.scrap_moves(cr, uid, context['active_id'],
datas['product_qty'], datas['location_id'],
context=context)
return {}
stock_move_scrap()
stock_move_scrap()
class spilt_in_lot(osv.osv_memory):
_name = "spilt.in.lot"
_description = "Split in lots"
_columns = {
'product_id': fields.many2one('product.product', 'Product', required=True, select=True),
'line_ids': fields.one2many('track.lines', 'lot_id', 'Lots Number')
}
def _get_product_id(self, cr, uid, context):
move = self.pool.get('stock.move').browse(cr, uid, context['active_id'], context=context)
return move.product_id.id
_defaults = {
'product_id': _get_product_id,
}
def split_lot(self, cr, uid, ids, context=None):
datas = self.read(cr, uid, ids)[0]
lines = []
for line in self.pool.get('track.lines').browse(cr, uid, datas.get('line_ids', [])):
lines.append({'tracking_num': line.name, 'quantity': line.quantity})
move_obj = self.pool.get('stock.move')
move_obj._track_lines(cr, uid, context['active_id'], lines, context=context)
return {}
spilt_in_lot()
class track_lines(osv.osv_memory):
_name = "track.lines"
_description = "Track lines"
_columns = {
'name': fields.char('Tracking serial', size=64),
'quantity': fields.integer('Quantity'),
'lot_id': fields.many2one('spilt.in.lot', 'Lot')
}
track_lines()