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
=== modified file 'bin/addons/msf_profile/i18n/fr_MF.po'
--- bin/addons/msf_profile/i18n/fr_MF.po 2022-08-23 13:15:58 +0000
+++ bin/addons/msf_profile/i18n/fr_MF.po 2022-10-07 12:13:16 +0000
@@ -84381,6 +84381,12 @@
84381msgid "UoM %s unknown"84381msgid "UoM %s unknown"
84382msgstr "UdM %s inconnue"84382msgstr "UdM %s inconnue"
8438384383
84384#. module: stock
84385#: code:addons/stock/physical_inventory.py:785
84386#, python-format
84387msgid "UoM is mandatory"
84388msgstr "L'UdM est obligatoire"
84389
84384#. module: account_chart84390#. module: account_chart
84385#: model:ir.module.module,shortdesc:account_chart.module_meta_information84391#: model:ir.module.module,shortdesc:account_chart.module_meta_information
84386msgid "Charts of Accounts"84392msgid "Charts of Accounts"
8438784393
=== modified file 'bin/addons/stock/physical_inventory.py'
--- bin/addons/stock/physical_inventory.py 2022-08-09 15:55:05 +0000
+++ bin/addons/stock/physical_inventory.py 2022-10-07 12:13:16 +0000
@@ -775,11 +775,14 @@
775775
776 # Check UoM776 # Check UoM
777 product_uom_id = False777 product_uom_id = False
778 product_uom = row.cells[3].data.lower()778 if row.cells[3].data:
779 if product_uom not in all_uom:779 product_uom = row.cells[3].data.lower()
780 add_error(_("""UoM %s unknown""") % product_uom, row_index, 3)780 if product_uom not in all_uom:
781 add_error(_("""UoM %s unknown""") % product_uom, row_index, 3)
782 else:
783 product_uom_id = all_uom[product_uom]
781 else:784 else:
782 product_uom_id = all_uom[product_uom]785 add_error(_("""UoM is mandatory"""), row_index, 3)
783786
784 # Check quantity787 # Check quantity
785 quantity = row.cells[4].data788 quantity = row.cells[4].data
@@ -795,84 +798,82 @@
795 quantity = 0.0798 quantity = 0.0
796 add_error(_('Quantity %s is not valid') % quantity, row_index, 4)799 add_error(_('Quantity %s is not valid') % quantity, row_index, 4)
797800
798 if product_id:801 if product_id and product_uom_id:
799 product_info = product_obj.read(cr, uid, product_id, ['batch_management', 'perishable', 'default_code', 'uom_id'])802 product_info = product_obj.read(cr, uid, product_id, ['batch_management', 'perishable', 'default_code', 'uom_id'])
800 else:803
801 product_info = {'batch_management': False, 'perishable': False, 'default_code': product_code, 'uom_id': False}804 if product_info['uom_id'] and product_info['uom_id'][0] != product_uom_id:
802805 add_error(_("""Product %s, UoM %s does not conform to that of product in stock""") % (product_info['default_code'], product_uom), row_index, 3)
803 if product_info['uom_id'] and product_uom_id and product_info['uom_id'][0] != product_uom_id:806
804 add_error(_("""Product %s, UoM %s does not conform to that of product in stock""") % (product_info['default_code'], product_uom), row_index, 3)807 # Check batch number
805808 batch_name = row.cells[5].data
806 # Check batch number809 if not batch_name and product_info['batch_management'] and quantity is not None:
807 batch_name = row.cells[5].data810 add_error(_('Batch number is required'), row_index, 5)
808 if not batch_name and product_info['batch_management'] and quantity is not None:811
809 add_error(_('Batch number is required'), row_index, 5)812 if batch_name and not product_info['batch_management']:
810813 add_error(_("Product %s is not BN managed, BN ignored") % (product_info['default_code'], ), row_index, 5, is_warning=True)
811 if batch_name and not product_info['batch_management']:814 batch_name = False
812 add_error(_("Product %s is not BN managed, BN ignored") % (product_info['default_code'], ), row_index, 5, is_warning=True)815
813 batch_name = False816 # Check expiry date
814817 expiry_date = row.cells[6].data
815 # Check expiry date818 if expiry_date and not product_info['perishable']:
816 expiry_date = row.cells[6].data819 add_error(_("Product %s is not ED managed, ED ignored") % (product_info['default_code'], ), row_index, 6, is_warning=True)
817 if expiry_date and not product_info['perishable']:820 expiry_date = False
818 add_error(_("Product %s is not ED managed, ED ignored") % (product_info['default_code'], ), row_index, 6, is_warning=True)821 elif expiry_date:
819 expiry_date = False822 expiry_date_type = row.cells[6].type
820 elif expiry_date:823 year = False
821 expiry_date_type = row.cells[6].type824 try:
822 year = False825 if expiry_date_type == 'datetime':
823 try:826 expiry_date = expiry_date.strftime(DEFAULT_SERVER_DATE_FORMAT)
824 if expiry_date_type == 'datetime':827 year = row.cells[6].data.year
825 expiry_date = expiry_date.strftime(DEFAULT_SERVER_DATE_FORMAT)828 elif expiry_date_type == 'str':
826 year = row.cells[6].data.year829 expiry_date_dt = parse(expiry_date)
827 elif expiry_date_type == 'str':830 year = expiry_date_dt.year
828 expiry_date_dt = parse(expiry_date)831 expiry_date = expiry_date_dt.strftime(DEFAULT_SERVER_DATE_FORMAT)
829 year = expiry_date_dt.year832 else:
830 expiry_date = expiry_date_dt.strftime(DEFAULT_SERVER_DATE_FORMAT)833 raise ValueError()
831 else:834 except ValueError:
832 raise ValueError()835 if not year or year >= 1900:
833 except ValueError:836 add_error(_("""Expiry date %s is not valid""") % expiry_date, row_index, 6)
834 if not year or year >= 1900:837
835 add_error(_("""Expiry date %s is not valid""") % expiry_date, row_index, 6)838 if year and year < 1900:
836839 add_error(_('Expiry date: year must be after 1899'), row_index, 6)
837 if year and year < 1900:840
838 add_error(_('Expiry date: year must be after 1899'), row_index, 6)841 if not expiry_date and product_info['perishable'] and quantity is not None:
839842 add_error(_('Expiry date is required'), row_index, 6)
840 if not expiry_date and product_info['perishable'] and quantity is not None:843
841 add_error(_('Expiry date is required'), row_index, 6)844 # Check duplicate line (Same product_id, batch_number, expirty_date)
842845 item = '%d-%s-%s' % (product_id or -1, batch_name or '', expiry_date or '')
843 # Check duplicate line (Same product_id, batch_number, expirty_date)846 if item in line_items:
844 item = '%d-%s-%s' % (product_id or -1, batch_name or '', expiry_date or '')847 add_error(_("""Product %s, Duplicate line (same product, batch number and expiry date)""") % product_info['default_code'], row_index)
845 if item in line_items:848 elif quantity is not None:
846 add_error(_("""Product %s, Duplicate line (same product, batch number and expiry date)""") % product_info['default_code'], row_index)849 line_items.append(item)
847 elif quantity is not None:850
848 line_items.append(item)851 data = {
849852 'product_id': product_id,
850 data = {853 'batch_number': batch_name,
851 'product_id': product_id,854 'expiry_date': expiry_date,
852 'batch_number': batch_name,855 'quantity': False,
853 'expiry_date': expiry_date,856 'product_uom_id': product_uom_id,
854 'quantity': False,857 }
855 'product_uom_id': product_uom_id,858
856 }859 if quantity is not None:
857860 data['quantity'] = quantity
858 if quantity is not None:861 # Check if line exist
859 data['quantity'] = quantity
860 # Check if line exist
861 line_ids = counting_obj.search(cr, uid, [('inventory_id', '=', inventory_rec.id),
862 ('product_id', '=', product_id),
863 ('batch_number', '=', batch_name),
864 ('expiry_date', '=', expiry_date)], context=context)
865 if not line_ids and (batch_name or expiry_date): # Search for empty BN/ED lines
866 line_ids = counting_obj.search(cr, uid, [('inventory_id', '=', inventory_rec.id),862 line_ids = counting_obj.search(cr, uid, [('inventory_id', '=', inventory_rec.id),
867 ('product_id', '=', product_id),863 ('product_id', '=', product_id),
868 ('batch_number', '=', False),864 ('batch_number', '=', batch_name),
869 ('expiry_date', '=', False)], context=context)865 ('expiry_date', '=', expiry_date)], context=context)
866 if not line_ids and (batch_name or expiry_date): # Search for empty BN/ED lines
867 line_ids = counting_obj.search(cr, uid, [('inventory_id', '=', inventory_rec.id),
868 ('product_id', '=', product_id),
869 ('batch_number', '=', False),
870 ('expiry_date', '=', False)], context=context)
870871
871 if line_ids:872 if line_ids:
872 counting_obj.write(cr, uid, line_ids[0], data, context=context)873 counting_obj.write(cr, uid, line_ids[0], data, context=context)
873 else:874 else:
874 data['inventory_id'] = inventory_rec.id875 data['inventory_id'] = inventory_rec.id
875 counting_obj.create(cr, uid, data, context=context)876 counting_obj.create(cr, uid, data, context=context)
876877
877 # endfor878 # endfor
878879

Subscribers

People subscribed via source and target branches