Merge lp:~dorian-kemps/unifield-server/US-3994 into lp:unifield-server

Proposed by jftempo
Status: Merged
Merged at revision: 4729
Proposed branch: lp:~dorian-kemps/unifield-server/US-3994
Merge into: lp:unifield-server
Diff against target: 85 lines (+25/-34)
2 files modified
bin/addons/import_data/import_data.py (+17/-31)
bin/addons/product_nomenclature/product_nomenclature.py (+8/-3)
To merge this branch: bzr merge lp:~dorian-kemps/unifield-server/US-3994
Reviewer Review Type Date Requested Status
UniField Reviewer Team Pending
Review via email: mp+336985@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/addons/import_data/import_data.py'
2--- bin/addons/import_data/import_data.py 2016-05-24 08:44:23 +0000
3+++ bin/addons/import_data/import_data.py 2018-02-02 16:33:38 +0000
4@@ -243,42 +243,28 @@
5 'product.asset.type': {'name': {}},
6 'product.international.status': {'name': {}},
7 }
8- # Product nomenclature
9- cr.execute('SELECT name, id FROM product_nomenclature;')
10+ # Product nomenclature and complete name
11+ temp_nomen_by_id = {}
12+ current_lang = context.get('lang', 'en_MF')
13+ cr.execute('''
14+ SELECT n.id, coalesce(t.value,n.name), n.parent_id
15+ FROM product_nomenclature n
16+ LEFT JOIN ir_translation t ON t.lang='en_MF' AND t.name='product.nomenclature,name' AND t.res_id=n.id
17+ ORDER BY n.level;
18+ ''')
19 for nv in cr.dictfetchall():
20- self._cache[dbname]['product.nomenclature']['name'].update({nv['name']: nv['id']})
21+ self._cache[dbname]['product.nomenclature']['name'].update({nv['coalesce']: nv['id']})
22+ if nv['parent_id'] and temp_nomen_by_id.get(nv['parent_id'], False):
23+ temp_full_name = temp_nomen_by_id[nv['parent_id']] + ' | ' + nv['coalesce']
24+ temp_nomen_by_id.update({nv['id']: temp_full_name})
25+ self._cache[dbname]['product.nomenclature']['complete_name'].update({temp_full_name: nv['id']})
26+ else:
27+ temp_nomen_by_id.update({nv['id']: nv['coalesce']})
28+ self._cache[dbname]['product.nomenclature']['complete_name'].update({nv['coalesce']: nv['id']})
29 # Product category
30 cr.execute('SELECT id, family_id FROM product_category;')
31 for pc in cr.dictfetchall():
32 self.pool.get('product.nomenclature')._cache[dbname].update({pc['family_id']: pc['id']})
33- # Product nomenclature complete name
34- cr.execute('''SELECT id, name FROM
35-(
36-(SELECT
37- n0.id, n0.name AS name
38-FROM product_nomenclature n0
39-WHERE n0.level = 0)
40-UNION
41-(SELECT n1.id, n0.name ||' | '|| n1.name AS name
42-FROM product_nomenclature n1
43- LEFT JOIN product_nomenclature n0 ON n1.parent_id = n0.id
44-WHERE n1.level = 1)
45-UNION
46-(SELECT n2.id, n0.name ||' | '|| n1.name ||' | '|| n2.name AS name
47-FROM product_nomenclature n1
48- LEFT JOIN product_nomenclature n0 ON n1.parent_id = n0.id
49- LEFT JOIN product_nomenclature n2 ON n2.parent_id = n1.id
50-WHERE n2.level = 2)
51-UNION
52-(SELECT n3.id, n0.name ||' | '|| n1.name ||' | '|| n2.name ||' | '|| n3.name AS name
53-FROM product_nomenclature n1
54- LEFT JOIN product_nomenclature n0 ON n1.parent_id = n0.id
55- LEFT JOIN product_nomenclature n2 ON n2.parent_id = n1.id
56- LEFT JOIN product_nomenclature n3 ON n3.parent_id = n2.id
57-WHERE n3.level = 3)
58-) AS cn''')
59- for cnv in cr.dictfetchall():
60- self._cache[dbname]['product.nomenclature']['complete_name'].update({cnv['name']: cnv['id']})
61 # Product UoM
62 cr.execute('SELECT name, id FROM product_uom;')
63 for uv in cr.dictfetchall():
64
65=== modified file 'bin/addons/product_nomenclature/product_nomenclature.py'
66--- bin/addons/product_nomenclature/product_nomenclature.py 2017-05-29 14:06:25 +0000
67+++ bin/addons/product_nomenclature/product_nomenclature.py 2018-02-02 16:33:38 +0000
68@@ -733,9 +733,14 @@
69 if from_import_menu and nomen_obj._cache.get(cr.dbname, {}).get(vals['nomen_manda_2'], False):
70 vals['categ_id'] = nomen_obj._cache.get(cr.dbname, {}).get(vals['nomen_manda_2'], False)
71 else:
72- vals['categ_id'] = self.pool.get('product.nomenclature').read(cr, uid, vals['nomen_manda_2'], ['category_id'], context=context)['category_id'][0]
73- if from_import_menu:
74- nomen_obj._cache[cr.dbname][vals['nomen_manda_2']] = vals['categ_id']
75+ categ_ids = self.pool.get('product.nomenclature').read(cr, uid, vals['nomen_manda_2'], ['category_id'], context=context)['category_id']
76+ if categ_ids and len(categ_ids) > 0:
77+ vals['categ_id'] = categ_ids[0]
78+ if from_import_menu:
79+ nomen_obj._cache[cr.dbname][vals['nomen_manda_2']] = vals['categ_id']
80+ else:
81+ raise osv.except_osv(_('Error'), _('No Product Category found for %s. Please contact an accounting member to create a new one for this family.'
82+ % vals['nomenclature_description']))
83 return super(product_template, self).create(cr, uid, vals, context)
84
85 def write(self, cr, uid, ids, vals, context=None):

Subscribers

People subscribed via source and target branches