From 40a06ef32a559efd3b3ba8c2165c51249d49598c Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Wed, 11 Dec 2013 11:25:11 +0100 Subject: [PATCH] [IMP] stock: misc changes (mainly the date propagation and a fix in push rules). See the details bellow. [IMP] stock, usability: improved some menuitems, added groups on fields, buttons.. [REF] stock: used DEFAULT_SERVER_DATE_FORMAT and DEFAULT_SERVER_DATETIME_FORMAT [FIX] stock: fixed push flows (the condition of selection of push rules was wrong and no matching rule were found even if there was some) [IMP] stock: added new attributes 'sequence' and 'route_sequence' on push rules, as for pull rules, in order to sort them for selection [IMP] stock: propagation of the expected dates on linked move, when changing manually the expected date of a move or when setting it to 'done' bzr revid: qdp-launchpad@openerp.com-20131211102511-kb61j1cpo1fbl5m9 --- addons/stock/procurement.py | 19 +++++- addons/stock/res_config.py | 15 ++++- addons/stock/res_config_view.xml | 4 ++ addons/stock/stock.py | 109 +++++++++++++++++++++---------- addons/stock/stock_view.xml | 20 +++--- 5 files changed, 121 insertions(+), 46 deletions(-) diff --git a/addons/stock/procurement.py b/addons/stock/procurement.py index 8af4baa5fa9..7686abc0c04 100644 --- a/addons/stock/procurement.py +++ b/addons/stock/procurement.py @@ -102,6 +102,22 @@ class procurement_order(osv.osv): 'warehouse_id': fields.many2one('stock.warehouse', 'Warehouse', help="Warehouse to consider for the route selection"), } + def write(self, cr, uid, ids, vals, context=None): + move_obj = self.pool.get('stock.move') + if vals.get('date_planned'): + #propagation of a change in date_planned + for procurement in self.browse(cr, uid, ids, context=context): + if procurement.move_dest_id and procurement.move_dest_id.propagate: + current_date = datetime.strptime(procurement.date_planned, '%Y-%m-%d %H:%M:%S') + new_date = datetime.strptime(vals.get('date_planned'), '%Y-%m-%d %H:%M:%S') + delta = new_date - current_date + if abs(delta.days) >= procurement.company_id.propagation_minimum_delta: + #propagate the same delta in dates on the move that created the procurement + old_move_date = datetime.strptime(procurement.move_dest_id.date_expected, '%Y-%m-%d %H:%M:%S') + new_move_date = (old_move_date + relativedelta(days=delta.days or 0)).strftime('%Y-%m-%d %H:%M:%S') + move_obj.write(cr, uid, [procurement.move_dest_id.id], {'date_expected': new_move_date}, context=context) + return super(procurement_order, self).write(cr, uid, ids, vals, context=context) + def propagate_cancel(self, cr, uid, procurement, context=None): if procurement.rule_id.action == 'move' and procurement.move_ids: self.pool.get('stock.move').action_cancel(cr, uid, [m.id for m in procurement.move_ids], context=context) @@ -175,8 +191,6 @@ class procurement_order(osv.osv): 'name': procurement.name, 'company_id': procurement.company_id.id, 'product_id': procurement.product_id.id, - 'date': procurement.date_planned, - 'date_expected': procurement.date_planned, 'product_qty': procurement.product_qty, 'product_uom': procurement.product_uom.id, 'product_uom_qty': procurement.product_qty, @@ -195,6 +209,7 @@ class procurement_order(osv.osv): 'route_ids': [(4, x.id) for x in procurement.route_ids], 'warehouse_id': procurement.rule_id.propagate_warehouse_id and procurement.rule_id.propagate_warehouse_id.id or procurement.rule_id.warehouse_id.id, 'date': newdate, + 'date_expected': newdate, 'propagate': procurement.rule_id.propagate, } return vals diff --git a/addons/stock/res_config.py b/addons/stock/res_config.py index b3e7c53229b..4265bbf9461 100644 --- a/addons/stock/res_config.py +++ b/addons/stock/res_config.py @@ -21,6 +21,16 @@ from openerp.osv import fields, osv +class res_company(osv.osv): + _inherit = "res.company" + _columns = { + 'propagation_minimum_delta': fields.integer('Minimum Delta for Propagation of a Date Change on moves linked together'), + } + + _defaults = { + 'propagation_minimum_delta': 1, + } + class stock_config_settings(osv.osv_memory): _name = 'stock.config.settings' _inherit = 'res.config.settings' @@ -71,10 +81,11 @@ This installs the module product_expiry."""), implied_group='stock.group_locations', help="""This allows to configure and use multiple stock locations and warehouses, instead of having a single default one."""), - 'group_stock_adv_location': fields.boolean("Active Push and Pull inventory flows", - implied_group='stock.group_adv_location', + 'group_stock_adv_location': fields.boolean("Active Push and Pull inventory flows", + implied_group='stock.group_adv_location', help="""This option supplements the warehouse application by effectively implementing Push and Pull inventory flows. """), 'decimal_precision': fields.integer('Decimal precision on weight', help="As an example, a decimal precision of 2 will allow weights like: 9.99 kg, whereas a decimal precision of 4 will allow weights like: 0.0231 kg."), + 'propagation_minimum_delta': fields.related('company_id', 'propagation_minimum_delta', type='integer', string="Minimum days to trigger a propagation of date change in pushed/pull flows."), 'module_stock_dropshipping': fields.boolean("Manage dropshipping", help='\nCreates the dropship route and add more complex tests' '-This installs the module stock_dropshipping.'), diff --git a/addons/stock/res_config_view.xml b/addons/stock/res_config_view.xml index a784c015ab5..fcff9e45221 100644 --- a/addons/stock/res_config_view.xml +++ b/addons/stock/res_config_view.xml @@ -78,6 +78,10 @@