[IMP] WIP: big cleaning
bzr revid: fp@tinyerp.com-20130629221703-ti4qqcc8e3pc0ddh
This commit is contained in:
parent
471dd0998d
commit
863ef7cf7a
|
@ -29,7 +29,6 @@ from openerp import SUPERUSER_ID
|
|||
|
||||
class sale_order(osv.osv):
|
||||
_inherit = "sale.order"
|
||||
|
||||
def copy(self, cr, uid, id, default=None, context=None):
|
||||
if not default:
|
||||
default = {}
|
||||
|
@ -39,33 +38,6 @@ class sale_order(osv.osv):
|
|||
})
|
||||
return super(sale_order, self).copy(cr, uid, id, default, context=context)
|
||||
|
||||
def shipping_policy_change(self, cr, uid, ids, policy, context=None):
|
||||
if not policy:
|
||||
return {}
|
||||
inv_qty = 'order'
|
||||
if policy == 'prepaid':
|
||||
inv_qty = 'order'
|
||||
elif policy == 'picking':
|
||||
inv_qty = 'procurement'
|
||||
return {'value': {'invoice_quantity': inv_qty}}
|
||||
|
||||
def write(self, cr, uid, ids, vals, context=None):
|
||||
if vals.get('order_policy', False):
|
||||
if vals['order_policy'] == 'prepaid':
|
||||
vals.update({'invoice_quantity': 'order'})
|
||||
elif vals['order_policy'] == 'picking':
|
||||
vals.update({'invoice_quantity': 'procurement'})
|
||||
return super(sale_order, self).write(cr, uid, ids, vals, context=context)
|
||||
|
||||
def create(self, cr, uid, vals, context=None):
|
||||
if vals.get('order_policy', False):
|
||||
if vals['order_policy'] == 'prepaid':
|
||||
vals.update({'invoice_quantity': 'order'})
|
||||
if vals['order_policy'] == 'picking':
|
||||
vals.update({'invoice_quantity': 'procurement'})
|
||||
order = super(sale_order, self).create(cr, uid, vals, context=context)
|
||||
return order
|
||||
|
||||
def _get_default_warehouse(self, cr, uid, context=None):
|
||||
company_id = self.pool.get('res.users')._get_company(cr, uid, context=context)
|
||||
warehouse_ids = self.pool.get('stock.warehouse').search(cr, uid, [('company_id', '=', company_id)], context=context)
|
||||
|
@ -73,45 +45,6 @@ class sale_order(osv.osv):
|
|||
raise osv.except_osv(_('Error!'), _('There is no warehouse defined for current company.'))
|
||||
return warehouse_ids[0]
|
||||
|
||||
# This is False
|
||||
def _picked_rate(self, cr, uid, ids, name, arg, context=None):
|
||||
if not ids:
|
||||
return {}
|
||||
res = {}
|
||||
tmp = {}
|
||||
for id in ids:
|
||||
tmp[id] = {'picked': 0.0, 'total': 0.0}
|
||||
cr.execute('''SELECT
|
||||
p.sale_id as sale_order_id, sum(m.product_qty) as nbr, mp.state as procurement_state, m.state as move_state, p.type as picking_type
|
||||
FROM
|
||||
stock_move m
|
||||
LEFT JOIN
|
||||
stock_picking p on (p.id=m.picking_id)
|
||||
LEFT JOIN
|
||||
procurement_order mp on (mp.move_id=m.id)
|
||||
WHERE
|
||||
p.sale_id IN %s GROUP BY m.state, mp.state, p.sale_id, p.type''', (tuple(ids),))
|
||||
|
||||
for item in cr.dictfetchall():
|
||||
if item['move_state'] == 'cancel':
|
||||
continue
|
||||
|
||||
if item['picking_type'] == 'in':#this is a returned picking
|
||||
tmp[item['sale_order_id']]['total'] -= item['nbr'] or 0.0 # Deducting the return picking qty
|
||||
if item['procurement_state'] == 'done' or item['move_state'] == 'done':
|
||||
tmp[item['sale_order_id']]['picked'] -= item['nbr'] or 0.0
|
||||
else:
|
||||
tmp[item['sale_order_id']]['total'] += item['nbr'] or 0.0
|
||||
if item['procurement_state'] == 'done' or item['move_state'] == 'done':
|
||||
tmp[item['sale_order_id']]['picked'] += item['nbr'] or 0.0
|
||||
|
||||
for order in self.browse(cr, uid, ids, context=context):
|
||||
if order.shipped:
|
||||
res[order.id] = 100.0
|
||||
else:
|
||||
res[order.id] = tmp[order.id]['total'] and (100.0 * tmp[order.id]['picked'] / tmp[order.id]['total']) or 0.0
|
||||
return res
|
||||
|
||||
_columns = {
|
||||
'state': fields.selection([
|
||||
('draft', 'Draft Quotation'),
|
||||
|
@ -137,33 +70,14 @@ class sale_order(osv.osv):
|
|||
('prepaid', 'Before Delivery'),
|
||||
], 'Create Invoice', required=True, readonly=True, states={'draft': [('readonly', False)], 'sent': [('readonly', False)]},
|
||||
help="""On demand: A draft invoice can be created from the sales order when needed. \nOn delivery order: A draft invoice can be created from the delivery order when the products have been delivered. \nBefore delivery: A draft invoice is created from the sales order and must be paid before the products can be delivered."""),
|
||||
'picking_ids': fields.one2many('stock.picking.out', 'sale_id', 'Related Picking', readonly=True, help="This is a list of delivery orders that has been generated for this sales order."),
|
||||
'shipped': fields.boolean('Delivered', readonly=True, help="It indicates that the sales order has been delivered. This field is updated only after the scheduler(s) have been launched."),
|
||||
'picked_rate': fields.function(_picked_rate, string='Picked', type='float'),
|
||||
'warehouse_id': fields.many2one('stock.warehouse', 'Warehouse', required=True),
|
||||
'invoice_quantity': fields.selection([('order', 'Ordered Quantities'), ('procurement', 'Shipped Quantities')], 'Invoice on',
|
||||
help="The sales order will automatically create the invoice proposition (draft invoice).\
|
||||
You have to choose if you want your invoice based on ordered ", required=True, readonly=True, states={'draft': [('readonly', False)]}),
|
||||
}
|
||||
_defaults = {
|
||||
'warehouse_id': _get_default_warehouse,
|
||||
'picking_policy': 'direct',
|
||||
'order_policy': 'manual',
|
||||
'invoice_quantity': 'order',
|
||||
}
|
||||
|
||||
# Form filling
|
||||
def unlink(self, cr, uid, ids, context=None):
|
||||
sale_orders = self.read(cr, uid, ids, ['state'], context=context)
|
||||
unlink_ids = []
|
||||
for s in sale_orders:
|
||||
if s['state'] in ['draft', 'cancel']:
|
||||
unlink_ids.append(s['id'])
|
||||
else:
|
||||
raise osv.except_osv(_('Invalid Action!'), _('In order to delete a confirmed sales order, you must cancel it.\nTo do so, you must first cancel related picking for delivery orders.'))
|
||||
|
||||
return osv.osv.unlink(self, cr, uid, unlink_ids, context=context)
|
||||
|
||||
'warehouse_id': _get_default_warehouse,
|
||||
'picking_policy': 'direct',
|
||||
'order_policy': 'manual',
|
||||
}
|
||||
def onchange_warehouse_id(self, cr, uid, ids, warehouse_id, context=None):
|
||||
val = {}
|
||||
if warehouse_id:
|
||||
|
@ -172,9 +86,14 @@ class sale_order(osv.osv):
|
|||
val['company_id'] = warehouse.company_id.id
|
||||
return {'value': val}
|
||||
|
||||
# FP Note: to change, take the picking related to the moves related to the
|
||||
# procurements related to SO lines
|
||||
|
||||
def action_view_delivery(self, cr, uid, ids, context=None):
|
||||
'''
|
||||
This function returns an action that display existing delivery orders of given sales order ids. It can either be a in a list or in a form view, if there is only one delivery order to show.
|
||||
This function returns an action that display existing delivery orders
|
||||
of given sales order ids. It can either be a in a list or in a form
|
||||
view, if there is only one delivery order to show.
|
||||
'''
|
||||
mod_obj = self.pool.get('ir.model.data')
|
||||
act_obj = self.pool.get('ir.actions.act_window')
|
||||
|
@ -182,10 +101,12 @@ class sale_order(osv.osv):
|
|||
result = mod_obj.get_object_reference(cr, uid, 'stock', 'action_picking_tree')
|
||||
id = result and result[1] or False
|
||||
result = act_obj.read(cr, uid, [id], context=context)[0]
|
||||
|
||||
#compute the number of delivery orders to display
|
||||
pick_ids = []
|
||||
for so in self.browse(cr, uid, ids, context=context):
|
||||
pick_ids += [picking.id for picking in so.picking_ids]
|
||||
|
||||
#choose the view_mode accordingly
|
||||
if len(pick_ids) > 1:
|
||||
result['domain'] = "[('id','in',["+','.join(map(str, pick_ids))+"])]"
|
||||
|
@ -295,9 +216,10 @@ class sale_order(osv.osv):
|
|||
elif mode == 'canceled':
|
||||
return canceled
|
||||
|
||||
def _prepare_order_line_procurement(self, cr, uid, order, line, move_id, date_planned, group_id = False, context=None):
|
||||
def _prepare_order_line_procurement(self, cr, uid, order, line, group_id = False, context=None):
|
||||
mod_obj = self.pool.get('ir.model.data')
|
||||
location_model, location_id = mod_obj.get_object_reference(cr, uid, 'stock', 'stock_location_customers')
|
||||
date_planned = self._get_date_planned(cr, uid, order, line, order.date_order, context=context)
|
||||
return {
|
||||
'name': line.name,
|
||||
'origin': order.name,
|
||||
|
@ -323,7 +245,7 @@ class sale_order(osv.osv):
|
|||
date_planned = (date_planned - timedelta(days=order.company_id.security_lead)).strftime(DEFAULT_SERVER_DATETIME_FORMAT)
|
||||
return date_planned
|
||||
|
||||
def _create_pickings_and_procurements(self, cr, uid, order, order_lines, picking_id=False, context=None):
|
||||
def action_ship_create(self, cr, uid, ids, context=None):
|
||||
"""Create the required procurements to supply sales order lines, also connecting
|
||||
the procurements to appropriate stock moves in order to bring the goods to the
|
||||
sales order's requested location.
|
||||
|
@ -342,42 +264,32 @@ class sale_order(osv.osv):
|
|||
will be added. A new picking will be created if ommitted.
|
||||
:return: True
|
||||
"""
|
||||
move_obj = self.pool.get('stock.move')
|
||||
picking_obj = self.pool.get('stock.picking')
|
||||
procurement_obj = self.pool.get('procurement.order')
|
||||
proc_ids = []
|
||||
for order in self.browse(cr, uid, ids, context=context):
|
||||
proc_ids = []
|
||||
group_id = self.pool.get("procurement.group").create(cr, uid, {'name': order.name}, context=context)
|
||||
for line in order.order_lines:
|
||||
if (line.state == 'done') or not line.product_id:
|
||||
continue
|
||||
|
||||
group_id = self.pool.get("procurement.group").create(cr, uid, {'name': order.name}, context=context)
|
||||
|
||||
for line in order_lines:
|
||||
if line.state == 'done':
|
||||
continue
|
||||
|
||||
date_planned = self._get_date_planned(cr, uid, order, line, order.date_order, context=context)
|
||||
|
||||
if line.product_id:
|
||||
proc_id = procurement_obj.create(cr, uid, self._prepare_order_line_procurement(cr, uid, order, line, move_id, date_planned, group_id = group_id, context=context))
|
||||
proc_id = procurement_obj.create(cr, uid, self._prepare_order_line_procurement(cr, uid, order, line, group_id=group_id, context=context))
|
||||
proc_ids.append(proc_id)
|
||||
line.write({'procurement_id': proc_id})
|
||||
|
||||
procurement_obj.signal_button_confirm(cr, uid, proc_ids)
|
||||
procurement_obj.signal_button_confirm(cr, uid, proc_ids)
|
||||
|
||||
val = {}
|
||||
if order.state == 'shipping_except':
|
||||
val['state'] = 'progress'
|
||||
val['shipped'] = False
|
||||
# FP NOTE: do we need this? isn't it the workflow that should set this
|
||||
val = {}
|
||||
if order.state == 'shipping_except':
|
||||
val['state'] = 'progress'
|
||||
val['shipped'] = False
|
||||
|
||||
if (order.order_policy == 'manual'):
|
||||
for line in order.order_line:
|
||||
if (not line.invoiced) and (line.state not in ('cancel', 'draft')):
|
||||
val['state'] = 'manual'
|
||||
break
|
||||
order.write(val)
|
||||
return True
|
||||
|
||||
def action_ship_create(self, cr, uid, ids, context=None):
|
||||
for order in self.browse(cr, uid, ids, context=context):
|
||||
self._create_pickings_and_procurements(cr, uid, order, order.order_line, None, context=context)
|
||||
if (order.order_policy == 'manual'):
|
||||
for line in order.order_line:
|
||||
if (not line.invoiced) and (line.state not in ('cancel', 'draft')):
|
||||
val['state'] = 'manual'
|
||||
break
|
||||
order.write(val)
|
||||
return True
|
||||
|
||||
def action_ship_end(self, cr, uid, ids, context=None):
|
||||
|
@ -432,21 +344,6 @@ class sale_order_line(osv.osv):
|
|||
'product_packaging': False,
|
||||
}
|
||||
|
||||
def _get_line_qty(self, cr, uid, line, context=None):
|
||||
if line.procurement_id and not (line.order_id.invoice_quantity=='order'):
|
||||
return self.pool.get('procurement.order').quantity_get(cr, uid,
|
||||
line.procurement_id.id, context=context)
|
||||
else:
|
||||
return super(sale_order_line, self)._get_line_qty(cr, uid, line, context=context)
|
||||
|
||||
|
||||
def _get_line_uom(self, cr, uid, line, context=None):
|
||||
if line.procurement_id and not (line.order_id.invoice_quantity=='order'):
|
||||
return self.pool.get('procurement.order').uom_get(cr, uid,
|
||||
line.procurement_id.id, context=context)
|
||||
else:
|
||||
return super(sale_order_line, self)._get_line_uom(cr, uid, line, context=context)
|
||||
|
||||
def button_cancel(self, cr, uid, ids, context=None):
|
||||
res = super(sale_order_line, self).button_cancel(cr, uid, ids, context=context)
|
||||
for line in self.browse(cr, uid, ids, context=context):
|
||||
|
|
|
@ -22,18 +22,6 @@
|
|||
from openerp.osv import fields, osv
|
||||
from openerp.tools.translate import _
|
||||
|
||||
class stock_move(osv.osv):
|
||||
_inherit = 'stock.move'
|
||||
_columns = {
|
||||
'sale_line_id': fields.many2one('sale.order.line', 'Sales Order Line', ondelete='set null', select=True, readonly=True),
|
||||
}
|
||||
|
||||
def _prepare_chained_picking(self, cr, uid, picking_name, picking, picking_type, moves_todo, context=None):
|
||||
values = super(stock_move, self)._prepare_chained_picking(cr, uid, picking_name, picking, picking_type, moves_todo, context=context)
|
||||
if picking.sale_id:
|
||||
values['sale_id'] = picking.sale_id.id
|
||||
return values
|
||||
|
||||
class stock_picking(osv.osv):
|
||||
_inherit = 'stock.picking'
|
||||
_columns = {
|
||||
|
|
|
@ -97,7 +97,6 @@
|
|||
!python {model: sale.order}: |
|
||||
order = self.pool.get('sale.order').browse(cr, uid, ref("sale.sale_order_6"))
|
||||
assert order.shipped == True, "Sale order is not Delivered."
|
||||
assert order.picked_rate == 100, "Shipment progress is not 100%."
|
||||
#assert order.state == 'progress', 'Order should be in inprogress.'
|
||||
assert len(order.invoice_ids) == False, "Invoice should not created on dispatch delivery order."
|
||||
-
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
from stock import *
|
||||
import partner
|
||||
import product
|
||||
import stock_fifo_lifo
|
||||
#import stock_fifo_lifo
|
||||
import report
|
||||
import wizard
|
||||
import res_config
|
||||
|
|
|
@ -202,36 +202,29 @@ class product_product(osv.osv):
|
|||
It will return all stock locations when no parameters are given
|
||||
Possible parameters are shop, warehouse, location, force_company, compute_child
|
||||
'''
|
||||
if context is None:
|
||||
context = {}
|
||||
context = context or {}
|
||||
|
||||
location_obj = self.pool.get('stock.location')
|
||||
warehouse_obj = self.pool.get('stock.warehouse')
|
||||
shop_obj = self.pool.get('sale.shop')
|
||||
if context.get('shop', False):
|
||||
warehouse_id = shop_obj.read(cr, uid, int(context['shop']), ['warehouse_id'])['warehouse_id'][0]
|
||||
if warehouse_id:
|
||||
context['warehouse'] = warehouse_id
|
||||
|
||||
if context.get('warehouse', False):
|
||||
lot_id = warehouse_obj.read(cr, uid, int(context['warehouse']), ['lot_stock_id'])['lot_stock_id'][0]
|
||||
if lot_id:
|
||||
context['location'] = lot_id
|
||||
|
||||
location_ids = []
|
||||
if context.get('location', False):
|
||||
if type(context['location']) == type(1):
|
||||
location_ids = [context['location']]
|
||||
elif type(context['location']) in (type(''), type(u'')):
|
||||
domain = [('name','ilike',context['location'])]
|
||||
if context.get('force_company', False):
|
||||
location_ids = location_obj.search(cr, uid, [('name','ilike',context['location']), ('company_id', '=', context['force_company'])], context=context)
|
||||
else:
|
||||
location_ids = location_obj.search(cr, uid, [('name','ilike',context['location'])], context=context)
|
||||
domain += [('company_id', '=', context['force_company'])]
|
||||
location_ids = location_obj.search(cr, uid, domain, context=context)
|
||||
else:
|
||||
location_ids = context['location']
|
||||
else:
|
||||
location_ids = []
|
||||
wids = warehouse_obj.search(cr, uid, [], context=context)
|
||||
if not wids:
|
||||
return False
|
||||
if context.get('warehouse', False):
|
||||
wh = warehouse_obj.browse(cr, uid, [context['warehouse']], context=context)
|
||||
else:
|
||||
wids = warehouse_obj.search(cr, uid, [], context=context)
|
||||
wh = warehouse_obj.browse(cr, uid, wids, context=context)
|
||||
|
||||
for w in warehouse_obj.browse(cr, uid, wids, context=context):
|
||||
if not context.get('force_company', False) or w.lot_stock_id.company_id.id == context['force_company']:
|
||||
location_ids.append(w.lot_stock_id.id)
|
||||
|
@ -245,7 +238,6 @@ class product_product(osv.osv):
|
|||
location_ids = child_location_ids or location_ids
|
||||
return location_ids
|
||||
|
||||
|
||||
def _get_date_query(self, cr, uid, ids, context):
|
||||
'''
|
||||
Parses the context and returns the dates query string needed to be processed in _get_product_available
|
||||
|
@ -255,7 +247,6 @@ class product_product(osv.osv):
|
|||
to_date = context.get('to_date',False)
|
||||
date_str = False
|
||||
whereadd = []
|
||||
|
||||
if from_date and to_date:
|
||||
date_str = "date>=%s and date<=%s"
|
||||
whereadd.append(tuple([from_date]))
|
||||
|
@ -268,9 +259,6 @@ class product_product(osv.osv):
|
|||
whereadd.append(tuple([to_date]))
|
||||
return (whereadd, date_str)
|
||||
|
||||
|
||||
|
||||
|
||||
def get_product_available(self, cr, uid, ids, context=None):
|
||||
""" Finds the quantity available of product(s) depending on parameters in the context
|
||||
for what, states, locations (company, warehouse, ), date, lot,
|
||||
|
@ -570,11 +558,21 @@ class product_template(osv.osv):
|
|||
'sale_delay': 7,
|
||||
}
|
||||
|
||||
class product_category(osv.osv):
|
||||
|
||||
# TODO: move this on stock module
|
||||
|
||||
class product_removal_strategy(osv.osv):
|
||||
_name = 'product.removal'
|
||||
_description = 'Removal Strategy'
|
||||
_columns = {
|
||||
'categ_ids':fields.one2many('product.category','removal_strategy_id', 'Product Categories', required=True),
|
||||
'method': fields.selection([('fifo', 'FIFO'), ('lifo', 'LIFO')], "Method", required=True),
|
||||
}
|
||||
|
||||
class product_category(osv.osv):
|
||||
_inherit = 'product.category'
|
||||
_columns = {
|
||||
'removal_strategy': fields.selection([('fifo', 'FIFO'), ('lifo', 'LIFO'), ('nearest', 'Nearest Location')], "Standard Removal Strategy"),
|
||||
'removal_strategy_id': fields.many2one('product.removal', 'Removal Strategy'),
|
||||
'property_stock_journal': fields.property(
|
||||
relation='account.journal',
|
||||
type='many2one',
|
||||
|
|
|
@ -31,7 +31,6 @@
|
|||
<field name="removal_strategy"/>
|
||||
</group>
|
||||
</group>
|
||||
|
||||
</data>
|
||||
</field>
|
||||
</record>
|
||||
|
|
|
@ -231,7 +231,7 @@ class report_stock_inventory(osv.osv):
|
|||
location_dest.usage as location_dest_type,
|
||||
location.usage as location_src_type
|
||||
FROM stock_quant sq
|
||||
LEFT JOIN quant_move_rel qm ON (qm.quant_id = sq.id)
|
||||
LEFT JOIN stock_quant_move_rel qm ON (qm.quant_id = sq.id)
|
||||
LEFT JOIN stock_move m ON (qm.move_id = m.id)
|
||||
LEFT JOIN stock_picking p ON (m.picking_id=p.id)
|
||||
LEFT JOIN stock_location location ON (m.location_id = location.id)
|
||||
|
|
|
@ -19,7 +19,6 @@ access_stock_picking_in_manager,stock.picking.in manager,model_stock_picking_in,
|
|||
access_stock_picking_out_manager,stock.picking.out manager,model_stock_picking_out,stock.group_stock_manager,1,0,0,0
|
||||
access_stock_production_lot_manager,stock.production.lot manager,model_stock_production_lot,stock.group_stock_manager,1,0,0,0
|
||||
access_stock_production_lot_user,stock.production.lot user,model_stock_production_lot,stock.group_stock_user,1,1,1,1
|
||||
access_stock_production_lot_revision,stock.production.lot.revision,model_stock_production_lot_revision,stock.group_stock_user,1,1,1,1
|
||||
access_stock_move_manager,stock.move manager,model_stock_move,stock.group_stock_manager,1,1,1,1
|
||||
access_stock_move_user,stock.move user,model_stock_move,stock.group_stock_user,1,1,1,0
|
||||
access_stock_inventory_user,stock.inventory user,model_stock_inventory,stock.group_stock_user,1,1,1,0
|
||||
|
|
|
File diff suppressed because it is too large
Load Diff
|
@ -39,20 +39,17 @@ watch your stock valuation, and track production lots upstream and downstream (b
|
|||
<record id="stock_location_locations" model="stock.location">
|
||||
<field name="name">Physical Locations</field>
|
||||
<field name="usage">view</field>
|
||||
<field name="icon">terp-stock</field>
|
||||
<field name="company_id"></field>
|
||||
</record>
|
||||
<record id="stock_location_locations_partner" model="stock.location">
|
||||
<field name="name">Partner Locations</field>
|
||||
<field name="usage">view</field>
|
||||
<field name="icon">terp-partner</field>
|
||||
<field name="posz">1</field>
|
||||
<field name="company_id"></field>
|
||||
</record>
|
||||
<record id="stock_location_locations_virtual" model="stock.location">
|
||||
<field name="name">Virtual Locations</field>
|
||||
<field name="usage">view</field>
|
||||
<field name="icon">terp-mrp</field>
|
||||
<field name="posz">1</field>
|
||||
<field name="company_id"></field>
|
||||
</record>
|
||||
|
|
|
@ -303,35 +303,6 @@
|
|||
</search>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_production_lot_revision_form" model="ir.ui.view">
|
||||
<field name="name">stock.production.lot.revision.form</field>
|
||||
<field name="model">stock.production.lot.revision</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Serial Number Revisions" version="7.0">
|
||||
<group col="4">
|
||||
<field name="name"/>
|
||||
<field name="indice"/>
|
||||
<field name="date"/>
|
||||
<field name="author_id"/>
|
||||
</group>
|
||||
<separator string="Description"/>
|
||||
<field name="description"/>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
<record id="view_production_lot_revision_tree" model="ir.ui.view">
|
||||
<field name="name">stock.production.lot.revision.tree</field>
|
||||
<field name="model">stock.production.lot.revision</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Serial Number Revisions">
|
||||
<field name="indice"/>
|
||||
<field name="author_id"/>
|
||||
<field name="date"/>
|
||||
<field name="name"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
<record id="view_production_lot_form" model="ir.ui.view">
|
||||
<field name="name">stock.production.lot.form</field>
|
||||
<field name="model">stock.production.lot</field>
|
||||
|
@ -350,32 +321,17 @@
|
|||
<group>
|
||||
<group>
|
||||
<field name="product_id"/>
|
||||
<field name="prefix"/>
|
||||
<field name="ref"/>
|
||||
</group>
|
||||
<group>
|
||||
<field name="date"/>
|
||||
<field name="stock_available"/>
|
||||
</group>
|
||||
</group>
|
||||
<notebook>
|
||||
<page string="Revisions">
|
||||
<field name="revisions"/>
|
||||
</page>
|
||||
<page string="Stock Moves">
|
||||
<field name="move_ids">
|
||||
<tree string="Stock Moves">
|
||||
<field name="picking_id" string="Reference"/>
|
||||
<field name="origin"/>
|
||||
<page string="Products">
|
||||
<field name="quant_ids">
|
||||
<tree string="Stock Moves">
|
||||
<field name="name"/>
|
||||
<field name="product_id"/>
|
||||
<field name="product_qty" on_change="onchange_quantity(product_id, product_qty, product_uom, product_uos)"/>
|
||||
<field name="product_uom" string="Unit of Measure" groups="product.group_uom"/>
|
||||
<field name="tracking_id" groups="stock.group_tracking_lot"/>
|
||||
<field name="date"/>
|
||||
<field name="prodlot_id"/>
|
||||
<field name="location_id" groups="stock.group_locations"/>
|
||||
<field name="location_dest_id" groups="stock.group_locations"/>
|
||||
<field name="state"/>
|
||||
</tree>
|
||||
</field>
|
||||
</page>
|
||||
|
@ -388,12 +344,10 @@
|
|||
<field name="model">stock.production.lot</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Serial Number">
|
||||
<field name="prefix"/>
|
||||
<field name="name"/>
|
||||
<field name="ref"/>
|
||||
<field name="product_id"/>
|
||||
<field name="stock_available"/>
|
||||
<field name="date"/>
|
||||
<field name="create_date"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
@ -403,7 +357,7 @@
|
|||
<field name="model">stock.production.lot</field>
|
||||
<field name="arch" type="xml">
|
||||
<search string="Product Lots Filter">
|
||||
<field name="name" string="Product Lots" filter_domain="['|','|',('name','ilike',self),('prefix','ilike',self),('ref','ilike',self)]"/>
|
||||
<field name="name" string="Product Lots" filter_domain="['|','|',('name','ilike',self),('ref','ilike',self)]"/>
|
||||
<field name="date"/>
|
||||
<filter icon="terp-check" name="available" string="Available" domain="[('stock_available', '>', 0)]" help="Available Product Lots"/>
|
||||
<field name="product_id"/>
|
||||
|
@ -446,7 +400,6 @@
|
|||
<record id="stock_move_tree" model="ir.ui.view">
|
||||
<field name="name">Stock Moves</field>
|
||||
<field name="model">stock.move</field>
|
||||
<field name="field_parent">move_history_ids</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree colors="grey:state == 'cancel'" string="Moves" create="false">
|
||||
<field name="product_id"/>
|
||||
|
@ -469,7 +422,6 @@
|
|||
<record id="stock_move_tree2" model="ir.ui.view">
|
||||
<field name="name">Stock Moves</field>
|
||||
<field name="model">stock.move</field>
|
||||
<field name="field_parent">move_history_ids2</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree colors="grey:state == 'cancel'" string="Moves" create="false">
|
||||
<field name="product_id"/>
|
||||
|
@ -535,7 +487,6 @@
|
|||
<field name="usage"/>
|
||||
<field name="partner_id"/>
|
||||
<field name="company_id" groups="base.group_multi_company" widget="selection"/>
|
||||
<field name="icon"/>
|
||||
<field name="scrap_location"/>
|
||||
<field name="active"/>
|
||||
</group>
|
||||
|
@ -628,7 +579,7 @@
|
|||
<field name="field_parent">child_ids</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree toolbar="1" string="Locations" >
|
||||
<field icon="icon" name="name"/>
|
||||
<field name="name"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
@ -773,7 +724,7 @@
|
|||
</h1>
|
||||
<group>
|
||||
<group>
|
||||
<field name="partner_id" on_change="onchange_partner_in(partner_id)"/>
|
||||
<field name="partner_id"/>
|
||||
<field name="backorder_id" readonly="1" attrs="{'invisible': [('backorder_id','=',False)]}"/>
|
||||
<field name="invoice_state" string="Invoice Control" groups="account.group_account_invoice" attrs="{'invisible':[('invoice_state', '=', 'none')]}"/>
|
||||
<field name="stock_journal_id" widget="selection" groups="account.group_account_user"/>
|
||||
|
@ -917,9 +868,6 @@
|
|||
<xpath expr="/form/header//field[@name='state']" position="replace">
|
||||
<field name="state" nolabel="1" readonly="1" widget="statusbar" statusbar_visible="draft,confirmed,assigned,done" statusbar_colors='{"auto":"blue", "confirmed":"blue"}'/>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='partner_id']" position="replace">
|
||||
<field name="partner_id" on_change="onchange_partner_in(partner_id)" string="Customer"/>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='move_lines']" position="replace">
|
||||
<field name="move_lines" context="{'address_out_id': partner_id, 'picking_type': 'out', 'form_view_ref':'view_move_picking_form', 'tree_view_ref':'view_move_picking_tree'}"/>
|
||||
</xpath>
|
||||
|
@ -1044,9 +992,6 @@
|
|||
<xpath expr="//button[@name='action_process']" position="replace">
|
||||
<button name="action_process" states="assigned" string="Receive" type="object" class="oe_highlight"/>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='partner_id']" position="replace">
|
||||
<field name="partner_id" on_change="onchange_partner_in(partner_id)" string="Supplier"/>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='move_lines']" position="replace">
|
||||
<field name="move_lines" context="{'address_in_id': partner_id, 'picking_type': 'in', 'form_view_ref':'view_move_picking_form', 'tree_view_ref':'view_move_picking_tree'}"/>
|
||||
</xpath>
|
||||
|
|
|
@ -69,7 +69,7 @@
|
|||
<record id="trans_assigned_move" model="workflow.transition">
|
||||
<field name="act_from" ref="act_assigned"/>
|
||||
<field name="act_to" ref="act_move"/>
|
||||
<field name="condition">auto_picking and test_auto_picking()</field>
|
||||
<field name="condition">auto_picking</field>
|
||||
</record>
|
||||
<record id="trans_assigned_move2" model="workflow.transition">
|
||||
<field name="act_from" ref="act_assigned"/>
|
||||
|
@ -89,7 +89,7 @@
|
|||
<record id="trans_assigned_cancel" model="workflow.transition">
|
||||
<field name="act_from" ref="act_assigned"/>
|
||||
<field name="act_to" ref="act_cancel"/>
|
||||
<field name="condition">allow_cancel()</field>
|
||||
<field name="condition">True</field>
|
||||
<field name="signal">button_cancel</field>
|
||||
</record>
|
||||
<record id="trans_confirmed_cancel" model="workflow.transition">
|
||||
|
|
|
@ -201,7 +201,6 @@ class stock_return_picking(osv.osv_memory):
|
|||
'location_id': new_location,
|
||||
'location_dest_id': move.location_id.id,
|
||||
'date': date_cur,
|
||||
'move_returned_from': move.id,
|
||||
})
|
||||
move_obj.write(cr, uid, [move.id], {'move_history_ids2':[(4,new_move)]}, context=context)
|
||||
if not returned_lines:
|
||||
|
|
|
@ -21,14 +21,9 @@
|
|||
from openerp.osv import osv, fields
|
||||
from openerp.tools.translate import _
|
||||
|
||||
|
||||
|
||||
|
||||
class procurement_order(osv.osv):
|
||||
_inherit = 'procurement.order'
|
||||
|
||||
|
||||
|
||||
def check_buy(self, cr, uid, ids, context=None):
|
||||
for procurement in self.browse(cr, uid, ids, context=context):
|
||||
for line in procurement.product_id.flow_pull_ids:
|
||||
|
@ -51,10 +46,7 @@ class procurement_order(osv.osv):
|
|||
return False
|
||||
|
||||
def action_move_create(self, cr, uid, ids, context=None):
|
||||
#Create moves from
|
||||
proc_obj = self.pool.get('procurement.order')
|
||||
move_obj = self.pool.get('stock.move')
|
||||
picking_obj=self.pool.get('stock.picking')
|
||||
for proc in proc_obj.browse(cr, uid, ids, context=context):
|
||||
line = None
|
||||
for line in proc.product_id.flow_pull_ids:
|
||||
|
@ -62,28 +54,8 @@ class procurement_order(osv.osv):
|
|||
break
|
||||
assert line, 'Line cannot be False if we are on this state of the workflow'
|
||||
origin = (proc.origin or proc.name or '').split(':')[0] +':'+line.name
|
||||
|
||||
#First do a search for moves which would not already have this picking:
|
||||
moves = move_obj.search(cr, uid, [('group_id', '=', proc.group_id.id), ('location_id', '=', line.location_src_id.id),
|
||||
('location_dest_id', '=', line.location_id.id), ('product_id', '=', proc.product_id.id),
|
||||
], context=context)
|
||||
print "moves, ", moves, proc.group_id.id
|
||||
if moves and move_obj.browse(cr, uid, moves[0], context=context).picking_id:
|
||||
picking_id = move_obj.browse(cr, uid, moves[0], context=context).picking_id.id
|
||||
else:
|
||||
picking_id = picking_obj.create(cr, uid, {
|
||||
'origin': origin,
|
||||
'company_id': line.company_id and line.company_id.id or False,
|
||||
'type': line.picking_type,
|
||||
'stock_journal_id': line.journal_id and line.journal_id.id or False,
|
||||
'move_type': 'one',
|
||||
'partner_id': line.partner_address_id.id,
|
||||
'note': _('Picking for pulled procurement coming from original location %s, pull rule %s, via original Procurement %s (#%d)') % (proc.location_id.name, line.name, proc.name, proc.id),
|
||||
'invoice_state': line.invoice_state,
|
||||
})
|
||||
move_id = move_obj.create(cr, uid, {
|
||||
'name': line.name,
|
||||
'picking_id': picking_id,
|
||||
'company_id': line.company_id and line.company_id.id or False,
|
||||
'product_id': proc.product_id.id,
|
||||
'date': proc.date_planned,
|
||||
|
@ -103,40 +75,5 @@ class procurement_order(osv.osv):
|
|||
'state': 'confirmed',
|
||||
'note': _('Move for pulled procurement coming from original location %s, pull rule %s, via original Procurement %s (#%d)') % (proc.location_id.name, line.name, proc.name, proc.id),
|
||||
})
|
||||
if proc.move_id and proc.move_id.state in ('confirmed'):
|
||||
move_obj.write(cr,uid, [proc.move_id.id], {
|
||||
'state':'waiting'
|
||||
}, context=context)
|
||||
proc_id = proc_obj.create(cr, uid, {
|
||||
'name': line.name,
|
||||
'origin': origin,
|
||||
'note': _('Pulled procurement coming from original location %s, pull rule %s, via original Procurement %s (#%d)') % (proc.location_id.name, line.name, proc.name, proc.id),
|
||||
'company_id': line.company_id and line.company_id.id or False,
|
||||
'date_planned': proc.date_planned,
|
||||
'product_id': proc.product_id.id,
|
||||
'product_qty': proc.product_qty,
|
||||
'product_uom': proc.product_uom.id,
|
||||
'product_uos_qty': (proc.product_uos and proc.product_uos_qty)\
|
||||
or proc.product_qty,
|
||||
'product_uos': (proc.product_uos and proc.product_uos.id)\
|
||||
or proc.product_uom.id,
|
||||
'location_id': line.location_src_id.id,
|
||||
'procure_method': line.procure_method,
|
||||
'move_id': move_id,
|
||||
'group_id': proc.group_id.id,
|
||||
})
|
||||
self.pool.get('stock.picking').signal_button_confirm(cr, uid, [picking_id])
|
||||
|
||||
self.signal_button_confirm(cr, uid, [proc_id])
|
||||
if proc.move_id:
|
||||
move_obj.write(cr, uid, [proc.move_id.id],
|
||||
{'location_id':proc.location_id.id})
|
||||
msg = _('Pulled from another location.')
|
||||
self.write(cr, uid, [proc.id], {'state':'running', 'message': msg})
|
||||
self.message_post(cr, uid, [proc.id], body=msg, context=context)
|
||||
# trigger direct processing (the new procurement shares the same planned date as the original one, which is already being processed)
|
||||
self.signal_button_check(cr, uid, [proc_id]) # TODO is it necessary to interleave the calls?
|
||||
move_obj.button_confirm(cr,uid, [move_id], context=context)
|
||||
return False
|
||||
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
|
@ -21,14 +21,32 @@
|
|||
|
||||
from openerp.osv import fields,osv
|
||||
|
||||
class stock_location_route(osv.osv):
|
||||
_name = 'stock.location.route'
|
||||
_description = "Inventory Routes"
|
||||
_order = 'sequence'
|
||||
_columns = {
|
||||
'name': fields.char('Route Name', required=True),
|
||||
'sequence': fields.integer('Sequence'),
|
||||
'pull_ids': fields.one2many('stock.location.pull', 'route_id', 'Pull Rules'),
|
||||
'push_ids': fields.one2many('stock.location.path', 'route_id', 'Push Rules'),
|
||||
|
||||
'journal_id': fields.many2one('stock.journal','Journal'),
|
||||
}
|
||||
_defaults = {
|
||||
'sequence': lambda self,cr,uid,ctx: 0,
|
||||
}
|
||||
|
||||
class stock_location_path(osv.osv):
|
||||
_name = "stock.location.path"
|
||||
_description = "Pushed Flows"
|
||||
_columns = {
|
||||
'name': fields.char('Operation', size=64),
|
||||
'company_id': fields.many2one('res.company', 'Company'),
|
||||
'route_id': fields.many2one('stock.location.route', 'Route'),
|
||||
|
||||
'product_id' : fields.many2one('product.product', 'Products', ondelete='cascade', select=1),
|
||||
'journal_id': fields.many2one('stock.journal','Journal'),
|
||||
|
||||
'location_from_id' : fields.many2one('stock.location', 'Source Location', ondelete='cascade', select=1, required=True),
|
||||
'location_dest_id' : fields.many2one('stock.location', 'Destination Location', ondelete='cascade', select=1, required=True),
|
||||
'delay': fields.integer('Delay (days)', help="Number of days to do this transition"),
|
||||
|
@ -46,7 +64,7 @@ class stock_location_path(osv.osv):
|
|||
"The 'Automatic Move' value will create a stock move after the current one that will be "\
|
||||
"validated automatically. With 'Manual Operation', the stock move has to be validated "\
|
||||
"by a worker. With 'Automatic No Step Added', the location is replaced in the original move."
|
||||
),
|
||||
),
|
||||
}
|
||||
_defaults = {
|
||||
'auto': 'auto',
|
||||
|
@ -54,6 +72,35 @@ class stock_location_path(osv.osv):
|
|||
'invoice_state': 'none',
|
||||
'picking_type': 'internal',
|
||||
}
|
||||
def _apply(self, cr, uid, rule, move, context=None):
|
||||
move_obj = self.pool.get('stock.move')
|
||||
newdate = (datetime.strptime(move.date, '%Y-%m-%d %H:%M:%S') + relativedelta(days=rule.delay or 0)).strftime('%Y-%m-%d')
|
||||
if rule.auto=='transparent':
|
||||
self.write(cr, uid, [move.id], {
|
||||
'date': newdate,
|
||||
'location_dest_id': rule.location_dest_id.id
|
||||
})
|
||||
vals = {}
|
||||
if route.journal_id:
|
||||
vals['stock_journal_id'] = route.journal_id.id
|
||||
vals['type'] = rule.picking_type
|
||||
if rule.location_dest_id.id<>move.location_dest_id.id:
|
||||
move_obj._push_apply(self, cr, uid, move.id, context):
|
||||
return move.id
|
||||
else:
|
||||
move_id = move_obj.copy(cr, uid, move.id, {
|
||||
'location_id': move.location_dest_id.id,
|
||||
'location_dest_id': rule.location_dest_id.id,
|
||||
'date': time.strftime('%Y-%m-%d'),
|
||||
'company_id': rule.company_id.id,
|
||||
'date_expected': newdate,
|
||||
)
|
||||
move_obj.write(cr, uid, [move.id], {
|
||||
'move_dest_id': move_id,
|
||||
})
|
||||
move_obj.action_confirm(self, cr, uid, [move_id], context=None)
|
||||
return move_id
|
||||
|
||||
|
||||
class product_pulled_flow(osv.osv):
|
||||
_name = 'product.pulled.flow'
|
||||
|
@ -61,15 +108,15 @@ class product_pulled_flow(osv.osv):
|
|||
_columns = {
|
||||
'name': fields.char('Name', size=64, required=True, help="This field will fill the packing Origin and the name of its moves"),
|
||||
'cancel_cascade': fields.boolean('Cancel Cascade', help="Allow you to cancel moves related to the product pull flow"),
|
||||
'route_id': fields.many2one('stock.location.route', 'Route'),
|
||||
'delay': fields.integer('Number of Hours'),
|
||||
'location_id': fields.many2one('stock.location','Destination Location', required=True, help="Is the destination location that needs supplying"),
|
||||
'location_src_id': fields.many2one('stock.location','Source Location', help="Location used by Destination Location to supply"),
|
||||
'journal_id': fields.many2one('stock.journal','Journal'),
|
||||
'procure_method': fields.selection([('make_to_stock','Make to Stock'),('make_to_order','Make to Order')], 'Procure Method', required=True, help="'Make to Stock': When needed, take from the stock or wait until re-supplying. 'Make to Order': When needed, purchase or produce for the procurement request."),
|
||||
'type_proc': fields.selection([('produce','Produce'),('buy','Buy'),('move','Move')], 'Type of Procurement', required=True),
|
||||
'company_id': fields.many2one('res.company', 'Company', help="Is used to know to which company the pickings and moves belong."),
|
||||
'partner_address_id': fields.many2one('res.partner', 'Partner Address'),
|
||||
'picking_type': fields.selection([('out','Sending Goods'),('in','Getting Goods'),('internal','Internal')], 'Shipping Type', required=True, select=True, help="Depending on the company, choose whatever you want to receive or send products"),
|
||||
'product_id':fields.many2one('product.product','Product'),
|
||||
'invoice_state': fields.selection([
|
||||
("invoiced", "Invoiced"),
|
||||
("2binvoiced", "To Be Invoiced"),
|
||||
|
@ -84,138 +131,151 @@ class product_pulled_flow(osv.osv):
|
|||
'invoice_state': 'none',
|
||||
'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'product.pulled.flow', context=c),
|
||||
}
|
||||
# FP Note: implement this
|
||||
def _apply(self, cr, uid, rule, move, context=None):
|
||||
newdate = (datetime.strptime(move.date, '%Y-%m-%d %H:%M:%S') - relativedelta(days=rule.delay or 0)).strftime('%Y-%m-%d %H:%M:%S')
|
||||
|
||||
proc_obj = self.pool.get('procurement.order')
|
||||
proc_id = proc_obj.create(cr, uid, {
|
||||
'name': move.name,
|
||||
'origin': move.origin,
|
||||
|
||||
'company_id': move.company_id and move.company_id.id or False,
|
||||
'date_planned': newdate,
|
||||
|
||||
'product_id': move.product_id.id,
|
||||
'product_qty': move.product_qty,
|
||||
'product_uom': move.product_uom.id,
|
||||
'product_uos_qty': (move.product_uos and move.product_uos_qty)\
|
||||
or move.product_qty,
|
||||
'product_uos': (move.product_uos and move.product_uos.id)\
|
||||
or move.product_uom.id,
|
||||
'location_id': move.location_id.id,
|
||||
'procure_method': rule.procure_method,
|
||||
})
|
||||
proc_obj.signal_button_confirm(cr, uid, [proc_id])
|
||||
msg = _('Pulled from another location.')
|
||||
self.message_post(cr, uid, [proc.id], body=msg, context=context)
|
||||
return True
|
||||
|
||||
class product_putaway_strategy(osv.osv):
|
||||
|
||||
def _calc_product_ids(self, cr, uid, ids, field, arg, context=None):
|
||||
'''
|
||||
This function should check on which products (including if the products are in a product category) this putaway strategy is used
|
||||
'''
|
||||
pass
|
||||
|
||||
_name = 'product.putaway'
|
||||
_description = 'Put Away Strategy'
|
||||
_columns = {
|
||||
'product_ids':fields.function(_calc_product_ids, "Products"),
|
||||
'product_categ_id':fields.many2one('product.category', 'Product Category', required=True),
|
||||
'location_id': fields.many2one('stock.location','Parent Location', help="Parent Destination Location from which a child bin location needs to be chosen", required=True), #domain=[('type', '=', 'parent')],
|
||||
'method': fields.selection([('empty', 'Empty'), ('fixed', 'Fixed Location')], "Method", required = True),
|
||||
}
|
||||
}
|
||||
|
||||
# TODO: move this on stock module
|
||||
|
||||
class product_removal_strategy(osv.osv):
|
||||
|
||||
def _calc_product_ids(self, cr, uid, ids, field, arg, context=None):
|
||||
'''
|
||||
This function should check on which products (including if the products are in a product category) this removal strategy is used
|
||||
'''
|
||||
pass
|
||||
|
||||
_name = 'product.removal'
|
||||
_description = 'Removal Strategy'
|
||||
_inherit = 'product.removal'
|
||||
_order = 'sequence'
|
||||
_columns = {
|
||||
'product_ids':fields.function(_calc_product_ids, "Products"),
|
||||
'product_categ_id':fields.many2one('product.category', 'Product Category', required=True),
|
||||
'location_id': fields.many2one('stock.location', 'Parent Location', help="Parent Source Location from which a child bin location needs to be chosen", required=True), #, domain=[('type', '=', 'parent')]
|
||||
'method': fields.selection([('fifo', 'FIFO'), ('lifo', 'LIFO')], "Method", required=True),
|
||||
}
|
||||
|
||||
|
||||
|
||||
'sequence': fields.integer('Sequence'),
|
||||
'location_id': fields.many2one('stock.location', 'Locations'),
|
||||
}
|
||||
|
||||
class product_product(osv.osv):
|
||||
_inherit = 'product.product'
|
||||
_columns = {
|
||||
'flow_pull_ids': fields.one2many('product.pulled.flow', 'product_id', 'Pulled Flows'),
|
||||
'path_ids': fields.one2many('stock.location.path', 'product_id',
|
||||
'Pushed Flow',
|
||||
help="These rules set the right path of the product in the "\
|
||||
"whole location tree.")
|
||||
'route_ids': fields.many2many('stock.location.path', 'Routes'),
|
||||
}
|
||||
|
||||
|
||||
class product_category(osv.osv):
|
||||
_inherit = 'product.category'
|
||||
_columns = {
|
||||
#'route_ids': fields.many2many('stock.route', 'product_catg_id', 'route_id', 'Routes'),
|
||||
'removal_strategy_ids': fields.one2many('product.removal', 'product_categ_id', 'Removal Strategies'),
|
||||
'putaway_strategy_ids': fields.one2many('product.putaway', 'product_categ_id', 'Put Away Strategies'),
|
||||
}
|
||||
|
||||
|
||||
|
||||
class stock_move(osv.osv):
|
||||
_name = 'stock.move.putaway'
|
||||
_description = 'Proposed Destination'
|
||||
_columns = {
|
||||
'move_id': fields.many2one('stock.move', required=True),
|
||||
'location_id': fields.many2one('stock.location', 'Location', required=True),
|
||||
'lot_id': fields.many2one('stock.production.lot', 'Lot'),
|
||||
'quantity': fields.float('Quantity', required=True),
|
||||
}
|
||||
|
||||
class stock_move(osv.osv):
|
||||
_inherit = 'stock.move'
|
||||
_columns = {
|
||||
'cancel_cascade': fields.boolean('Cancel Cascade', help='If checked, when this move is cancelled, cancel the linked move too')
|
||||
'cancel_cascade': fields.boolean('Cancel Cascade', help='If checked, when this move is cancelled, cancel the linked move too'),
|
||||
'putaway_ids': fields.one2many('stock.move.putaway', 'move_id', 'Put Away Suggestions')
|
||||
}
|
||||
def action_cancel(self, cr, uid, ids, context=None):
|
||||
for m in self.browse(cr, uid, ids, context=context):
|
||||
if m.cancel_cascade and m.move_dest_id:
|
||||
self.action_cancel(cr, uid, [m.move_dest_id.id], context=context)
|
||||
res = super(stock_move,self).action_cancel(cr,uid,ids,context)
|
||||
return res
|
||||
|
||||
def splitforputaway (self, cr, uid, ids, context=None):
|
||||
'''
|
||||
Splits this move in order to do the put away
|
||||
|
||||
Happens at move getting done
|
||||
'''
|
||||
putaway_obj = self.pool.get("product.putaway")
|
||||
location_obj = self.pool.get("stock.location")
|
||||
quant_obj = self.pool.get("stock.quant")
|
||||
for move in self.browse(cr, uid, ids, context=context):
|
||||
putaways = putaway_obj.search(cr, uid, [('product_categ_id','=', move.product_id.categ_id.id), ('location_id', '=', move.location_dest_id.id)], context=context)
|
||||
print putaways
|
||||
if putaways:
|
||||
#Search for locations for PutAway
|
||||
locs = location_obj.search(cr, uid, [('id', 'child_of', move.location_dest_id.id), ('id', '!=', move.location_dest_id.id), ('quant_ids', '=', False),
|
||||
('destination_move_ids', '=', False)], context=context)
|
||||
if locs:
|
||||
quants = quant_obj.search(cr, uid, [('history_ids', 'in', move.id)])
|
||||
quant_obj.write(cr, uid, quants, {'location_id': locs[0]}, context=context)
|
||||
def _pull_apply(self, cr, uid, moves, context):
|
||||
for move in moves:
|
||||
for route in move.product_id.route_ids:
|
||||
found = False
|
||||
for rule in route.pull_ids:
|
||||
if rule.location_id.id == move.location_id.id:
|
||||
self.pool.get('stock.location.pull')._apply(cr, uid, rule, move, context=context)
|
||||
found = True
|
||||
break
|
||||
if found: break
|
||||
return True
|
||||
|
||||
def _push_apply(self, cr, uid, moves, context):
|
||||
for move in moves:
|
||||
for route in move.product_id.route_ids:
|
||||
found = False
|
||||
for rule in route.push_ids:
|
||||
if rule.location_from_id.id == move.location_dest_id.id:
|
||||
self.pool.get('stock.location.path')._apply(cr, uid, rule, move, context=context)
|
||||
found = True
|
||||
break
|
||||
if found: break
|
||||
return True
|
||||
|
||||
# Create the stock.move.putaway records
|
||||
def _putaway_apply(self,cr, uid, ids, context=None):
|
||||
for move in self.browse(cr, uid, ids, context=context):
|
||||
res = self.pool.get('stock.location').get_putaway_strategy(cr, uid, move.location_dest_id.id, move.product_id.id, context=context)
|
||||
if res:
|
||||
raise 'put away strategies not implemented yet!'
|
||||
return True
|
||||
|
||||
def _prepare_chained_picking(self, cr, uid, picking_name, picking, picking_type, moves_todo, context=None):
|
||||
res = super(stock_move, self)._prepare_chained_picking(cr, uid, picking_name, picking, picking_type, moves_todo, context=context)
|
||||
res.update({'invoice_state': moves_todo[0][1][6] or 'none'})
|
||||
return res
|
||||
def action_assign(self, cr, uid, ids, context=None):
|
||||
result = super(stock_move, self).action_assign(cr, uid, ids, context=context)
|
||||
self._putaway_apply(cr, uid, ids, context=context)
|
||||
return result
|
||||
|
||||
def action_confirm(self, cr, uid, ids, context=None):
|
||||
result = super(stock_move, self).action_confirm(cr, uid, ids, context)
|
||||
moves = self.browse(cr, uid, ids, context=context)
|
||||
self._pull_apply(cr, uid, ids, context=context)
|
||||
self._push_apply(cr, uid, ids, context=context)
|
||||
return result
|
||||
|
||||
class stock_location(osv.osv):
|
||||
_inherit = 'stock.location'
|
||||
_columns = {
|
||||
'removal_strategy_ids': fields.one2many('product.removal', 'location_id', 'Removal Strategies'),
|
||||
'putaway_strategy_ids': fields.one2many('product.putaway', 'location_id', 'Put Away Strategies'),
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
def get_putaway_strategy(self, cr, uid, id, product_id, context=None):
|
||||
product = self.pool.get("product.product").browse(cr, uid, product_id, context=context)
|
||||
strats = self.pool.get('product.removal').search(cr, uid, [('location_id','=',id), ('product_categ_id','child_of', product.categ_id.id)], context=context) #Also child_of for location???
|
||||
return strats and strats[0] or 'nearest'
|
||||
strats = self.pool.get('product.removal').search(cr, uid, [('location_id','=',id), ('product_categ_id','child_of', product.categ_id.id)], context=context)
|
||||
return strats and strats[0] or None
|
||||
|
||||
def get_removal_strategy(self, cr, uid, id, product_id, context=None):
|
||||
#TODO improve code
|
||||
pr = self.pool.get('product.removal')
|
||||
product = self.pool.get("product.product").browse(cr, uid, product_id, context=context)
|
||||
strats = self.pool.get('product.removal').search(cr, uid, [('location_id','=',id), ('product_categ_id','=', product.categ_id.id)], context=context) #Also child_of for location???
|
||||
if not strats:
|
||||
strat = product.categ_id.removal_strategy
|
||||
else:
|
||||
strat = strats[0]
|
||||
return strat or product.categ_id.removal_strategy or 'fifo'
|
||||
categ = product.categ_id
|
||||
categs = [categ.id, False]
|
||||
while categ.parent_id:
|
||||
categ = categ.parent_id
|
||||
categs.append(categ.id)
|
||||
|
||||
result = pr.search(cr,uid, [
|
||||
('location_id', '=', id),
|
||||
('category_ids', 'in', categs)
|
||||
], context=context)
|
||||
if result:
|
||||
return pr.browse(cr, uid, result[0], context=context)
|
||||
return super(stock_location, self).get_removal_strategy(cr, uid, id, product_id, context=context)
|
||||
|
||||
|
||||
def chained_location_get(self, cr, uid, location, partner=None, product=None, context=None):
|
||||
if product:
|
||||
for path in product.path_ids:
|
||||
if path.location_from_id.id == location.id:
|
||||
return path.location_dest_id, path.auto, path.delay, path.journal_id and path.journal_id.id or False, path.company_id and path.company_id.id or False, path.picking_type, path.invoice_state
|
||||
return super(stock_location, self).chained_location_get(cr, uid, location, partner, product, context)
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
Loading…
Reference in New Issue