Merge lp:~akretion-team/openobject-addons/addons_purchase into lp:openobject-addons

Proposed by Benoit Guillot - http://www.akretion.com
Status: Rejected
Rejected by: Antony Lesuisse (OpenERP)
Proposed branch: lp:~akretion-team/openobject-addons/addons_purchase
Merge into: lp:openobject-addons
Diff against target: 51 lines (+17/-3)
1 file modified
purchase/purchase.py (+17/-3)
To merge this branch: bzr merge lp:~akretion-team/openobject-addons/addons_purchase
Reviewer Review Type Date Requested Status
Olivier Dony (Odoo) Approve
Florent (community) Approve
Review via email: mp+88347@code.launchpad.net

Description of the change

This is a refactoring of date_planned in the class purchase_order_line in order to overload it easily. I define a new fonction: _get_date_planned. I need it for a module calculating the delivery orders considering the working time.

Moreover, it seems to me that having int(seller_delay) or 0.0 is useless. Indeed, if seller_delay == False, int() will return 0.
I can add a commit to delete "or 0.0" if it's necessary.

To post a comment you must log in.
Revision history for this message
Florent (florent.x) wrote :

The patch looks OK.
However, the returned value can be simplified as:

  return str(datetime.now() + relativedelta(days=int(seller_delay)))

Because str() returns the correct value:
 - on a 'date' it returns '%Y-%m-%d'
 - on a 'datetime' it returns '%Y-%m-%d %H:%M:%S'

In this case the date_planned is a 'fields.date' object, so it's ok to store '%Y-%m-%d' on it.
The docstring should be fixed accordingly.

Revision history for this message
Florent (florent.x) wrote :

On second reading, the patch is not correct.

The method _get_date_planned() should return a date (or datetime) object (as described in its docstring), not a string representing the date.

This is consistent with the sibling methods in this module: _get_purchase_schedule_date and _get_purchase_order_date

The date formatting should remain in the caller method (product_id_change):

    dt = self._get_date_planned(...).strftime(DEFAULT_SERVER_DATETIME_FORMAT)

review: Needs Fixing
6337. By Benoit Guillot - http://www.akretion.com

[FIX] Change the returned type to fit with the other methods: _get_purchase_schedule_date and _get_purchase_order_date

Revision history for this message
Benoit Guillot - http://www.akretion.com (benoit-guillot-z) wrote :

Hello Florent,

Thanks for your reply.

Indeed the return type should be a datetime, it's better to fit with the similar methods : _get_purchase_schedule_date and _get_purchase_order_date as you said.
I pushed the changes according to your advice.

Revision history for this message
Florent (florent.x) wrote :

LGTM.

review: Approve
6338. By Benoit Guillot - http://www.akretion.com

[REF] Refactor the function purchase/_get_date_planned to have the seller informations in the function

Revision history for this message
Benoit Guillot - http://www.akretion.com (benoit-guillot-z) wrote :

Hello,

I made a refactor of my merge proposal. Instead of giving the seller delay as argument of the function _get_date_planned(), I propose to give the seller. It's better for me because in the module calculating the delivery delays I'm creating, I have an other information in the seller useful to get the date planned. Moreover, in general it's better to have a global argument.

Best regards,

Revision history for this message
Florent (florent.x) wrote :

small typo in docstring `param int seller`.

Revision history for this message
Florent (florent.x) wrote :

> small typo in docstring `param int seller`.

And I would do the convert "int(seller.delay)" in the "if".

6339. By Benoit Guillot - http://www.akretion.com

[FIX] fix typo and change the "int" conversion

Revision history for this message
Benoit Guillot - http://www.akretion.com (benoit-guillot-z) wrote :

Thank you Florent for your wise advices !

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

Looks good, but some minor things could still be fixed:

- improved docstring: browse -> browse_record, second param is not a supplier, it's a "supplier info"
- better names: seller parameter would better be named "supplier_info"
- l.16 - simpler test:
   seller_delay = int(seller.delay) if seller else 0
- minor refactoring needing in the original code: l.39 - the `for` loop is rather weird and unintuitive. The search() is not supposed to return multiple results, but if it does, the loop effect may be inconsistent.

We'll fix the above when merging.

Benoit and Florent, thanks a lot for your great collaborative work!

review: Approve
Revision history for this message
Benoit Guillot - http://www.akretion.com (benoit-guillot-z) wrote :

Thank you Olivier for the fix and the merge.

Revision history for this message
Benoit Guillot - http://www.akretion.com (benoit-guillot-z) wrote :

Hello Olivier,

After a quick look on the updated addons, I can't find the changes I proposed.
Is the merge still planned in the 6.1 ?

Best regards,

Revision history for this message
Raphaël Valyi - http://www.akretion.com (rvalyi) wrote :

Hello, I did a fresh rebase of this MP here https://code.launchpad.net/~akretion-team/openobject-addons/purchase-date-planned2/+register-merge

Can you merge the new one so we close this one too?

Revision history for this message
Antony Lesuisse (OpenERP) (al-openerp) wrote :
Revision history for this message
Raphaël Valyi - http://www.akretion.com (rvalyi) wrote :

Not sure this link work for you, here is a better one for the new MP:
https://code.launchpad.net/~akretion-team/openobject-addons/purchase-date-planned2/+merge/93316

Unmerged revisions

6339. By Benoit Guillot - http://www.akretion.com

[FIX] fix typo and change the "int" conversion

6338. By Benoit Guillot - http://www.akretion.com

[REF] Refactor the function purchase/_get_date_planned to have the seller informations in the function

6337. By Benoit Guillot - http://www.akretion.com

[FIX] Change the returned type to fit with the other methods: _get_purchase_schedule_date and _get_purchase_order_date

6336. By Benoit Guillot - http://www.akretion.com

[REF]refactor of the date_planned in the purchase order line

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-01-11 08:53:48 +0000
3+++ purchase/purchase.py 2012-01-23 16:00:32 +0000
4@@ -697,6 +697,20 @@
5 default.update({'state':'draft', 'move_ids':[],'invoiced':0,'invoice_lines':[]})
6 return super(purchase_order_line, self).copy_data(cr, uid, id, default, context)
7
8+ def _get_date_planned(self, cr, uid, seller, 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 seller: the supplier of the product.
13+ :rtype: datetime
14+ :return: the desired Schedule Date for the PO lines
15+ """
16+ if seller:
17+ seller_delay = int(seller.delay)
18+ else:
19+ seller_delay = 0
20+ return datetime.now() + relativedelta(days=seller_delay)
21+
22 #TOFIX:
23 # - name of method should "onchange_product_id"
24 # - docstring
25@@ -728,7 +742,7 @@
26 if not date_order:
27 date_order = time.strftime('%Y-%m-%d')
28 qty = qty or 1.0
29- seller_delay = 0
30+ seller = False
31 if uom:
32 uom1_cat = prod.uom_id.category_id.id
33 uom2_cat = product_uom_pool.browse(cr, uid, uom).category_id.id
34@@ -739,7 +753,7 @@
35 res = {}
36 for s in prod.seller_ids:
37 if s.name.id == partner_id:
38- seller_delay = s.delay
39+ seller = s
40 if s.product_uom:
41 temp_qty = product_uom_pool._compute_qty(cr, uid, s.product_uom.id, s.min_qty, to_uom_id=prod.uom_id.id)
42 uom = s.product_uom.id #prod_uom_po
43@@ -753,7 +767,7 @@
44 'uom': uom,
45 'date': date_order,
46 })[pricelist]
47- dt = (datetime.now() + relativedelta(days=int(seller_delay) or 0.0)).strftime('%Y-%m-%d %H:%M:%S')
48+ dt = self._get_date_planned(cr, uid, seller, context=context).strftime(DEFAULT_SERVER_DATETIME_FORMAT)
49
50
51 res.update({'value': {'price_unit': price, 'name': prod_name,

Subscribers

People subscribed via source and target branches

to all changes: