erpnext icon indicating copy to clipboard operation
erpnext copied to clipboard

fix: distributed discounts on si

Open blaggacao opened this issue 1 year ago • 6 comments

Context

  • Tax Included in Price
  • Additional Discount on Grand Total

Did not work.

Now it does, needs tests to stabilize.

~~Test failures in the POS seem like trivial, unintended side effects.~~ All green after fixup

It took us more than 8 months to figure out this was actually a bug in ERPNext.

blaggacao avatar Jun 02 '24 08:06 blaggacao

@blaggacao Before me checking this, can you resolve the conflicts and let the test suite run.

ruthra-kumar avatar Aug 28 '24 04:08 ruthra-kumar

unrelated changes in https://github.com/frappe/erpnext/pull/41721/commits/6bfefd222e092f76ad483ba6cdac968a1d7361b5

ruthra-kumar avatar Aug 28 '24 09:08 ruthra-kumar

unrelated changes in 6bfefd2

Well, without them, I can't properly work on json files without forced reformatting and introducing unnecessary diff.

.editorconfig is misconfigured and others would be affected as well, as long as they use a prettier-based language server with auto-format on save switched on which reads out .editorconfig for auto-formatting. However, the framework saves json files with a space-indent of 1 space, not 2 spaces as the editorconfig configures.

Still, I can extract that devx fix into a separate PR, though, so that this PR comtext remains as narrowly scoped as possible, without that opportunistic fix. I'll do that in a bit ...

blaggacao avatar Aug 28 '24 10:08 blaggacao

Well, without them, I can't properly work on json files without forced reformatting and introducing unnecessary diff.

.editorconfig is misconfigured and others would be affected as well, as long as they use a prettier-based language server with auto-format on save switched on which reads out .editorconfig for auto-formatting. However, the framework saves json files with a space-indent of 1 space, not 2 spaces as the editorconfig configures.

The pre-commit hooks should make sure there are no incorrect formatting before committing. So, I don't how you'll get unnecessary diff.

Still, I can extract that devx fix into a separate PR, though, so that this PR comtext remains as narrowly scoped as possible, without that opportunistic fix. I'll do that in a bit ...

Please do

ruthra-kumar avatar Aug 28 '24 11:08 ruthra-kumar

@ruthra-kumar Could you help me understand how to fix the test so that I can run it individually?

(it seems to be missing some generic test data)

❯ bench run-tests --module "erpnext.controllers.tests.test_distributed_discount"
/nix/store/3bkksgdvxkqmbzhakhq1g8a1jv7rpkd1-python3-3.11.9-env/lib/python3.11/site-packages/passlib/utils/__init__.py:854: DeprecationWarning: 'crypt' is deprecated and slated for removal in Python 3.13
  from crypt import crypt as _crypt
EE
======================================================================
ERROR: test_distributed_discount_amount (erpnext.controllers.tests.test_distributed_discount.TestTaxesAndTotals.test_distributed_discount_amount)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/blaggacao/src/gitlab.com/pristina/infraestructura/apps/erpnext/erpnext/controllers/tests/test_distributed_discount.py", line 18, in test_distributed_discount_amount
    so.save()
  File "/home/blaggacao/src/gitlab.com/pristina/infraestructura/apps/frappe/frappe/model/document.py", line 503, in save
    return self._save(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/blaggacao/src/gitlab.com/pristina/infraestructura/apps/frappe/frappe/model/document.py", line 525, in _save
    return self.insert()
           ^^^^^^^^^^^^^
  File "/home/blaggacao/src/gitlab.com/pristina/infraestructura/apps/frappe/frappe/model/document.py", line 449, in insert
    self._validate_links()
  File "/home/blaggacao/src/gitlab.com/pristina/infraestructura/apps/frappe/frappe/model/document.py", line 1096, in _validate_links
    frappe.throw(_("Could not find {0}").format(msg), frappe.LinkValidationError)
  File "/home/blaggacao/src/gitlab.com/pristina/infraestructura/apps/frappe/frappe/__init__.py", line 675, in throw
    msgprint(
  File "/home/blaggacao/src/gitlab.com/pristina/infraestructura/apps/frappe/frappe/__init__.py", line 640, in msgprint
    _raise_exception()
  File "/home/blaggacao/src/gitlab.com/pristina/infraestructura/apps/frappe/frappe/__init__.py", line 591, in _raise_exception
    raise exc
frappe.exceptions.LinkValidationError: Could not find Company: _Test Company, Row #1: Delivery Warehouse: _Test Warehouse - _TC

======================================================================
ERROR: test_distributed_discount_amount_with_taxes (erpnext.controllers.tests.test_distributed_discount.TestTaxesAndTotals.test_distributed_discount_amount_with_taxes)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/blaggacao/src/gitlab.com/pristina/infraestructura/apps/erpnext/erpnext/controllers/tests/test_distributed_discount.py", line 49, in test_distributed_discount_amount_with_taxes
    so.save()
  File "/home/blaggacao/src/gitlab.com/pristina/infraestructura/apps/frappe/frappe/model/document.py", line 503, in save
    return self._save(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/blaggacao/src/gitlab.com/pristina/infraestructura/apps/frappe/frappe/model/document.py", line 525, in _save
    return self.insert()
           ^^^^^^^^^^^^^
  File "/home/blaggacao/src/gitlab.com/pristina/infraestructura/apps/frappe/frappe/model/document.py", line 449, in insert
    self._validate_links()
  File "/home/blaggacao/src/gitlab.com/pristina/infraestructura/apps/frappe/frappe/model/document.py", line 1096, in _validate_links
    frappe.throw(_("Could not find {0}").format(msg), frappe.LinkValidationError)
  File "/home/blaggacao/src/gitlab.com/pristina/infraestructura/apps/frappe/frappe/__init__.py", line 675, in throw
    msgprint(
  File "/home/blaggacao/src/gitlab.com/pristina/infraestructura/apps/frappe/frappe/__init__.py", line 640, in msgprint
    _raise_exception()
  File "/home/blaggacao/src/gitlab.com/pristina/infraestructura/apps/frappe/frappe/__init__.py", line 591, in _raise_exception
    raise exc
frappe.exceptions.LinkValidationError: Could not find Company: _Test Company, Row #1: Delivery Warehouse: _Test Warehouse - _TC, Row #1: Cost Center: _Test Cost Center - _TC

----------------------------------------------------------------------
Ran 2 tests in 0.366s

FAILED (errors=2)

blaggacao avatar Aug 30 '24 09:08 blaggacao

@blaggacao Most of the test cases are not indempotent. They'll need some test data setup by test suite of another doctype.

Try running test suite of 'Company' doctype. Then, try running yours.

ruthra-kumar avatar Aug 30 '24 10:08 ruthra-kumar

@ruthra-kumar I finally found the time to perfect the test. This is ready to ship. I'll stand by for any in-adverted consequences, should there be any.

blaggacao avatar Sep 03 '24 19:09 blaggacao

test_distributed_discount_amount_with_taxes is still failing

ruthra-kumar avatar Sep 05 '24 07:09 ruthra-kumar

Thanks Ruthra, that was just a fat finger of mine. :smile:

blaggacao avatar Sep 05 '24 09:09 blaggacao