Merge lp:~therp-nl/openerp-stock-delivery-times/7.0_lp1298520_crash_product_nocompany into lp:openerp-stock-delivery-times

Proposed by Ronald Portier (Therp)
Status: Merged
Merged at revision: 111
Proposed branch: lp:~therp-nl/openerp-stock-delivery-times/7.0_lp1298520_crash_product_nocompany
Merge into: lp:openerp-stock-delivery-times
Diff against target: 66 lines (+34/-2)
2 files modified
stock_delivery_times_advanced/__openerp__.py (+1/-1)
stock_delivery_times_advanced/product.py (+33/-1)
To merge this branch: bzr merge lp:~therp-nl/openerp-stock-delivery-times/7.0_lp1298520_crash_product_nocompany
Reviewer Review Type Date Requested Status
Benoit Guillot - http://www.akretion.com Approve
Review via email: mp+213276@code.launchpad.net

Description of the change

Fixes 1298520. PO lead is normally taken from the company defined in the product.

However, the code crashed when product did not refer to a company (products shared in multicompany install).

This change will take the company from the product, the context, the user, or the main company. If everything else fails, it will just return a PO lead time of zero days.

To post a comment you must log in.
Revision history for this message
Benoit Guillot - http://www.akretion.com (benoit-guillot-z) wrote :

Thank you for the fixes and the contributions !
Sorry for the delay ...

review: Approve
Revision history for this message
Ronald Portier (Therp) (rportier1962) wrote :

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello Benoit,

I was very glad with the Akretion modules, just needed these fixes to
get everything working!

Kind regards,

Ronald

Op 29-08-14 om 11:01 schreef Benoit Guillot - http://www.akretion.com:
> Review: Approve
>
> Thank you for the fixes and the contributions !
> Sorry for the delay ...
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.15 (GNU/Linux)

iQIcBAEBAgAGBQJUAEZ/AAoJEKGB+BJNcQHTqDUQAMQCCSdQJlTE06HY3rzfSdLK
YvgbyK9xpLp3bq2EC2PTf6SLhwEK9LrByr7fO4CMAZWXZfxWMkhj4rVriQEDefxV
PLkj6oKV7F3bMqBnlZZhulIFdBFWktMMP8v9yN1Umw/AJoUSVFSoYG7UwrjfZ2gx
d7NrNYwrB0mGEVV1aSayAqqp5N8kahA+XoxvQJXD204r9kNtWMzI+LBOAKrgG+vb
irLYk5tq6h+cTwKFSkvWLfC03k/ZhwQ7x0f3Seq3YKG7dGFRWVmxuQIAvr9Tx8d9
mRFUxdDHZQ1InL5MH55dD9RK50ky1GekvREi1FU/xVjOCyvZfR3OmfvkiH6frCxt
2A0oOlNk8qgGPofYxZofkDruqU8hVsYnubxEhlSozWNdHKAODsXPVy29yq8ESPq7
zKJgyguGrqQyl3ZGbGfH/1mc41TaHkE2MrJZmCbNfcsvnZljVai4vJgpY0yoW4RG
bb0n/ppj2Q3I7rA6vv5G0YC2H77stR4WRmIJcNjHqPGvhBO55wGS4I8EU8wunzfc
AWmnd6TG/7/ojPhnFLNNP1CA1QYZk+E89pVdw8cqiy1DGEMmLqfLZaezWAvE8TS5
dcrUlsxKXKoI9ssXt/cy7SeVUioyZt+WIe3bP51rdXPxIqsCKPk4i3aPC3nzbiwt
TEvFUdzATa5fS69y2KUc
=z2Xd
-----END PGP SIGNATURE-----

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'stock_delivery_times_advanced/__openerp__.py'
2--- stock_delivery_times_advanced/__openerp__.py 2014-01-16 15:01:13 +0000
3+++ stock_delivery_times_advanced/__openerp__.py 2014-03-28 14:32:43 +0000
4@@ -34,11 +34,11 @@
5 'stock_available_immediately',
6 ],
7 'data': [
8+ 'wizard/stock_change_date_view.xml',
9 'stock_view.xml',
10 'sale_view.xml',
11 'product_view.xml',
12 'product_data.xml',
13- 'wizard/stock_change_date_view.xml',
14 ],
15 'demo': [],
16 'installable': True,
17
18=== modified file 'stock_delivery_times_advanced/product.py'
19--- stock_delivery_times_advanced/product.py 2014-01-16 15:01:13 +0000
20+++ stock_delivery_times_advanced/product.py 2014-03-28 14:32:43 +0000
21@@ -46,6 +46,38 @@
22 class product_product(orm.Model):
23 _inherit = 'product.product'
24
25+ def _get_company_po_lead(self, cr, uid, product_obj, context=None):
26+ '''Get po_lead from company. Company is taken, in order of preference,
27+ from 1. product, 2. context, 3 user, 4. main company. if no company
28+ is found, we will simply return a zero po leadtime.'''
29+ context = context or {}
30+ # check wether product refers to company
31+ if product_obj.company_id:
32+ return product_obj.company_id.po_lead
33+ # Company in context?
34+ if 'force_company' in context:
35+ company_id = context['force_company']
36+ else:
37+ # Take company from user
38+ user_model = self.pool['res.users']
39+ user_record = user_model.read(
40+ cr, uid, uid, ['company_id'], context=context)
41+ company_id = (
42+ user_record and user_record['company_id']
43+ and user_record['company_id'][0] or False)
44+ # if still no company, last resort is to use main company
45+ if not company_id:
46+ base_model = self.pool['ir.model.data']
47+ company_id = base_model.get_object_reference(
48+ cr, uid, 'base', 'main_company')[1]
49+ # If we still did not find a company, just return 0
50+ if not company_id:
51+ return 0.0
52+ company_model = self.pool['res.company']
53+ company_record = company_model.read(
54+ cr, uid, company_id, ['po_lead'], context=context)
55+ return company_record['po_lead']
56+
57 def _get_delays(self, cr, uid, product, qty=1, context=None):
58 """Compute the delay information for a product
59 """
60@@ -58,5 +90,5 @@
61 #TODO use a different calendar for the supplier delay than the company calendar
62 supplier_shortage = product.seller_info_id['supplier_shortage']
63 #add purchase lead time
64- delay += product.company_id.po_lead
65+ delay += self._get_company_po_lead(cr, uid, product, context=context)
66 return delay, supplier_shortage

Subscribers

People subscribed via source and target branches