[IMP] stock, mrp: code improve on scrap, consume, split line
bzr revid: hmo@tinyerp.com-20100317075605-7md35k8okenczlg9
This commit is contained in:
parent
3c3b63918b
commit
aa2f699167
|
@ -20,6 +20,7 @@
|
|||
##############################################################################
|
||||
|
||||
import mrp
|
||||
import stock
|
||||
import installer
|
||||
import wizard
|
||||
import report
|
||||
|
|
|
@ -794,15 +794,6 @@ class mrp_production(osv.osv):
|
|||
|
||||
mrp_production()
|
||||
|
||||
|
||||
class stock_move(osv.osv):
|
||||
_name = 'stock.move'
|
||||
_inherit = 'stock.move'
|
||||
_columns = {
|
||||
'production_id': fields.many2one('mrp.production', 'Production', select=True),
|
||||
}
|
||||
stock_move()
|
||||
|
||||
class mrp_production_workcenter_line(osv.osv):
|
||||
_name = 'mrp.production.workcenter.line'
|
||||
_description = 'Work Orders'
|
||||
|
@ -1240,202 +1231,5 @@ class mrp_procurement(osv.osv):
|
|||
self._procure_orderpoint_confirm(cr, uid, automatic=automatic,\
|
||||
use_new_cursor=use_new_cursor, context=context)
|
||||
mrp_procurement()
|
||||
|
||||
|
||||
class stock_warehouse_orderpoint(osv.osv):
|
||||
_name = "stock.warehouse.orderpoint"
|
||||
_description = "Orderpoint minimum rule"
|
||||
_columns = {
|
||||
'name': fields.char('Name', size=32, required=True),
|
||||
'active': fields.boolean('Active', help="If the active field is set to true, it will allow you to hide the orderpoint without removing it."),
|
||||
'logic': fields.selection([('max','Order to Max'),('price','Best price (not yet active!)')], 'Reordering Mode', required=True),
|
||||
'warehouse_id': fields.many2one('stock.warehouse', 'Warehouse', required=True),
|
||||
'location_id': fields.many2one('stock.location', 'Location', required=True),
|
||||
'product_id': fields.many2one('product.product', 'Product', required=True, domain=[('type','=','product')]),
|
||||
'product_uom': fields.many2one('product.uom', 'Product UOM', required=True ),
|
||||
'product_min_qty': fields.float('Min Quantity', required=True,
|
||||
help="When the virtual stock goes belong the Min Quantity, Open ERP generates "\
|
||||
"a requisition to bring the virtual stock to the Max Quantity."),
|
||||
'product_max_qty': fields.float('Max Quantity', required=True,
|
||||
help="When the virtual stock goes belong the Min Quantity, Open ERP generates "\
|
||||
"a requisition to bring the virtual stock to the Max Quantity."),
|
||||
'qty_multiple': fields.integer('Qty Multiple', required=True,
|
||||
help="The requisition quantity will by rounded up to this multiple."),
|
||||
'procurement_id': fields.many2one('mrp.procurement', 'Latest Requisition'),
|
||||
'company_id': fields.many2one('res.company','Company',required=True),
|
||||
}
|
||||
_defaults = {
|
||||
'active': lambda *a: 1,
|
||||
'logic': lambda *a: 'max',
|
||||
'qty_multiple': lambda *a: 1,
|
||||
'name': lambda x,y,z,c: x.pool.get('ir.sequence').get(y,z,'mrp.warehouse.orderpoint') or '',
|
||||
'product_uom': lambda sel, cr, uid, context: context.get('product_uom', False),
|
||||
'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'stock.warehouse.orderpoint', context=c)
|
||||
}
|
||||
def onchange_warehouse_id(self, cr, uid, ids, warehouse_id, context={}):
|
||||
if warehouse_id:
|
||||
w=self.pool.get('stock.warehouse').browse(cr,uid,warehouse_id, context)
|
||||
v = {'location_id':w.lot_stock_id.id}
|
||||
return {'value': v}
|
||||
return {}
|
||||
def onchange_product_id(self, cr, uid, ids, product_id, context={}):
|
||||
if product_id:
|
||||
prod=self.pool.get('product.product').browse(cr,uid,product_id)
|
||||
v = {'product_uom':prod.uom_id.id}
|
||||
return {'value': v}
|
||||
return {}
|
||||
def copy(self, cr, uid, id, default=None,context={}):
|
||||
if not default:
|
||||
default = {}
|
||||
default.update({
|
||||
'name': self.pool.get('ir.sequence').get(cr, uid, 'mrp.warehouse.orderpoint') or '',
|
||||
})
|
||||
return super(stock_warehouse_orderpoint, self).copy(cr, uid, id, default, context)
|
||||
stock_warehouse_orderpoint()
|
||||
|
||||
|
||||
class StockMove(osv.osv):
|
||||
_inherit = 'stock.move'
|
||||
_columns = {
|
||||
'procurements': fields.one2many('mrp.procurement', 'move_id', 'Requisitions'),
|
||||
}
|
||||
def copy(self, cr, uid, id, default=None, context=None):
|
||||
default = default or {}
|
||||
default['procurements'] = []
|
||||
return super(StockMove, self).copy(cr, uid, id, default, context)
|
||||
|
||||
def _action_explode(self, cr, uid, move, context={}):
|
||||
if move.product_id.supply_method=='produce' and move.product_id.procure_method=='make_to_order':
|
||||
bis = self.pool.get('mrp.bom').search(cr, uid, [
|
||||
('product_id','=',move.product_id.id),
|
||||
('bom_id','=',False),
|
||||
('type','=','phantom')])
|
||||
if bis:
|
||||
factor = move.product_qty
|
||||
bom_point = self.pool.get('mrp.bom').browse(cr, uid, bis[0])
|
||||
res = self.pool.get('mrp.bom')._bom_explode(cr, uid, bom_point, factor, [])
|
||||
dest = move.product_id.product_tmpl_id.property_stock_production.id
|
||||
state = 'confirmed'
|
||||
if move.state=='assigned':
|
||||
state='assigned'
|
||||
for line in res[0]:
|
||||
valdef = {
|
||||
'picking_id': move.picking_id.id,
|
||||
'product_id': line['product_id'],
|
||||
'product_uom': line['product_uom'],
|
||||
'product_qty': line['product_qty'],
|
||||
'product_uos': line['product_uos'],
|
||||
'product_uos_qty': line['product_uos_qty'],
|
||||
'move_dest_id': move.id,
|
||||
'state': state,
|
||||
'name': line['name'],
|
||||
'location_dest_id': dest,
|
||||
'move_history_ids': [(6,0,[move.id])],
|
||||
'move_history_ids2': [(6,0,[])],
|
||||
'procurements': [],
|
||||
}
|
||||
mid = self.pool.get('stock.move').copy(cr, uid, move.id, default=valdef)
|
||||
prodobj = self.pool.get('product.product').browse(cr, uid, line['product_id'], context=context)
|
||||
proc_id = self.pool.get('mrp.procurement').create(cr, uid, {
|
||||
'name': (move.picking_id.origin or ''),
|
||||
'origin': (move.picking_id.origin or ''),
|
||||
'date_planned': move.date_planned,
|
||||
'product_id': line['product_id'],
|
||||
'product_qty': line['product_qty'],
|
||||
'product_uom': line['product_uom'],
|
||||
'product_uos_qty': line['product_uos'] and line['product_uos_qty'] or False,
|
||||
'product_uos': line['product_uos'],
|
||||
'location_id': move.location_id.id,
|
||||
'procure_method': prodobj.procure_method,
|
||||
'move_id': mid,
|
||||
'company_id': line['company_id'],
|
||||
})
|
||||
wf_service = netsvc.LocalService("workflow")
|
||||
wf_service.trg_validate(uid, 'mrp.procurement', proc_id, 'button_confirm', cr)
|
||||
self.pool.get('stock.move').write(cr, uid, [move.id], {
|
||||
'location_id': move.location_dest_id.id,
|
||||
'auto_validate': True,
|
||||
'picking_id': False,
|
||||
'location_id': dest,
|
||||
'state': 'waiting'
|
||||
})
|
||||
for m in self.pool.get('mrp.procurement').search(cr, uid, [('move_id','=',move.id)], context):
|
||||
wf_service = netsvc.LocalService("workflow")
|
||||
wf_service.trg_validate(uid, 'mrp.procurement', m, 'button_wait_done', cr)
|
||||
return True
|
||||
|
||||
|
||||
def consume_moves(self, cr, uid, ids, product_qty, location_id=False, location_dest_id=False, consume=True, context=None):
|
||||
res = []
|
||||
production_obj = self.pool.get('mrp.production')
|
||||
wf_service = netsvc.LocalService("workflow")
|
||||
for move in self.browse(cr, uid, ids):
|
||||
new_moves = super(StockMove, self).consume_moves(cr, uid, [move.id], product_qty, location_id, location_dest_id, consume, context=context)
|
||||
production_ids = production_obj.search(cr, uid, [('move_lines', 'in', [move.id])])
|
||||
for prod in production_obj.browse(cr, uid, production_ids, context=context):
|
||||
if prod.state == 'confirmed':
|
||||
production_obj.force_production(cr, uid, [prod.id])
|
||||
wf_service.trg_validate(uid, 'mrp.production', prod.id, 'button_produce', cr)
|
||||
for new_move in new_moves:
|
||||
production_obj.write(cr, uid, production_ids, {'move_lines': [(4, new_move)]})
|
||||
res.append(new_move)
|
||||
return res
|
||||
|
||||
def scrap_moves(self, cr, uid, ids, product_qty, location_id, context=None):
|
||||
res = []
|
||||
production_obj = self.pool.get('mrp.production')
|
||||
wf_service = netsvc.LocalService("workflow")
|
||||
for move in self.browse(cr, uid, ids):
|
||||
new_moves = super(StockMove, self).scrap_moves(cr, uid, [move.id], product_qty, location_id, context=context)
|
||||
production_ids = production_obj.search(cr, uid, [('move_lines', 'in', [move.id])])
|
||||
for prod_id in production_ids:
|
||||
wf_service.trg_validate(uid, 'mrp.production', prod_id, 'button_produce', cr)
|
||||
for new_move in new_moves:
|
||||
production_obj.write(cr, uid, production_ids, {'move_lines': [(4, new_move)]})
|
||||
res.append(new_move)
|
||||
return {}
|
||||
|
||||
StockMove()
|
||||
|
||||
|
||||
class StockPicking(osv.osv):
|
||||
_inherit = 'stock.picking'
|
||||
|
||||
def test_finnished(self, cursor, user, ids):
|
||||
wf_service = netsvc.LocalService("workflow")
|
||||
res = super(StockPicking, self).test_finnished(cursor, user, ids)
|
||||
for picking in self.browse(cursor, user, ids):
|
||||
for move in picking.move_lines:
|
||||
if move.state == 'done' and move.procurements:
|
||||
for procurement in move.procurements:
|
||||
wf_service.trg_validate(user, 'mrp.procurement',
|
||||
procurement.id, 'button_check', cursor)
|
||||
return res
|
||||
|
||||
#
|
||||
# Explode picking by replacing phantom BoMs
|
||||
#
|
||||
def action_explode(self, cr, uid, picks, *args):
|
||||
for move in self.pool.get('stock.move').browse(cr, uid, picks):
|
||||
self.pool.get('stock.move')._action_explode(cr, uid, move)
|
||||
return picks
|
||||
|
||||
StockPicking()
|
||||
|
||||
|
||||
class spilt_in_production_lot(osv.osv_memory):
|
||||
_inherit = "stock.move.split"
|
||||
def split(self, cr, uid, ids, move_ids, context=None):
|
||||
production_obj = self.pool.get('mrp.production')
|
||||
move_obj = self.pool.get('stock.move')
|
||||
res = []
|
||||
for move in move_obj.browse(cr, uid, move_ids, context=context):
|
||||
new_moves = super(spilt_in_production_lot, self).split(cr, uid, ids, move_ids, context=context)
|
||||
production_ids = production_obj.search(cr, uid, [('move_lines', 'in', [move.id])])
|
||||
for new_move in new_moves:
|
||||
production_obj.write(cr, uid, production_ids, {'move_lines': [(4, new_move)]})
|
||||
return res
|
||||
spilt_in_production_lot()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
|
|
|
@ -485,6 +485,7 @@
|
|||
<field name="product_id" />
|
||||
<field name="product_qty" string="Qty"/>
|
||||
<field name="product_uom" string="UOM"/>
|
||||
<field name="state" invisible="1"/>
|
||||
<button name="%(stock.move_consume)d"
|
||||
string="Consume Products" type="action"
|
||||
icon="gtk-go-forward" context="{'consume': True}"
|
||||
|
@ -504,6 +505,7 @@
|
|||
<field name="product_uom" readonly="1" string="UOM"/>
|
||||
<field name="location_dest_id" readonly="1" string="Destination"/>
|
||||
<field name="prodlot_id" />
|
||||
<field name="state" invisible="1"/>
|
||||
<button
|
||||
name="%(stock.track_line)d"
|
||||
string="Split in production lots"
|
||||
|
@ -536,6 +538,7 @@
|
|||
<field name="product_id" />
|
||||
<field name="product_qty" string="Qty"/>
|
||||
<field name="product_uom" string="UOM"/>
|
||||
<field name="state" invisible="1"/>
|
||||
<button name="%(stock.move_consume)d"
|
||||
string="Consume Products" type="action"
|
||||
icon="gtk-go-forward" context="{'consume': True}"
|
||||
|
@ -555,6 +558,7 @@
|
|||
<field name="product_uom" readonly="1" />
|
||||
<field name="location_id" readonly="1"/>
|
||||
<field name="prodlot_id" />
|
||||
<field name="state" invisible="1"/>
|
||||
<button name="%(stock.track_line)d"
|
||||
string="Split in production lots" type="action" icon="gtk-justify-fill" states="done,cancel"/>
|
||||
<button name="%(stock.move_scrap)d"
|
||||
|
|
|
@ -0,0 +1,225 @@
|
|||
# -*- 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 mx import DateTime
|
||||
from osv import fields
|
||||
from osv import osv
|
||||
from tools.translate import _
|
||||
import ir
|
||||
import netsvc
|
||||
import time
|
||||
|
||||
|
||||
class stock_warehouse_orderpoint(osv.osv):
|
||||
_name = "stock.warehouse.orderpoint"
|
||||
_description = "Orderpoint minimum rule"
|
||||
_columns = {
|
||||
'name': fields.char('Name', size=32, required=True),
|
||||
'active': fields.boolean('Active', help="If the active field is set to true, it will allow you to hide the orderpoint without removing it."),
|
||||
'logic': fields.selection([('max','Order to Max'),('price','Best price (not yet active!)')], 'Reordering Mode', required=True),
|
||||
'warehouse_id': fields.many2one('stock.warehouse', 'Warehouse', required=True),
|
||||
'location_id': fields.many2one('stock.location', 'Location', required=True),
|
||||
'product_id': fields.many2one('product.product', 'Product', required=True, domain=[('type','=','product')]),
|
||||
'product_uom': fields.many2one('product.uom', 'Product UOM', required=True ),
|
||||
'product_min_qty': fields.float('Min Quantity', required=True,
|
||||
help="When the virtual stock goes belong the Min Quantity, Open ERP generates "\
|
||||
"a requisition to bring the virtual stock to the Max Quantity."),
|
||||
'product_max_qty': fields.float('Max Quantity', required=True,
|
||||
help="When the virtual stock goes belong the Min Quantity, Open ERP generates "\
|
||||
"a requisition to bring the virtual stock to the Max Quantity."),
|
||||
'qty_multiple': fields.integer('Qty Multiple', required=True,
|
||||
help="The requisition quantity will by rounded up to this multiple."),
|
||||
'procurement_id': fields.many2one('mrp.procurement', 'Latest Requisition'),
|
||||
'company_id': fields.many2one('res.company','Company',required=True),
|
||||
}
|
||||
_defaults = {
|
||||
'active': lambda *a: 1,
|
||||
'logic': lambda *a: 'max',
|
||||
'qty_multiple': lambda *a: 1,
|
||||
'name': lambda x,y,z,c: x.pool.get('ir.sequence').get(y,z,'mrp.warehouse.orderpoint') or '',
|
||||
'product_uom': lambda sel, cr, uid, context: context.get('product_uom', False),
|
||||
'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'stock.warehouse.orderpoint', context=c)
|
||||
}
|
||||
def onchange_warehouse_id(self, cr, uid, ids, warehouse_id, context={}):
|
||||
if warehouse_id:
|
||||
w=self.pool.get('stock.warehouse').browse(cr,uid,warehouse_id, context)
|
||||
v = {'location_id':w.lot_stock_id.id}
|
||||
return {'value': v}
|
||||
return {}
|
||||
def onchange_product_id(self, cr, uid, ids, product_id, context={}):
|
||||
if product_id:
|
||||
prod=self.pool.get('product.product').browse(cr,uid,product_id)
|
||||
v = {'product_uom':prod.uom_id.id}
|
||||
return {'value': v}
|
||||
return {}
|
||||
def copy(self, cr, uid, id, default=None,context={}):
|
||||
if not default:
|
||||
default = {}
|
||||
default.update({
|
||||
'name': self.pool.get('ir.sequence').get(cr, uid, 'mrp.warehouse.orderpoint') or '',
|
||||
})
|
||||
return super(stock_warehouse_orderpoint, self).copy(cr, uid, id, default, context)
|
||||
stock_warehouse_orderpoint()
|
||||
|
||||
class StockMove(osv.osv):
|
||||
_inherit = 'stock.move'
|
||||
_columns = {
|
||||
'production_id': fields.many2one('mrp.production', 'Production', select=True),
|
||||
'procurements': fields.one2many('mrp.procurement', 'move_id', 'Requisitions'),
|
||||
}
|
||||
def copy(self, cr, uid, id, default=None, context=None):
|
||||
default = default or {}
|
||||
default['procurements'] = []
|
||||
return super(StockMove, self).copy(cr, uid, id, default, context)
|
||||
|
||||
def _action_explode(self, cr, uid, move, context={}):
|
||||
if move.product_id.supply_method=='produce' and move.product_id.procure_method=='make_to_order':
|
||||
bis = self.pool.get('mrp.bom').search(cr, uid, [
|
||||
('product_id','=',move.product_id.id),
|
||||
('bom_id','=',False),
|
||||
('type','=','phantom')])
|
||||
if bis:
|
||||
factor = move.product_qty
|
||||
bom_point = self.pool.get('mrp.bom').browse(cr, uid, bis[0])
|
||||
res = self.pool.get('mrp.bom')._bom_explode(cr, uid, bom_point, factor, [])
|
||||
dest = move.product_id.product_tmpl_id.property_stock_production.id
|
||||
state = 'confirmed'
|
||||
if move.state=='assigned':
|
||||
state='assigned'
|
||||
for line in res[0]:
|
||||
valdef = {
|
||||
'picking_id': move.picking_id.id,
|
||||
'product_id': line['product_id'],
|
||||
'product_uom': line['product_uom'],
|
||||
'product_qty': line['product_qty'],
|
||||
'product_uos': line['product_uos'],
|
||||
'product_uos_qty': line['product_uos_qty'],
|
||||
'move_dest_id': move.id,
|
||||
'state': state,
|
||||
'name': line['name'],
|
||||
'location_dest_id': dest,
|
||||
'move_history_ids': [(6,0,[move.id])],
|
||||
'move_history_ids2': [(6,0,[])],
|
||||
'procurements': [],
|
||||
}
|
||||
mid = self.pool.get('stock.move').copy(cr, uid, move.id, default=valdef)
|
||||
prodobj = self.pool.get('product.product').browse(cr, uid, line['product_id'], context=context)
|
||||
proc_id = self.pool.get('mrp.procurement').create(cr, uid, {
|
||||
'name': (move.picking_id.origin or ''),
|
||||
'origin': (move.picking_id.origin or ''),
|
||||
'date_planned': move.date_planned,
|
||||
'product_id': line['product_id'],
|
||||
'product_qty': line['product_qty'],
|
||||
'product_uom': line['product_uom'],
|
||||
'product_uos_qty': line['product_uos'] and line['product_uos_qty'] or False,
|
||||
'product_uos': line['product_uos'],
|
||||
'location_id': move.location_id.id,
|
||||
'procure_method': prodobj.procure_method,
|
||||
'move_id': mid,
|
||||
'company_id': line['company_id'],
|
||||
})
|
||||
wf_service = netsvc.LocalService("workflow")
|
||||
wf_service.trg_validate(uid, 'mrp.procurement', proc_id, 'button_confirm', cr)
|
||||
self.pool.get('stock.move').write(cr, uid, [move.id], {
|
||||
'location_id': move.location_dest_id.id,
|
||||
'auto_validate': True,
|
||||
'picking_id': False,
|
||||
'location_id': dest,
|
||||
'state': 'waiting'
|
||||
})
|
||||
for m in self.pool.get('mrp.procurement').search(cr, uid, [('move_id','=',move.id)], context):
|
||||
wf_service = netsvc.LocalService("workflow")
|
||||
wf_service.trg_validate(uid, 'mrp.procurement', m, 'button_wait_done', cr)
|
||||
return True
|
||||
|
||||
|
||||
def action_consume(self, cr, uid, ids, product_qty, location_id=False, context=None):
|
||||
res = []
|
||||
production_obj = self.pool.get('mrp.production')
|
||||
wf_service = netsvc.LocalService("workflow")
|
||||
for move in self.browse(cr, uid, ids):
|
||||
new_moves = super(StockMove, self).action_consume(cr, uid, [move.id], product_qty, location_id, context=context)
|
||||
production_ids = production_obj.search(cr, uid, [('move_lines', 'in', [move.id])])
|
||||
for prod in production_obj.browse(cr, uid, production_ids, context=context):
|
||||
if prod.state == 'confirmed':
|
||||
production_obj.force_production(cr, uid, [prod.id])
|
||||
wf_service.trg_validate(uid, 'mrp.production', prod.id, 'button_produce', cr)
|
||||
for new_move in new_moves:
|
||||
production_obj.write(cr, uid, production_ids, {'move_lines': [(4, new_move)]})
|
||||
res.append(new_move)
|
||||
return res
|
||||
|
||||
def action_scrap(self, cr, uid, ids, product_qty, location_id, context=None):
|
||||
res = []
|
||||
production_obj = self.pool.get('mrp.production')
|
||||
wf_service = netsvc.LocalService("workflow")
|
||||
for move in self.browse(cr, uid, ids):
|
||||
new_moves = super(StockMove, self).action_scrap(cr, uid, [move.id], product_qty, location_id, context=context)
|
||||
production_ids = production_obj.search(cr, uid, [('move_lines', 'in', [move.id])])
|
||||
for prod_id in production_ids:
|
||||
wf_service.trg_validate(uid, 'mrp.production', prod_id, 'button_produce', cr)
|
||||
for new_move in new_moves:
|
||||
production_obj.write(cr, uid, production_ids, {'move_lines': [(4, new_move)]})
|
||||
res.append(new_move)
|
||||
return {}
|
||||
|
||||
StockMove()
|
||||
|
||||
|
||||
class StockPicking(osv.osv):
|
||||
_inherit = 'stock.picking'
|
||||
|
||||
def test_finnished(self, cursor, user, ids):
|
||||
wf_service = netsvc.LocalService("workflow")
|
||||
res = super(StockPicking, self).test_finnished(cursor, user, ids)
|
||||
for picking in self.browse(cursor, user, ids):
|
||||
for move in picking.move_lines:
|
||||
if move.state == 'done' and move.procurements:
|
||||
for procurement in move.procurements:
|
||||
wf_service.trg_validate(user, 'mrp.procurement',
|
||||
procurement.id, 'button_check', cursor)
|
||||
return res
|
||||
|
||||
#
|
||||
# Explode picking by replacing phantom BoMs
|
||||
#
|
||||
def action_explode(self, cr, uid, picks, *args):
|
||||
for move in self.pool.get('stock.move').browse(cr, uid, picks):
|
||||
self.pool.get('stock.move')._action_explode(cr, uid, move)
|
||||
return picks
|
||||
|
||||
StockPicking()
|
||||
|
||||
|
||||
class spilt_in_production_lot(osv.osv_memory):
|
||||
_inherit = "stock.move.split"
|
||||
def split(self, cr, uid, ids, move_ids, context=None):
|
||||
production_obj = self.pool.get('mrp.production')
|
||||
move_obj = self.pool.get('stock.move')
|
||||
res = []
|
||||
for move in move_obj.browse(cr, uid, move_ids, context=context):
|
||||
new_moves = super(spilt_in_production_lot, self).split(cr, uid, ids, move_ids, context=context)
|
||||
production_ids = production_obj.search(cr, uid, [('move_lines', 'in', [move.id])])
|
||||
for new_move in new_moves:
|
||||
production_obj.write(cr, uid, production_ids, {'move_lines': [(4, new_move)]})
|
||||
return res
|
||||
spilt_in_production_lot()
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
@ -1308,41 +1308,8 @@ class stock_move(osv.osv):
|
|||
for id in ids:
|
||||
wf_service.trg_trigger(uid, 'stock.move', id, cr)
|
||||
#self.action_cancel(cr,uid, ids2, context)
|
||||
return True
|
||||
return True
|
||||
|
||||
def action_scrap(self, cr, uid, ids,context=None):
|
||||
'''
|
||||
add the damaged product into consumed product by updating its state to cancel and
|
||||
add same product since we need that product to manufacture the parent product.
|
||||
|
||||
:param cr: the database cursor
|
||||
:param uid: the user id
|
||||
:param ids: ids of product object to be scraped
|
||||
:param context: context arguments
|
||||
:return:
|
||||
'''
|
||||
# to find the parent id(manufacturing order) of the active record(product to consume),
|
||||
# obtain active record id 1st and then get the production_id from mrp_production_move_ids
|
||||
active_id=ids[0]
|
||||
cr.execute("select production_id from mrp_production_move_ids where move_id=%s" % (active_id))
|
||||
# it gives parent id in [list(tuple)] format so extract it [(21,)]
|
||||
parent_id = int(cr.fetchall()[0][0])
|
||||
# get the parent object
|
||||
parent_obj = self.pool.get('mrp.production').browse(cr, uid, parent_id)
|
||||
# create copy for multiple id processing for product to consume which r scraped
|
||||
for id in ids:
|
||||
#create copy of the product records which are scraped due to damage since they are
|
||||
#still required to manufacture the product.
|
||||
new_rec_id = self.copy(cr, uid, id, {'state': 'waiting'}, context)
|
||||
|
||||
#assign all new products which will replace damaged product to the current manufacturing order
|
||||
cr.execute('insert into mrp_production_move_ids (production_id,move_id) values (%s,%s)', (parent_id, new_rec_id))
|
||||
|
||||
# all damaged product needs to be in consumed product window having cancel state.
|
||||
vals={'state': 'cancel', 'date_planned': time.strftime('%Y-%m-%d %H:%M:%S')}
|
||||
self.pool.get('stock.move').write(cr, uid, ids,vals )
|
||||
|
||||
return True
|
||||
def action_done(self, cr, uid, ids, context=None):
|
||||
track_flag = False
|
||||
picking_ids = []
|
||||
|
@ -1483,8 +1450,51 @@ class stock_move(osv.osv):
|
|||
prodlot_obj.write(cr, uid, [prodlot_id], {'ref': ref})
|
||||
return prodlot_id
|
||||
|
||||
def split_lines(self, cr, uid, ids, quantity, split_by_qty=1, prefix=False, with_lot=True, context=None):
|
||||
|
||||
def action_scrap(self, cr, uid, ids, quantity, location_id, context=None):
|
||||
'''
|
||||
Move the scrap/damaged product into scrap location
|
||||
|
||||
@ param cr: the database cursor
|
||||
@ param uid: the user id
|
||||
@ param ids: ids of stock move object to be scraped
|
||||
@ param quantity : specify scrap qty
|
||||
@ param location_id : specify scrap location
|
||||
@ param context: context arguments
|
||||
|
||||
@ return: True
|
||||
'''
|
||||
if quantity <= 0:
|
||||
raise osv.except_osv(_('Warning!'), _('Please provide Proper Quantity !'))
|
||||
res = []
|
||||
for move in self.browse(cr, uid, ids, context=context):
|
||||
move_qty = move.product_qty
|
||||
uos_qty = quantity / move_qty * move.product_uos_qty
|
||||
default_val = {
|
||||
'product_qty': quantity,
|
||||
'product_uos_qty': uos_qty,
|
||||
'state': move.state,
|
||||
'location_dest_id': location_id
|
||||
}
|
||||
new_move = self.copy(cr, uid, move.id, default_val)
|
||||
res += [new_move]
|
||||
|
||||
return True
|
||||
|
||||
def action_split(self, cr, uid, ids, quantity, split_by_qty=1, prefix=False, with_lot=True, context=None):
|
||||
'''
|
||||
Split Stock Move lines into production lot which specified split by quantity.
|
||||
|
||||
@ param cr: the database cursor
|
||||
@ param uid: the user id
|
||||
@ param ids: ids of stock move object to be splited
|
||||
@ param split_by_qty : specify split by qty
|
||||
@ param prefix : specify prefix of production lot
|
||||
@ param with_lot : if true, prodcution lot will assign for split line otherwise not.
|
||||
@ param context: context arguments
|
||||
|
||||
@ return: True
|
||||
'''
|
||||
|
||||
if quantity <= 0:
|
||||
raise osv.except_osv(_('Warning!'), _('Please provide Proper Quantity !'))
|
||||
|
@ -1534,7 +1544,19 @@ class stock_move(osv.osv):
|
|||
self.write(cr, uid, [current_move], update_val)
|
||||
return res
|
||||
|
||||
def consume_moves(self, cr, uid, ids, quantity, location_id=False, location_dest_id=False, consume=True, context=None):
|
||||
def action_consume(self, cr, uid, ids, quantity, location_id=False, context=None):
|
||||
'''
|
||||
Consumed product with specific quatity from specific source location
|
||||
|
||||
@ param cr: the database cursor
|
||||
@ param uid: the user id
|
||||
@ param ids: ids of stock move object to be consumed
|
||||
@ param quantity : specify consume quantity
|
||||
@ param location_id : specify source location
|
||||
@ param context: context arguments
|
||||
|
||||
@ return: True
|
||||
'''
|
||||
if not context:
|
||||
context = {}
|
||||
|
||||
|
@ -1547,7 +1569,7 @@ class stock_move(osv.osv):
|
|||
quantity_rest = move.product_qty
|
||||
|
||||
quantity_rest -= quantity
|
||||
uos_qty_rest = quantity_rest / move_qty * move.product_uos_qty
|
||||
uos_qty_rest = quantity_rest / move_qty * move.product_uos_qty
|
||||
if quantity_rest <= 0:
|
||||
quantity_rest = 0
|
||||
uos_qty_rest = 0
|
||||
|
@ -1560,14 +1582,11 @@ class stock_move(osv.osv):
|
|||
'product_qty': quantity,
|
||||
'product_uos_qty': uos_qty,
|
||||
'state': move.state,
|
||||
}
|
||||
if location_dest_id:
|
||||
default_val.update({'location_dest_id': location_dest_id})
|
||||
if location_id:
|
||||
default_val.update({'location_id': location_id})
|
||||
|
||||
'location_id': location_id
|
||||
}
|
||||
if move.product_id.track_production and location_id:
|
||||
res += self.split_lines(cr, uid, [move.id], quantity, split_by_qty=1, context=context)
|
||||
# IF product has checked track for production lot, move lines will be split by 1
|
||||
res += self.action_split(cr, uid, [move.id], quantity, split_by_qty=1, context=context)
|
||||
else:
|
||||
current_move = self.copy(cr, uid, move.id, default_val)
|
||||
res += [current_move]
|
||||
|
@ -1585,38 +1604,16 @@ class stock_move(osv.osv):
|
|||
res += self.split_lines(cr, uid, [move.id], quantity_rest, split_by_qty=1, context=context)
|
||||
else:
|
||||
res += [move.id]
|
||||
update_val = {}
|
||||
update_val['product_qty'] = quantity_rest
|
||||
update_val['product_uos_qty'] = uos_qty_rest
|
||||
if location_dest_id:
|
||||
update_val.update({'location_dest_id': location_dest_id})
|
||||
if location_id:
|
||||
update_val.update({'location_id': location_id})
|
||||
update_val = {
|
||||
'product_qty' : quantity_rest,
|
||||
'product_uos_qty' : uos_qty_rest,
|
||||
'location_id': location_id
|
||||
}
|
||||
|
||||
self.write(cr, uid, [move.id], update_val)
|
||||
|
||||
if consume:
|
||||
self.action_done(cr, uid, res)
|
||||
else:
|
||||
self.action_scrap(cr, uid, res,context)
|
||||
return res
|
||||
|
||||
def scrap_moves(self, cr, uid, ids, quantity, location_dest_id, context=None):
|
||||
if quantity <= 0:
|
||||
raise osv.except_osv(_('Warning!'), _('Please provide Proper Quantity !'))
|
||||
res = []
|
||||
for move in self.browse(cr, uid, ids, context=context):
|
||||
move_qty = move.product_qty
|
||||
uos_qty = quantity / move_qty * move.product_uos_qty
|
||||
default_val = {
|
||||
'product_qty': quantity,
|
||||
'product_uos_qty': uos_qty,
|
||||
'state': move.state,
|
||||
'location_dest_id': location_dest_id
|
||||
}
|
||||
new_move = self.copy(cr, uid, move.id, default_val)
|
||||
res += [new_move]
|
||||
return res
|
||||
self.action_done(cr, uid, res)
|
||||
return res
|
||||
|
||||
stock_move()
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ class stock_move_consume(osv.osv_memory):
|
|||
'product_qty': fields.float('Quantity', required=True),
|
||||
'product_uom': fields.many2one('product.uom', 'Product UOM', required=True),
|
||||
'location_id': fields.many2one('stock.location', 'Location', required=True)
|
||||
}
|
||||
}
|
||||
|
||||
def default_get(self, cr, uid, fields_list, context=None):
|
||||
"""
|
||||
|
@ -104,7 +104,7 @@ class stock_move_consume(osv.osv_memory):
|
|||
move_obj = self.pool.get('stock.move')
|
||||
move_ids = context['active_ids']
|
||||
for data in self.read(cr, uid, ids):
|
||||
move_obj.consume_moves(cr, uid, move_ids,
|
||||
move_obj.action_consume(cr, uid, move_ids,
|
||||
data['product_qty'], data['location_id'],
|
||||
context=context)
|
||||
return {}
|
||||
|
@ -137,7 +137,7 @@ class stock_move_scrap(osv.osv_memory):
|
|||
move_obj = self.pool.get('stock.move')
|
||||
move_ids = context['active_ids']
|
||||
for data in self.read(cr, uid, ids):
|
||||
move_obj.scrap_moves(cr, uid, move_ids,
|
||||
move_obj.action_scrap(cr, uid, move_ids,
|
||||
data['product_qty'], data['location_id'],
|
||||
context=context)
|
||||
return {}
|
||||
|
|
Loading…
Reference in New Issue