[REF] some refactoring

bzr revid: qdp-launchpad@openerp.com-20131023134021-jf2n0l1coh7uuc0c
This commit is contained in:
Quentin (OpenERP) 2013-10-23 15:40:21 +02:00
parent f2b9d8f05f
commit 45c990e833
14 changed files with 98 additions and 183 deletions

View File

@ -1,7 +1,7 @@
-
Set "can_manufacture_for_resupply" at true for warehouse0 by default
Enable the manufacturing in warehouse0
-
!python {model: stock.warehouse}: |
main_warehouse = self.browse(cr, uid, ref('stock.warehouse0'), context=context)
self.write(cr,uid,main_warehouse.id,{'can_manufacture_for_resupply':True},context=context)
self.write(cr, uid, main_warehouse.id, {'manufacture_to_resupply': True}, context=context)

View File

@ -1035,7 +1035,7 @@
<field name="inherit_id" ref="stock.view_warehouse"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='default_resupply_wh_id']" position="after">
<field name="can_manufacture_for_resupply" />
<field name="manufacture_to_resupply" />
</xpath>
</field>
</record>

View File

@ -164,7 +164,6 @@ class StockPicking(osv.osv):
return list(set(todo))
class split_in_production_lot(osv.osv_memory):
_inherit = "stock.move.split"
@ -182,19 +181,13 @@ class split_in_production_lot(osv.osv_memory):
class stock_warehouse(osv.osv):
_inherit = 'stock.warehouse'
_columns = {
'can_manufacture_for_resupply': fields.boolean('Can manufacture for resupply this warehouse'),
'manufacture_pull_id': fields.many2one('procurement.rule', 'Manufacture rule'),
_columns = {
'manufacture_to_resupply': fields.boolean('Manufacture in this Warehouse'),
'manufacture_pull_id': fields.many2one('procurement.rule', 'Manufacture Rule'),
}
_defaults= {
'manufacture_pull_id' : False
}
def _get_manufacture_pull_rule(self, cr, uid, warehouse, context=None):
if not warehouse.can_manufacture_for_resupply:
return False
#
route_obj = self.pool.get('stock.location.route')
def _get_manufacture_pull_rule(self, cr, uid, warehouse, context=None):
route_obj = self.pool.get('stock.location.route')
data_obj = self.pool.get('ir.model.data')
try:
manufacture_route_id = data_obj.get_object_reference(cr, uid, 'stock', 'route_warehouse0_manufacture')[1]
@ -202,68 +195,56 @@ class stock_warehouse(osv.osv):
manufacture_route_id = route_obj.search(cr, uid, [('name', 'like', _('Manufacture'))], context=context)
manufacture_route_id = manufacture_route_id and manufacture_route_id[0] or False
if not manufacture_route_id:
raise osv.except_osv(_('Error!'), _('Can\'t find any generic Manufacture route.'))
dest_loc = warehouse.in_type_id
raise osv.except_osv(_('Error!'), _('Can\'t find any generic Manufacture route.'))
return {
'name': warehouse.name + ': ' + _(' Manufacture') + ' -> ' + dest_loc.name,
'name': self._format_routename(cr, uid, warehouse, _(' Manufacture'), context=context),
'location_id': warehouse.lot_stock_id.id,
'route_id': manufacture_route_id,
'action': 'manufacture',
'picking_type_id': dest_loc.id,
'picking_type_id': warehouse.int_type_id.id,
'procure_method': 'make_to_order',
'active': True,
}
def create_routes(self, cr, uid, ids, warehouse, context=None):
pull_obj = self.pool.get('procurement.rule')
def create_routes(self, cr, uid, ids, warehouse, context=None):
pull_obj = self.pool.get('procurement.rule')
res = super(stock_warehouse, self).create_routes(cr, uid, ids, warehouse, context=context)
manufacture_pull_vals = self._get_manufacture_pull_rule(cr, uid, warehouse, context=context)
if manufacture_pull_vals:
if warehouse.manufacture_to_resupply:
manufacture_pull_vals = self._get_manufacture_pull_rule(cr, uid, warehouse, context=context)
manufacture_pull_id = pull_obj.create(cr, uid, manufacture_pull_vals, context=context)
res['manufacture_pull_id'] = manufacture_pull_id
else:
res['manufacture_pull_id'] = False
return res
def write(self, cr, uid, ids, vals, context=None):
pull_obj = self.pool.get('procurement.rule')
if isinstance(ids, (int, long)):
ids = [ids]
#only if update and checkbox have changed !
if not vals.get("can_manufacture_for_resupply",None) is None:
if vals.get("can_manufacture_for_resupply",False):
if 'manufacture_to_resupply' in vals:
if vals.get("manufacture_to_resupply"):
for warehouse in self.browse(cr, uid, ids, context=context):
if not warehouse.manufacture_pull_id:
warehouse.can_manufacture_for_resupply = True
manufacture_pull_vals = self._get_manufacture_pull_rule(cr, uid, warehouse, context=context)
manufacture_pull_id = pull_obj.create(cr, uid, manufacture_pull_vals, context=context)
vals['manufacture_pull_id'] = manufacture_pull_id
else:
for warehouse in self.browse(cr, uid, ids, context=context):
for warehouse in self.browse(cr, uid, ids, context=context):
if warehouse.manufacture_pull_id:
pull_obj.unlink(cr, uid, warehouse.manufacture_pull_id.id, context=context)
vals['manufacture_pull_id'] = False
return super(stock_warehouse,self).write(cr, uid, ids, vals, context=None)
pull_obj.unlink(cr, uid, warehouse.manufacture_pull_id.id, context=context)
return super(stock_warehouse, self).write(cr, uid, ids, vals, context=None)
def get_all_routes_for_wh(self, cr, uid, warehouse, context=None):
all_routes = super(stock_warehouse,self).get_all_routes_for_wh(cr,uid,warehouse,context=context)
if warehouse.can_manufacture_for_resupply and warehouse.manufacture_pull_id and warehouse.manufacture_pull_id.route_id:
all_routes += [warehouse.manufacture_pull_id.route_id.id]
all_routes = super(stock_warehouse, self).get_all_routes_for_wh(cr, uid, warehouse, context=context)
if warehouse.manufacture_to_resupply and warehouse.manufacture_pull_id and warehouse.manufacture_pull_id.route_id:
all_routes += [warehouse.manufacture_pull_id.route_id.id]
return all_routes
def _get_all_products_to_resupply(self, cr, uid, warehouse, context=None):
res = super(stock_warehouse,self)._get_all_products_to_resupply(cr, uid, warehouse, context=context)
if warehouse.manufacture_pull_id and warehouse.manufacture_pull_id.route_id:
res = super(stock_warehouse, self)._get_all_products_to_resupply(cr, uid, warehouse, context=context)
if warehouse.manufacture_pull_id and warehouse.manufacture_pull_id.route_id:
for product_id in res:
for route in self.pool.get('product.product').browse(cr, uid, product_id, context=context).route_ids:
if route.id == warehouse.manufacture_pull_id.route_id.id:
res.remove(product_id)
break
for route in self.pool.get('product.product').browse(cr, uid, product_id, context=context).route_ids:
if route.id == warehouse.manufacture_pull_id.route_id.id:
res.remove(product_id)
break
return res

View File

@ -65,7 +65,6 @@ Dashboard / Reports for Purchase Management will include:
'report/purchase_report_view.xml',
'board_purchase_view.xml',
'edi/purchase_order_action_data.xml',
'purchase_stock_data.yml',
'res_config_view.xml',
],
'test': [

View File

@ -62,26 +62,14 @@
<!--
Procurement rules and routes
-->
-->
<record id="route_warehouse0_buy" model='stock.location.route'>
<field name="name">Buy</field>
<field name="sequence">5</field>
</record>
<!-- TODO: use a yaml file with python code to enable purcahse on main warehouse, so that the location_id is correct -->
<!--
<record id="procurement_rule_supply_stock" model="procurement.rule">
<field name="name">WH: Buy</field>
<field name="action">buy</field>
<field name="location_id" ref="stock.stock_location_stock"/>
<field name="picking_type_id" ref="stock.picking_type_in"/>
<field name="route_id" ref="route_warehouse0_buy"/>
</record>
-->
</data>
</openerp>

View File

@ -2,5 +2,12 @@
!python {model: ir.values, id: purchase_default_set}: |
whr = self.pool.get('stock.warehouse').browse(cr, uid, ref('stock.warehouse0'), context=context)
self.set(cr, uid, 'default',False,'picking_type_id', [('purchase.order', False)], whr.in_type_id.id, True, False, False, False, True)
-
!python {model: stock.warehouse}: |
main_warehouse = self.browse(cr, uid, ref('stock.warehouse0'), context=context)
#Force the rewriting of route and rule
self.write(cr, uid, main_warehouse.id, {'buy_to_resupply': True}, context=context)

View File

@ -1,6 +0,0 @@
-
!python {model: stock.warehouse}: |
main_warehouse = self.browse(cr, uid, ref('stock.warehouse0'), context=context)
#Force the rewriting of route and rule
self.write(cr,uid,main_warehouse.id,{'can_buy_for_resupply':True},context=context)

View File

@ -5,7 +5,7 @@
for wh_ref in wh_to_assign:
warehouse = self.browse(cr, uid, ref('stock.' + wh_ref), context=context)
#Force the rewriting of route and rule
self.write(cr,uid,warehouse.id,{'can_buy_for_resupply':True},context=context)
self.write(cr, uid, warehouse.id, {'buy_to_resupply': True}, context=context)

View File

@ -77,20 +77,16 @@ class stock_picking(osv.osv):
class stock_warehouse(osv.osv):
_inherit = 'stock.warehouse'
_columns = {
'can_buy_for_resupply': fields.boolean('Can buy for resupply this warehouse'),
'buy_pull_id': fields.many2one('procurement.rule', 'BUY rule'),
_columns = {
'buy_to_resupply': fields.boolean('Purchase to resupply this warehouse'),
'buy_pull_id': fields.many2one('procurement.rule', 'BUY rule'),
}
_defaults= {
_defaults = {
'can_buy_for_resupply': True,
'buy_pull_id' : False
}
def _get_buy_pull_rule(self, cr, uid, warehouse, context=None):
if not warehouse.can_buy_for_resupply:
return False
#
route_obj = self.pool.get('stock.location.route')
def _get_buy_pull_rule(self, cr, uid, warehouse, context=None):
route_obj = self.pool.get('stock.location.route')
data_obj = self.pool.get('ir.model.data')
try:
buy_route_id = data_obj.get_object_reference(cr, uid, 'stock', 'route_warehouse0_buy')[1]
@ -98,66 +94,56 @@ class stock_warehouse(osv.osv):
buy_route_id = route_obj.search(cr, uid, [('name', 'like', _('Buy'))], context=context)
buy_route_id = buy_route_id and buy_route_id[0] or False
if not buy_route_id:
raise osv.except_osv(_('Error!'), _('Can\'t find any generic Buy route.'))
dest_loc = warehouse.in_type_id
raise osv.except_osv(_('Error!'), _('Can\'t find any generic Buy route.'))
return {
'name': warehouse.name + ': ' + _(' Buy') + ' -> ' + dest_loc.name,
'name': self._format_routename(cr, uid, warehouse, _(' Buy'), context=context),
'location_id': warehouse.wh_input_stock_loc_id.id,
'route_id': buy_route_id,
'action': 'move',
'picking_type_id': dest_loc.id,
'action': 'buy',
'picking_type_id': warehouse.in_type_id.id,
'procure_method': 'make_to_order',
'active': True,
}
def create_routes(self, cr, uid, ids, warehouse, context=None):
pull_obj = self.pool.get('procurement.rule')
def create_routes(self, cr, uid, ids, warehouse, context=None):
pull_obj = self.pool.get('procurement.rule')
res = super(stock_warehouse, self).create_routes(cr, uid, ids, warehouse, context=context)
buy_pull_vals = self._get_buy_pull_rule(cr, uid, warehouse, context=context)
if buy_pull_vals:
if warehouse.buy_to_resupply:
buy_pull_vals = self._get_buy_pull_rule(cr, uid, warehouse, context=context)
buy_pull_id = pull_obj.create(cr, uid, buy_pull_vals, context=context)
res['buy_pull_id'] = buy_pull_id
else:
res['buy_pull_id'] = False
return res
def write(self, cr, uid, ids, vals, context=None):
pull_obj = self.pool.get('procurement.rule')
if isinstance(ids, (int, long)):
ids = [ids]
#only if update and checkbox have changed !
if not vals.get("can_buy_for_resupply",None) is None:
if vals.get("can_buy_for_resupply",False):
if 'buy_to_resupply' in vals:
if vals.get("buy_to_resupply"):
for warehouse in self.browse(cr, uid, ids, context=context):
if not warehouse.buy_pull_id:
warehouse.can_buy_for_resupply = True
buy_pull_vals = self._get_buy_pull_rule(cr, uid, warehouse, context=context)
buy_pull_id = pull_obj.create(cr, uid, buy_pull_vals, context=context)
vals['buy_pull_id'] = buy_pull_id
else:
for warehouse in self.browse(cr, uid, ids, context=context):
for warehouse in self.browse(cr, uid, ids, context=context):
if warehouse.buy_pull_id:
buy_pull_id = pull_obj.unlink(cr, uid, warehouse.buy_pull_id.id, context=context)
vals['buy_pull_id'] = False
return super(stock_warehouse,self).write(cr, uid, ids, vals, context=None)
buy_pull_id = pull_obj.unlink(cr, uid, warehouse.buy_pull_id.id, context=context)
return super(stock_warehouse, self).write(cr, uid, ids, vals, context=None)
def get_all_routes_for_wh(self, cr, uid, warehouse, context=None):
all_routes = super(stock_warehouse,self).get_all_routes_for_wh(cr,uid,warehouse,context=context)
all_routes = super(stock_warehouse, self).get_all_routes_for_wh(cr, uid, warehouse, context=context)
if warehouse.can_buy_for_resupply and warehouse.buy_pull_id and warehouse.buy_pull_id.route_id:
all_routes += [warehouse.buy_pull_id.route_id.id]
all_routes += [warehouse.buy_pull_id.route_id.id]
return all_routes
def _get_all_products_to_resupply(self, cr, uid, warehouse, context=None):
res = super(stock_warehouse,self)._get_all_products_to_resupply(cr, uid, warehouse, context=context)
res = super(stock_warehouse, self)._get_all_products_to_resupply(cr, uid, warehouse, context=context)
if warehouse.buy_pull_id and warehouse.buy_pull_id.route_id:
for product_id in res:
for route in self.pool.get('product.product').browse(cr, uid, product_id, context=context).route_ids:
if route.id == warehouse.buy_pull_id.route_id.id:
res.remove(product_id)
break
return res
for route in self.pool.get('product.product').browse(cr, uid, product_id, context=context).route_ids:
if route.id == warehouse.buy_pull_id.route_id.id:
res.remove(product_id)
break
return res

View File

@ -47,12 +47,10 @@
<field name="inherit_id" ref="stock.view_warehouse"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='default_resupply_wh_id']" position="after">
<field name="can_buy_for_resupply" />
<field name="buy_to_resupply" />
</xpath>
</field>
</record>
<record id="action_picking_tree_picking_to_invoice" model="ir.actions.act_window">
<field name="name">On Incoming Shipments</field>

View File

@ -65,7 +65,7 @@ Dashboard / Reports for Warehouse Management will include:
'stock_orderpoint.yml',
'stock_demo.yml',
'stock_location_demo_cpu1.xml',
'stock_location_demo_cpu3.yml',
'stock_location_demo_cpu3.yml',
],
'data': [
'security/stock_security.xml',
@ -113,7 +113,7 @@ Dashboard / Reports for Warehouse Management will include:
'static/lib/sparkline/jquery.sparkline.js',
'static/lib/justgage.js',
'static/src/js/stock_picking_type.js',
'static/src/js/widgets.js',
'static/src/js/widgets.js',
],
'qweb': ['static/src/xml/picking.xml'],
}

View File

@ -234,30 +234,6 @@ picking, batch picking and "by order" picking.
</div>
</section>
<section class="oe_container oe_dark">
<div class="oe_row">
<h2 class="oe_slogan">Double Entry Inventory Management</h2>
<h3 class="oe_slogan">Nothing is lost, everything is moved</h3>
<div class="oe_span6">
<p class='oe_mt32'>
Based on the concept of double entry that revolutionized accounting, OpenERP's
inventory management isn't about consumption, loss or missing products;
products are just moved from one location to another.
</p><p>
This allows full traceability (from customer to supplier, not limited to your
warehouse), advanced reporting (e.g. inventory valuation on manufacturing
counter-parts locations) and a very simple user interface.
</p>
</div>
<div class="oe_span6">
<div class="oe_bg_img oe_centered">
<img class="oe_picture" src="warehouse_illu_02.png">
</div>
</div>
</div>
</section>
<section class="oe_container oe_dark">
<div class="oe_row">
<h2 class="oe_slogan">Cross-Docking some products</h2>
@ -363,6 +339,5 @@ efficiently incoming materials.
</div>
</section>
<section class="oe_container oe_separator">
</section>

View File

@ -2280,11 +2280,10 @@ class stock_warehouse(osv.osv):
'resupply_wh_ids': fields.many2many('stock.warehouse', 'stock_wh_resupply_table', 'supplied_wh_id', 'supplier_wh_id', 'Resupply Warehouses'),
'resupply_route_ids': fields.one2many('stock.location.route', 'supplied_wh_id', 'Resupply Routes'),
'default_resupply_wh_id': fields.many2one('stock.warehouse', 'Default Resupply Warehouse', domain="[('id','in',resupply_init_filter)]"),
'show_default_resupply_wh_id': fields.function(show_field_default_wh_resupply,type='boolean',string="Show field default_resupply_wh_id"),
'resupply_init_filter' : fields.function(init_filtre_default_resupply_wh_id, type='many2one', string='test',relation='stock.warehouse'),
}
'show_default_resupply_wh_id': fields.function(show_field_default_wh_resupply,type='boolean',string="Show field default_resupply_wh_id"),
'resupply_init_filter' : fields.function(init_filtre_default_resupply_wh_id, type='many2one', string='test',relation='stock.warehouse'),
}
def onchange_filtre_default_resupply_wh_id(self, cr, uid, ids, resupply_wh_ids,default_resupply_wh_id, context=None):
resupply_wh_ids = [x['id'] for x in (self.resolve_2many_commands(cr, uid, 'resupply_wh_ids',resupply_wh_ids, ['id']))]
print(default_resupply_wh_id,resupply_wh_ids)
@ -2303,7 +2302,7 @@ class stock_warehouse(osv.osv):
'domain':{ 'default_resupply_wh_id':[('id','in',resupply_wh_ids)] },
'warning': warning
}
def _get_inter_wh_location(self, cr, uid, warehouse, context=None):
''' returns a tuple made of the browse record of customer location and the browse record of supplier location'''
data_obj = self.pool.get('ir.model.data')
@ -2371,7 +2370,7 @@ class stock_warehouse(osv.osv):
}
_sql_constraints = [
('warehouse_name_uniq', 'unique(name, company_id)', 'The name of the warehouse must be unique per company!'),
('warehouse_code_uniq', 'unique(code, company_id)', 'The code of the warehouse must be unique per company !'),
('warehouse_code_uniq', 'unique(code, company_id)', 'The code of the warehouse must be unique per company !'),
]
def _get_partner_locations(self, cr, uid, ids, context=None):
@ -2527,12 +2526,12 @@ class stock_warehouse(osv.osv):
#return routes and mto pull rule for warehouse
return {
'route_ids': wh_route_ids,
'mto_pull_id': mto_pull_id,
'reception_route_id': reception_route_id,
'delivery_route_id': delivery_route_id,
'crossdock_route_id': crossdock_route_id,
}
'route_ids': wh_route_ids,
'mto_pull_id': mto_pull_id,
'reception_route_id': reception_route_id,
'delivery_route_id': delivery_route_id,
'crossdock_route_id': crossdock_route_id,
}
def change_route(self, cr, uid, ids, warehouse, new_reception_step=False, new_delivery_step=False, context=None):
picking_type_obj = self.pool.get('stock.picking.type')
@ -2588,7 +2587,6 @@ class stock_warehouse(osv.osv):
def create(self, cr, uid, vals, context=None):
if context is None:
context = {}
if vals is None:
vals = {}
data_obj = self.pool.get('ir.model.data')
@ -2717,8 +2715,8 @@ class stock_warehouse(osv.osv):
warehouse.refresh()
#create routes and push/pull rules
ret = self.create_routes(cr, uid, new_id, warehouse, context=context)
self.write(cr, uid, warehouse.id, ret , context=context)
new_objects_dict = self.create_routes(cr, uid, new_id, warehouse, context=context)
self.write(cr, uid, warehouse.id, new_objects_dict, context=context)
return new_id
def _format_rulename(self, cr, uid, obj, from_loc, dest_loc, context=None):
@ -2738,7 +2736,7 @@ class stock_warehouse(osv.osv):
'crossdock': (_('Cross-Dock'), [(warehouse.wh_input_stock_loc_id, warehouse.wh_output_stock_loc_id, warehouse.int_type_id.id), (warehouse.wh_output_stock_loc_id, customer_loc, warehouse.out_type_id.id)]),
'ship_only': (_('Ship Only'), [(warehouse.lot_stock_id, customer_loc, warehouse.out_type_id.id)]),
'pick_ship': (_('Pick + Ship'), [(warehouse.lot_stock_id, warehouse.wh_output_stock_loc_id, warehouse.pick_type_id.id), (warehouse.wh_output_stock_loc_id, customer_loc, warehouse.out_type_id.id)]),
'pick_pack_ship': (_('Pick + Pack + Ship'), [(warehouse.lot_stock_id, warehouse.wh_pack_stock_loc_id, warehouse.int_type_id.id), (warehouse.wh_pack_stock_loc_id, warehouse.wh_output_stock_loc_id, warehouse.pack_type_id.id), (warehouse.wh_output_stock_loc_id, customer_loc, warehouse.out_type_id.id)]),
'pick_pack_ship': (_('Pick + Pack + Ship'), [(warehouse.lot_stock_id, warehouse.wh_pack_stock_loc_id, warehouse.int_type_id.id), (warehouse.wh_pack_stock_loc_id, warehouse.wh_output_stock_loc_id, warehouse.pack_type_id.id), (warehouse.wh_output_stock_loc_id, customer_loc, warehouse.out_type_id.id)]),
}
def write(self, cr, uid, ids, vals, context=None):
@ -2746,7 +2744,6 @@ class stock_warehouse(osv.osv):
context = {}
if isinstance(ids, (int, long)):
ids = [ids]
seq_obj = self.pool.get('ir.sequence')
location_obj = self.pool.get('stock.location')
route_obj = self.pool.get('stock.location.route')
@ -3227,16 +3224,6 @@ class stock_warehouse_orderpoint(osv.osv):
return True
def _check_uniq_name(self, cr, uid, ids, context=None):
if not context:
context = {}
for name in self.browse(cr, uid, ids, context=context):
if rule.product_id.uom_id.category_id.id != rule.product_uom.category_id.id:
return False
return True
_columns = {
'name': fields.char('Name', size=32, required=True),
'active': fields.boolean('Active', help="If the active field is set to False, it will allow you to hide the orderpoint without removing it."),
@ -3267,10 +3254,10 @@ class stock_warehouse_orderpoint(osv.osv):
'company_id': lambda self, cr, uid, context: self.pool.get('res.company')._company_default_get(cr, uid, 'stock.warehouse.orderpoint', context=context)
}
_sql_constraints = [
('qty_multiple_check', 'CHECK( qty_multiple > 0 )', 'Qty Multiple must be greater than zero.'),
('qty_multiple_check', 'CHECK( qty_multiple > 0 )', 'Qty Multiple must be greater than zero.'),
]
_constraints = [
(_check_product_uom, 'You have to select a product unit of measure in the same category than the default unit of measure of the product', ['product_id', 'product_uom']),
(_check_product_uom, 'You have to select a product unit of measure in the same category than the default unit of measure of the product', ['product_id', 'product_uom']),
]
def default_get(self, cr, uid, fields, context=None):

View File

@ -676,7 +676,7 @@
</page>
<page string="Technical Information" groups='base.group_no_one'>
<group>
<group string="Locations">
<group string="Locations">
<field name="wh_input_stock_loc_id" readonly="1"/>
<field name="wh_qc_stock_loc_id" readonly="1"/>
<field name="wh_pack_stock_loc_id" readonly="1"/>