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

Proposed by jftempo
Status: Merged
Merged at revision: 6328
Proposed branch: lp:~dorian-kemps/unifield-server/US-10522
Merge into: lp:unifield-server
Diff against target: 195 lines (+85/-78)
2 files modified
bin/addons/msf_profile/i18n/fr_MF.po (+6/-0)
bin/addons/stock/physical_inventory.py (+79/-78)
To merge this branch: bzr merge lp:~dorian-kemps/unifield-server/US-10522
Reviewer Review Type Date Requested Status
UniField Reviewer Team Pending
Review via email: mp+430434@code.launchpad.net
To post a comment you must log in.
6297. By Dorian

US-10522 [FIX] PI counting lines import: Prevent attempt at counting line creation if there is no UoM found, and made it mandatory

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/addons/msf_profile/i18n/fr_MF.po'
2--- bin/addons/msf_profile/i18n/fr_MF.po 2022-08-23 13:15:58 +0000
3+++ bin/addons/msf_profile/i18n/fr_MF.po 2022-10-07 12:13:16 +0000
4@@ -84381,6 +84381,12 @@
5 msgid "UoM %s unknown"
6 msgstr "UdM %s inconnue"
7
8+#. module: stock
9+#: code:addons/stock/physical_inventory.py:785
10+#, python-format
11+msgid "UoM is mandatory"
12+msgstr "L'UdM est obligatoire"
13+
14 #. module: account_chart
15 #: model:ir.module.module,shortdesc:account_chart.module_meta_information
16 msgid "Charts of Accounts"
17
18=== modified file 'bin/addons/stock/physical_inventory.py'
19--- bin/addons/stock/physical_inventory.py 2022-08-09 15:55:05 +0000
20+++ bin/addons/stock/physical_inventory.py 2022-10-07 12:13:16 +0000
21@@ -775,11 +775,14 @@
22
23 # Check UoM
24 product_uom_id = False
25- product_uom = row.cells[3].data.lower()
26- if product_uom not in all_uom:
27- add_error(_("""UoM %s unknown""") % product_uom, row_index, 3)
28+ if row.cells[3].data:
29+ product_uom = row.cells[3].data.lower()
30+ if product_uom not in all_uom:
31+ add_error(_("""UoM %s unknown""") % product_uom, row_index, 3)
32+ else:
33+ product_uom_id = all_uom[product_uom]
34 else:
35- product_uom_id = all_uom[product_uom]
36+ add_error(_("""UoM is mandatory"""), row_index, 3)
37
38 # Check quantity
39 quantity = row.cells[4].data
40@@ -795,84 +798,82 @@
41 quantity = 0.0
42 add_error(_('Quantity %s is not valid') % quantity, row_index, 4)
43
44- if product_id:
45+ if product_id and product_uom_id:
46 product_info = product_obj.read(cr, uid, product_id, ['batch_management', 'perishable', 'default_code', 'uom_id'])
47- else:
48- product_info = {'batch_management': False, 'perishable': False, 'default_code': product_code, 'uom_id': False}
49-
50- if product_info['uom_id'] and product_uom_id and product_info['uom_id'][0] != product_uom_id:
51- add_error(_("""Product %s, UoM %s does not conform to that of product in stock""") % (product_info['default_code'], product_uom), row_index, 3)
52-
53- # Check batch number
54- batch_name = row.cells[5].data
55- if not batch_name and product_info['batch_management'] and quantity is not None:
56- add_error(_('Batch number is required'), row_index, 5)
57-
58- if batch_name and not product_info['batch_management']:
59- add_error(_("Product %s is not BN managed, BN ignored") % (product_info['default_code'], ), row_index, 5, is_warning=True)
60- batch_name = False
61-
62- # Check expiry date
63- expiry_date = row.cells[6].data
64- if expiry_date and not product_info['perishable']:
65- add_error(_("Product %s is not ED managed, ED ignored") % (product_info['default_code'], ), row_index, 6, is_warning=True)
66- expiry_date = False
67- elif expiry_date:
68- expiry_date_type = row.cells[6].type
69- year = False
70- try:
71- if expiry_date_type == 'datetime':
72- expiry_date = expiry_date.strftime(DEFAULT_SERVER_DATE_FORMAT)
73- year = row.cells[6].data.year
74- elif expiry_date_type == 'str':
75- expiry_date_dt = parse(expiry_date)
76- year = expiry_date_dt.year
77- expiry_date = expiry_date_dt.strftime(DEFAULT_SERVER_DATE_FORMAT)
78- else:
79- raise ValueError()
80- except ValueError:
81- if not year or year >= 1900:
82- add_error(_("""Expiry date %s is not valid""") % expiry_date, row_index, 6)
83-
84- if year and year < 1900:
85- add_error(_('Expiry date: year must be after 1899'), row_index, 6)
86-
87- if not expiry_date and product_info['perishable'] and quantity is not None:
88- add_error(_('Expiry date is required'), row_index, 6)
89-
90- # Check duplicate line (Same product_id, batch_number, expirty_date)
91- item = '%d-%s-%s' % (product_id or -1, batch_name or '', expiry_date or '')
92- if item in line_items:
93- add_error(_("""Product %s, Duplicate line (same product, batch number and expiry date)""") % product_info['default_code'], row_index)
94- elif quantity is not None:
95- line_items.append(item)
96-
97- data = {
98- 'product_id': product_id,
99- 'batch_number': batch_name,
100- 'expiry_date': expiry_date,
101- 'quantity': False,
102- 'product_uom_id': product_uom_id,
103- }
104-
105- if quantity is not None:
106- data['quantity'] = quantity
107- # Check if line exist
108- line_ids = counting_obj.search(cr, uid, [('inventory_id', '=', inventory_rec.id),
109- ('product_id', '=', product_id),
110- ('batch_number', '=', batch_name),
111- ('expiry_date', '=', expiry_date)], context=context)
112- if not line_ids and (batch_name or expiry_date): # Search for empty BN/ED lines
113+
114+ if product_info['uom_id'] and product_info['uom_id'][0] != product_uom_id:
115+ add_error(_("""Product %s, UoM %s does not conform to that of product in stock""") % (product_info['default_code'], product_uom), row_index, 3)
116+
117+ # Check batch number
118+ batch_name = row.cells[5].data
119+ if not batch_name and product_info['batch_management'] and quantity is not None:
120+ add_error(_('Batch number is required'), row_index, 5)
121+
122+ if batch_name and not product_info['batch_management']:
123+ add_error(_("Product %s is not BN managed, BN ignored") % (product_info['default_code'], ), row_index, 5, is_warning=True)
124+ batch_name = False
125+
126+ # Check expiry date
127+ expiry_date = row.cells[6].data
128+ if expiry_date and not product_info['perishable']:
129+ add_error(_("Product %s is not ED managed, ED ignored") % (product_info['default_code'], ), row_index, 6, is_warning=True)
130+ expiry_date = False
131+ elif expiry_date:
132+ expiry_date_type = row.cells[6].type
133+ year = False
134+ try:
135+ if expiry_date_type == 'datetime':
136+ expiry_date = expiry_date.strftime(DEFAULT_SERVER_DATE_FORMAT)
137+ year = row.cells[6].data.year
138+ elif expiry_date_type == 'str':
139+ expiry_date_dt = parse(expiry_date)
140+ year = expiry_date_dt.year
141+ expiry_date = expiry_date_dt.strftime(DEFAULT_SERVER_DATE_FORMAT)
142+ else:
143+ raise ValueError()
144+ except ValueError:
145+ if not year or year >= 1900:
146+ add_error(_("""Expiry date %s is not valid""") % expiry_date, row_index, 6)
147+
148+ if year and year < 1900:
149+ add_error(_('Expiry date: year must be after 1899'), row_index, 6)
150+
151+ if not expiry_date and product_info['perishable'] and quantity is not None:
152+ add_error(_('Expiry date is required'), row_index, 6)
153+
154+ # Check duplicate line (Same product_id, batch_number, expirty_date)
155+ item = '%d-%s-%s' % (product_id or -1, batch_name or '', expiry_date or '')
156+ if item in line_items:
157+ add_error(_("""Product %s, Duplicate line (same product, batch number and expiry date)""") % product_info['default_code'], row_index)
158+ elif quantity is not None:
159+ line_items.append(item)
160+
161+ data = {
162+ 'product_id': product_id,
163+ 'batch_number': batch_name,
164+ 'expiry_date': expiry_date,
165+ 'quantity': False,
166+ 'product_uom_id': product_uom_id,
167+ }
168+
169+ if quantity is not None:
170+ data['quantity'] = quantity
171+ # Check if line exist
172 line_ids = counting_obj.search(cr, uid, [('inventory_id', '=', inventory_rec.id),
173 ('product_id', '=', product_id),
174- ('batch_number', '=', False),
175- ('expiry_date', '=', False)], context=context)
176+ ('batch_number', '=', batch_name),
177+ ('expiry_date', '=', expiry_date)], context=context)
178+ if not line_ids and (batch_name or expiry_date): # Search for empty BN/ED lines
179+ line_ids = counting_obj.search(cr, uid, [('inventory_id', '=', inventory_rec.id),
180+ ('product_id', '=', product_id),
181+ ('batch_number', '=', False),
182+ ('expiry_date', '=', False)], context=context)
183
184- if line_ids:
185- counting_obj.write(cr, uid, line_ids[0], data, context=context)
186- else:
187- data['inventory_id'] = inventory_rec.id
188- counting_obj.create(cr, uid, data, context=context)
189+ if line_ids:
190+ counting_obj.write(cr, uid, line_ids[0], data, context=context)
191+ else:
192+ data['inventory_id'] = inventory_rec.id
193+ counting_obj.create(cr, uid, data, context=context)
194
195 # endfor
196

Subscribers

People subscribed via source and target branches