From 79a3c7a976d563b1650798c6608b79ab746c370a Mon Sep 17 00:00:00 2001 From: benoit-guillot-z <> Date: Wed, 15 Feb 2012 20:47:43 -0200 Subject: [PATCH] [REF] purchase: refactoring of date_planned in the class purchase_order_line in order to overload it easily bzr revid: rvalyi@gmail.com-20120215224743-5gtpc8q6pane2ybm --- addons/purchase/purchase.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py index 5432067191d..3669aeb402a 100644 --- a/addons/purchase/purchase.py +++ b/addons/purchase/purchase.py @@ -709,6 +709,17 @@ class purchase_order_line(osv.osv): partner_id, date_order=date_order, fiscal_position_id=fiscal_position_id, date_planned=date_planned, name=name, price_unit=price_unit, notes=notes, context=context) + def _get_date_planned(self, cr, uid, seller, start_date, context=None): + """Return the datetime value to use as Schedule Date (``date_planned``) for the + Purchase Order Lines created in the purchase order. + + :param browse_record supplierinfo: the supplier of the product. + :rtype: datetime + :return: the desired Schedule Date for the PO lines + """ + seller_delay = seller and int(seller.delay) or 0 + return datetime.strptime(start_date, '%Y-%m-%d') + relativedelta(days=seller_delay) + def onchange_product_id(self, cr, uid, ids, pricelist_id, product_id, qty, uom_id, partner_id, date_order=False, fiscal_position_id=False, date_planned=False, name=False, price_unit=False, notes=False, context=None): @@ -761,10 +772,10 @@ class purchase_order_line(osv.osv): date_order = fields.date.context_today(cr,uid,context=context) qty = qty or 1.0 - seller_delay = 0 + seller = False supplierinfo_ids = product_supplierinfo.search(cr, uid, [('name','=',partner_id),('product_id','=',product.id)]) for supplierinfo in product_supplierinfo.browse(cr, uid, supplierinfo_ids, context=context): - seller_delay = supplierinfo.delay + seller = supplierinfo if supplierinfo.product_uom.id != uom_id: res['warning'] = {'title': _('Warning'), 'message': _('The selected supplier only sells this product by %s') % supplierinfo.product_uom.name } min_qty = product_uom._compute_qty(cr, uid, supplierinfo.product_uom.id, supplierinfo.min_qty, to_uom_id=uom_id) @@ -772,7 +783,8 @@ class purchase_order_line(osv.osv): res['warning'] = {'title': _('Warning'), 'message': _('The selected supplier has a minimal quantity set to %s %s, you should not purchase less.') % (supplierinfo.min_qty, supplierinfo.product_uom.name)} qty = min_qty - dt = (datetime.strptime(date_order, '%Y-%m-%d') + relativedelta(days=int(seller_delay) or 0.0)).strftime('%Y-%m-%d %H:%M:%S') + dt = self._get_date_planned(cr, uid, seller, date_order, context=context).strftime(DEFAULT_SERVER_DATETIME_FORMAT) + res['value'].update({'date_planned': date_planned or dt, 'product_qty': qty}) # - determine price_unit and taxes_id