Merge lp:~akretion-team/openobject-addons/purchase-date-planned2 into lp:openobject-addons

Proposed by Raphaël Valyi - http://www.akretion.com
Status: Merged
Merged at revision: 6604
Proposed branch: lp:~akretion-team/openobject-addons/purchase-date-planned2
Merge into: lp:openobject-addons
Diff against target: 44 lines (+15/-3)
1 file modified
purchase/purchase.py (+15/-3)
To merge this branch: bzr merge lp:~akretion-team/openobject-addons/purchase-date-planned2
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+93316@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Raphaël Valyi - http://www.akretion.com (rvalyi) wrote :

Hello, following Antony Lessuisse advice, this is a fresh rebase of the old MP https://code.launchpad.net/~akretion-team/openobject-addons/addons_purchase/+merge/88347

It's approved already, can you merge it?

Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

Thanks for rebasing, that was very useful indeed!

I've just merged it, changing only a few things on-the-fly as discussed on the previous version of the MP (you had already improved some of it, that's great).
I also replaced l.16 "seller and int(seller.delay) or 0" to use the if/else Python 2.5 conditional, as it was subject to the classical problem of having a "falsy B" in `A and B or C`.

Thanks for your clean refactoring!

In related news, I will probably commit soon a trivial refactoring of the weird and useless loop on supplierinfo_ids, as we only care about one supplierinfo.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'purchase/purchase.py'
2--- purchase/purchase.py 2012-02-14 12:25:20 +0000
3+++ purchase/purchase.py 2012-02-15 22:55:22 +0000
4@@ -709,6 +709,17 @@
5 partner_id, date_order=date_order, fiscal_position_id=fiscal_position_id, date_planned=date_planned,
6 name=name, price_unit=price_unit, notes=notes, context=context)
7
8+ def _get_date_planned(self, cr, uid, seller, start_date, context=None):
9+ """Return the datetime value to use as Schedule Date (``date_planned``) for the
10+ Purchase Order Lines created in the purchase order.
11+
12+ :param browse_record supplierinfo: the supplier of the product.
13+ :rtype: datetime
14+ :return: the desired Schedule Date for the PO lines
15+ """
16+ seller_delay = seller and int(seller.delay) or 0
17+ return datetime.strptime(start_date, '%Y-%m-%d') + relativedelta(days=seller_delay)
18+
19 def onchange_product_id(self, cr, uid, ids, pricelist_id, product_id, qty, uom_id,
20 partner_id, date_order=False, fiscal_position_id=False, date_planned=False,
21 name=False, price_unit=False, notes=False, context=None):
22@@ -761,10 +772,10 @@
23 date_order = fields.date.context_today(cr,uid,context=context)
24
25 qty = qty or 1.0
26- seller_delay = 0
27+ seller = False
28 supplierinfo_ids = product_supplierinfo.search(cr, uid, [('name','=',partner_id),('product_id','=',product.id)])
29 for supplierinfo in product_supplierinfo.browse(cr, uid, supplierinfo_ids, context=context):
30- seller_delay = supplierinfo.delay
31+ seller = supplierinfo
32 if supplierinfo.product_uom.id != uom_id:
33 res['warning'] = {'title': _('Warning'), 'message': _('The selected supplier only sells this product by %s') % supplierinfo.product_uom.name }
34 min_qty = product_uom._compute_qty(cr, uid, supplierinfo.product_uom.id, supplierinfo.min_qty, to_uom_id=uom_id)
35@@ -772,7 +783,8 @@
36 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)}
37 qty = min_qty
38
39- dt = (datetime.strptime(date_order, '%Y-%m-%d') + relativedelta(days=int(seller_delay) or 0.0)).strftime('%Y-%m-%d %H:%M:%S')
40+ dt = self._get_date_planned(cr, uid, seller, date_order, context=context).strftime(DEFAULT_SERVER_DATETIME_FORMAT)
41+
42 res['value'].update({'date_planned': date_planned or dt, 'product_qty': qty})
43
44 # - determine price_unit and taxes_id

Subscribers

People subscribed via source and target branches

to all changes: