[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"
@ -183,17 +182,11 @@ 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'),
}
_defaults= {
'manufacture_pull_id' : False
'manufacture_to_resupply': fields.boolean('Manufacture in this Warehouse'),
'manufacture_pull_id': fields.many2one('procurement.rule', 'Manufacture Rule'),
}
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')
data_obj = self.pool.get('ir.model.data')
try:
@ -204,43 +197,33 @@ class stock_warehouse(osv.osv):
if not manufacture_route_id:
raise osv.except_osv(_('Error!'), _('Can\'t find any generic Manufacture route.'))
dest_loc = warehouse.in_type_id
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')
res = super(stock_warehouse, self).create_routes(cr, uid, ids, warehouse, context=context)
if warehouse.manufacture_to_resupply:
manufacture_pull_vals = self._get_manufacture_pull_rule(cr, uid, warehouse, context=context)
if manufacture_pull_vals:
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
@ -248,13 +231,11 @@ class stock_warehouse(osv.osv):
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)
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:
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

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

@ -69,19 +69,7 @@
<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

@ -78,18 +78,14 @@ 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_to_resupply': fields.boolean('Purchase to resupply this warehouse'),
'buy_pull_id': fields.many2one('procurement.rule', 'BUY rule'),
}
_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')
data_obj = self.pool.get('ir.model.data')
try:
@ -100,41 +96,33 @@ class stock_warehouse(osv.osv):
if not buy_route_id:
raise osv.except_osv(_('Error!'), _('Can\'t find any generic Buy route.'))
dest_loc = warehouse.in_type_id
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')
res = super(stock_warehouse, self).create_routes(cr, uid, ids, warehouse, context=context)
if warehouse.buy_to_resupply:
buy_pull_vals = self._get_buy_pull_rule(cr, uid, warehouse, context=context)
if buy_pull_vals:
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
@ -142,8 +130,6 @@ class stock_warehouse(osv.osv):
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)
def get_all_routes_for_wh(self, cr, uid, warehouse, context=None):

View File

@ -47,13 +47,11 @@
<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>
<field name="res_model">stock.picking</field>

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

@ -2284,7 +2284,6 @@ class stock_warehouse(osv.osv):
'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)
@ -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):
@ -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."),