odoo-addon-account-move-payroll-import 16.0.1.0.1__py2.py3-none-any.whl → 16.0.1.0.3__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,7 @@
3
3
  from odoo import models, fields, api, _, Command
4
4
  from odoo.exceptions import UserError
5
5
 
6
- from ..utils.parse_utils import abs_float
6
+ from ..utils.parse_utils import abs_float, parse_float
7
7
 
8
8
 
9
9
  # This are the only allowed mappings for the moment
@@ -18,6 +18,8 @@ ALLOWED_MAPPINGS = [
18
18
  "payroll_import_mapping_ss_bonus",
19
19
  ]
20
20
 
21
+ VALUE_ERROR_MSG = "Invalid value '%s' in column %s."
22
+
21
23
 
22
24
  class PayrollImportSetup(models.Model):
23
25
  _name = "payroll.import.setup"
@@ -338,9 +340,51 @@ class PayrollImportSetup(models.Model):
338
340
  }
339
341
 
340
342
  def validate_column_numbers(self, data_length):
343
+ def validate_indexes(names):
344
+ repeated_indexes = [
345
+ k for k, v in names.items() if list(names.values()).count(v) > 1
346
+ ]
347
+ if repeated_indexes:
348
+ raise UserError(
349
+ _(
350
+ "%s indexes are repeated. Please review your setup."
351
+ % (", ".join(repeated_indexes))
352
+ )
353
+ )
354
+
355
+ for name, idx in names.items():
356
+ if idx < 1:
357
+ raise UserError(
358
+ _(
359
+ "Column index for %s must be greater than or equal to 1."
360
+ % name
361
+ )
362
+ )
363
+ if idx > data_length:
364
+ raise UserError(
365
+ _(
366
+ "Column index for %s must be less or equal than %s."
367
+ % (name, data_length)
368
+ )
369
+ )
370
+
371
+ names = {}
341
372
  for field in [k for k in self._fields.keys() if k.startswith("column_")]:
342
- if getattr(self, field) > data_length:
343
- raise UserError(_("Column %s is out of range." % field))
373
+ index = getattr(self, field)
374
+ name = self.env["ir.model.fields"].search(
375
+ [("model", "=", self._name), ("name", "=", field)],
376
+ limit=1,
377
+ ).field_description
378
+ names[name] = index
379
+
380
+ for custom_concept in self.custom_concepts_ids:
381
+ index = custom_concept.col_index
382
+ name = custom_concept.name
383
+ names[name] = index
384
+
385
+ validate_indexes(names)
386
+
387
+ return True
344
388
 
345
389
  def compute_tc1rlc_ss_cumulative(self, row, cumulative):
346
390
  """
@@ -352,16 +396,37 @@ class PayrollImportSetup(models.Model):
352
396
  row[self.column_total_tc1rlc - 1],
353
397
  self.thousands_delimiter,
354
398
  self.decimal_delimiter,
399
+ context={
400
+ "raise_exception": True,
401
+ "exception_msg": VALUE_ERROR_MSG % (
402
+ row[self.column_total_tc1rlc - 1],
403
+ self.column_total_tc1rlc
404
+ )
405
+ }
355
406
  )
356
407
  - abs_float(
357
408
  row[self.column_ss_employee - 1],
358
409
  self.thousands_delimiter,
359
410
  self.decimal_delimiter,
411
+ context={
412
+ "raise_exception": True,
413
+ "exception_msg": VALUE_ERROR_MSG % (
414
+ row[self.column_ss_employee - 1],
415
+ self.column_ss_employee
416
+ )
417
+ }
360
418
  )
361
419
  - abs_float(
362
420
  row[self.column_ss_company - 1],
363
421
  self.thousands_delimiter,
364
422
  self.decimal_delimiter,
423
+ context={
424
+ "raise_exception": True,
425
+ "exception_msg": VALUE_ERROR_MSG % (
426
+ row[self.column_ss_company - 1],
427
+ self.column_ss_company
428
+ )
429
+ }
365
430
  )
366
431
  )
367
432
  return cumulative
@@ -394,8 +459,10 @@ class PayrollImportSetup(models.Model):
394
459
  return {}
395
460
 
396
461
  column = getattr(self, line_mapping.column_field, False)
397
- value = abs_float(
398
- row[column - 1], self.thousands_delimiter, self.decimal_delimiter
462
+ exception_msg = VALUE_ERROR_MSG % (row[column - 1], column)
463
+ value = parse_float(
464
+ row[column - 1], self.thousands_delimiter, self.decimal_delimiter,
465
+ context={"raise_exception": True, "exception_msg": exception_msg}
399
466
  )
400
467
 
401
468
  if not value:
@@ -447,8 +514,10 @@ class PayrollImportSetup(models.Model):
447
514
  cc_vals_list = []
448
515
  for custom_concept in self.custom_concepts_ids:
449
516
  column = custom_concept.col_index
517
+ exception_msg = VALUE_ERROR_MSG % (row[column - 1], column)
450
518
  value = abs_float(
451
- row[column - 1], self.thousands_delimiter, self.decimal_delimiter
519
+ row[column - 1], self.thousands_delimiter, self.decimal_delimiter,
520
+ context={"raise_exception": True, "exception_msg": exception_msg}
452
521
  )
453
522
 
454
523
  if not value:
@@ -469,6 +538,14 @@ class PayrollImportSetup(models.Model):
469
538
  """
470
539
  Create the payroll account move.
471
540
  """
541
+ for vals in lines_vals:
542
+ # credits might be negative in the file
543
+ vals["credit"] = abs(vals.get("credit", 0.0))
544
+
545
+ # debits must be positive so: switch debit/credit if debit is negative
546
+ if vals.get("debit", 0.0) < 0.0:
547
+ vals["credit"] = abs(vals.pop("debit"))
548
+
472
549
  move = self.env["account.move"].with_context(
473
550
  is_payroll_import=True
474
551
  ).create(
@@ -10,7 +10,8 @@ def get_file_extension(file_name):
10
10
  Get the file extension from the file name.
11
11
  """
12
12
  if file_name:
13
- return os.path.splitext(file_name)[-1]
13
+ ext = os.path.splitext(file_name)[-1]
14
+ return str(ext).lower() if ext else False
14
15
  return False
15
16
 
16
17
 
@@ -1,12 +1,14 @@
1
1
  # -*- coding: utf-8 -*-
2
+ from odoo.exceptions import UserError
2
3
 
3
4
 
4
- def parse_float(value, thousands_sep=",", decimal_sep="."):
5
+ def parse_float(value, thousands_sep=",", decimal_sep=".", context={}):
5
6
  """
6
7
  Parse a float value.
7
8
  :param thousands_sep: the thousands separator.
8
9
  :param decimal_sep: the decimal separator.
9
10
  :param value: the value to parse.
11
+ :param context: the context.
10
12
  :return: the parsed float value.
11
13
  """
12
14
  if type(value) in (int, float, bool):
@@ -16,19 +18,29 @@ def parse_float(value, thousands_sep=",", decimal_sep="."):
16
18
  if not value:
17
19
  return 0.0
18
20
 
19
- value = value.replace(thousands_sep, "").replace(decimal_sep, ".")
20
- return float(value)
21
+ value = value.replace(thousands_sep, "", 1).replace(decimal_sep, ".", 1)
22
+ try:
23
+ return float(value)
24
+ except ValueError:
25
+ if context.get("raise_exception", True):
26
+ msg = context.get("exception_msg", "Invalid float value: %s" % value)
27
+ raise UserError(msg)
28
+ return 0.0
21
29
 
22
30
 
23
- def abs_float(value, thousands_sep=",", decimal_sep="."):
31
+ def abs_float(value, thousands_sep=",", decimal_sep=".", context={}):
24
32
  """
25
33
  Parse a float value and return its absolute value.
26
34
  :param thousands_sep: the thousands separator.
27
35
  :param decimal_sep: the decimal separator.
28
36
  :param value: the value to parse.
37
+ :param context: the context.
29
38
  :return: the absolute value of the parsed float value.
30
39
  """
31
40
  try:
32
41
  return abs(parse_float(value, thousands_sep, decimal_sep))
33
42
  except ValueError:
34
- raise ValueError("Invalid float value: %s" % value)
43
+ if context.get("raise_exception", True):
44
+ msg = context.get("exception_msg", "Invalid float value: %s" % value)
45
+ raise UserError(msg)
46
+ return 0.0
@@ -290,6 +290,8 @@ class AccountPayrollImportWizard(models.TransientModel):
290
290
  rows, cumulative_tc1rlc_ss = [], 0.0
291
291
  skip_lines = options.get("header_lines", 1) - 1
292
292
  for idx, row in enumerate(getattr(self, f"_read_{extension}")(options)):
293
+ if idx == 0:
294
+ import_setup.validate_column_numbers(len(row))
293
295
  if idx == import_setup.header_ref_line - 1:
294
296
  self.account_move_ref = row[0].strip() or import_setup.name
295
297
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: odoo-addon-account-move-payroll-import
3
- Version: 16.0.1.0.1
3
+ Version: 16.0.1.0.3
4
4
  Summary: ODOO account move spanish payroll data import for social cooperatives.
5
5
  Home-page: https://gitlab.com/somitcoop/erp-research/odoo-accounting
6
6
  Author: Som It Cooperatiu SCCL, Som Connexió SCCL
@@ -1,28 +1,28 @@
1
1
  odoo/addons/account_move_payroll_import/CHANGELOG.md,sha256=COE0An9jnvIrV7eWgGSa6XzTGN8tACjr_LkFmjRbqos,608
2
2
  odoo/addons/account_move_payroll_import/README.rst,sha256=fnLmb6E5pLv2d-kzAVwIs2O1QKyApMwCobkT9nUgXbo,3354
3
3
  odoo/addons/account_move_payroll_import/__init__.py,sha256=xdfbExIUANT_2sXVtonxwfOse1Cqvz2AVNntyx_lINE,68
4
- odoo/addons/account_move_payroll_import/__manifest__.py,sha256=8Tl6Ba4ENLvLvnqQc0Z4p4xZm0LvxYVjBFPG6dWfRUc,1379
4
+ odoo/addons/account_move_payroll_import/__manifest__.py,sha256=ZNwrFnlEv-s7-KXZpw3ysYRKTmi3YP1KczQDz5xknWg,1379
5
5
  odoo/addons/account_move_payroll_import/data/payroll_import_defaults.xml,sha256=8fnC8Z2ov3ulvcwcaazG5i3DGBzaK5Q0JFhF4dRzn9s,4570
6
- odoo/addons/account_move_payroll_import/i18n/ca_ES.po,sha256=8ucDStleOanDEsdBK1IFKGsbwWjrQ6_-YUCICN3TGaI,38186
7
- odoo/addons/account_move_payroll_import/i18n/es.po,sha256=grQjubV3lz29tHlLtRyUjSF6NrmHyDRRUGo1V7poTpw,38369
6
+ odoo/addons/account_move_payroll_import/i18n/ca_ES.po,sha256=shnWYO_4x0t4HRM7ajXBT06tIOuEmFch6zXc7wfKybQ,41693
7
+ odoo/addons/account_move_payroll_import/i18n/es.po,sha256=MJslDNYJsRPQRk11u3SB-uH6diHLHQoqa-rqTEqt-cw,41915
8
8
  odoo/addons/account_move_payroll_import/models/__init__.py,sha256=MvOdNmgSVk-29bpZZRt415YrRUGryuSE7gpIzoRqw5c,161
9
9
  odoo/addons/account_move_payroll_import/models/account_move.py,sha256=8T-DNpKHc_e4r18NSx8Bh2xFQB4DlLI69ImxmghXJU8,6031
10
10
  odoo/addons/account_move_payroll_import/models/payroll_custom_concept.py,sha256=m8Wl_xFsWCwOqLJWwBFTmtA669rqIg0mIvGNqDtBnfw,2003
11
11
  odoo/addons/account_move_payroll_import/models/payroll_import_mapping.py,sha256=ARiif1H0CMs17n-0SW563Jv9jA1ta3nhCtq9l4vVbHA,943
12
- odoo/addons/account_move_payroll_import/models/payroll_import_setup.py,sha256=WHT3A4jy6Ba-8i_A6Voddpxa8Dk4BXJJdaYJpBZFDAI,17577
12
+ odoo/addons/account_move_payroll_import/models/payroll_import_setup.py,sha256=9LJnoFphJD7-YWUQ9ZiVvS7uZWlNRiIjOk-WRmBKNv0,20488
13
13
  odoo/addons/account_move_payroll_import/security/ir.model.access.csv,sha256=YI4EAYd35NkiQvd1URS3Ex_zV3GVuI1-T-thl9mlCrU,536
14
14
  odoo/addons/account_move_payroll_import/static/src/css/styles.css,sha256=JK4NBJ_TIy-sWYIGa5nRlZh-KH1OKr1eBzCYx7pJjyI,522
15
15
  odoo/addons/account_move_payroll_import/static/src/js/payroll_import_button.js,sha256=cK9eHxA9jCSGr0HuZFV5Gvy8WWXe8iwNSDV4bYpJEFc,844
16
16
  odoo/addons/account_move_payroll_import/static/src/xml/payroll_import_templates.xml,sha256=HKgIpLA1aN9JruR-W3yKb5MEFezCGurxJAG1sOhDlQ0,731
17
17
  odoo/addons/account_move_payroll_import/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
18
- odoo/addons/account_move_payroll_import/utils/file_utils.py,sha256=ngbyD5Z9kdJ4nSiuI2jxuuTUTuy9ZrLrXEVjrXVyJpI,566
19
- odoo/addons/account_move_payroll_import/utils/parse_utils.py,sha256=G5Crc1A0NzMtD6zSZOl2PVrgMMOfTOZNR2y0Mh9u3FM,1020
18
+ odoo/addons/account_move_payroll_import/utils/file_utils.py,sha256=kgf_NfE-HwJlIv6M8aVJFWl7ZHMRGJuCg6cqITXQvOg,615
19
+ odoo/addons/account_move_payroll_import/utils/parse_utils.py,sha256=z0C9Q14W24tBRfb-j28w1kVnVc7WPXVGHZ8b58g4ziA,1496
20
20
  odoo/addons/account_move_payroll_import/views/assets_template.xml,sha256=SMV2_61cbZG_IjIlsBEiYVLVAb4VmoBRYSsiljou1jU,544
21
21
  odoo/addons/account_move_payroll_import/views/payroll_import_views.xml,sha256=r4PrdTU7MY_KZMJFIcOgms9IaCPv2sirJagnlVWUotI,10386
22
22
  odoo/addons/account_move_payroll_import/wizards/__init__.py,sha256=ZJP90LnlsKPOz5hOqllzpC8O0__7WcIiH6FauPHav_w,60
23
- odoo/addons/account_move_payroll_import/wizards/payroll_import_wizard.py,sha256=gdOBxLPhEmZ2GnUi2rTz5JBfCWk1gy53cFM3Mx8kGCg,12340
23
+ odoo/addons/account_move_payroll_import/wizards/payroll_import_wizard.py,sha256=bJjuYMjc_kSspxWld8xw6nMvE-JgwDRurYBjEzZ9zoE,12428
24
24
  odoo/addons/account_move_payroll_import/wizards/payroll_import_wizard.xml,sha256=p7ewpc4WKDMdJ3a5DGYLtyX8bYDZWHqUrZ42XKzW868,1926
25
- odoo_addon_account_move_payroll_import-16.0.1.0.1.dist-info/METADATA,sha256=uqfPwlUPPXRpa289NBaW--5RmVg0MdDZ9DlPwY9Wqss,3905
26
- odoo_addon_account_move_payroll_import-16.0.1.0.1.dist-info/WHEEL,sha256=QyeGbh-t8WT0nt0_LNSP02jN-g4ymd1egk1U3osCGMU,110
27
- odoo_addon_account_move_payroll_import-16.0.1.0.1.dist-info/top_level.txt,sha256=qBj40grFkGOfDZ2WDSw3y1RnDlgG0u8rP8pvGNdbz4w,5
28
- odoo_addon_account_move_payroll_import-16.0.1.0.1.dist-info/RECORD,,
25
+ odoo_addon_account_move_payroll_import-16.0.1.0.3.dist-info/METADATA,sha256=Kh-cYP-FgxqMszhcSUW9Fme8LfBBvivoSGMDicE05fQ,3905
26
+ odoo_addon_account_move_payroll_import-16.0.1.0.3.dist-info/WHEEL,sha256=QyeGbh-t8WT0nt0_LNSP02jN-g4ymd1egk1U3osCGMU,110
27
+ odoo_addon_account_move_payroll_import-16.0.1.0.3.dist-info/top_level.txt,sha256=qBj40grFkGOfDZ2WDSw3y1RnDlgG0u8rP8pvGNdbz4w,5
28
+ odoo_addon_account_move_payroll_import-16.0.1.0.3.dist-info/RECORD,,