Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[15.0][BKP][IMP] edi_oca: add button to regenerate file after error on validation #1013

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion edi_oca/models/edi_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,13 @@ def exchange_generate(self, exchange_record, store=True, force=False, **kw):

:param exchange_record: edi.exchange.record recordset
:param store: store output on the record itself
:param force: allow to re-genetate the content
:param force: allow to re-generate the content
:param kw: keyword args to be propagated to output generate handler
"""
self.ensure_one()
if force and exchange_record.exchange_file:
# Remove file to regenerate
exchange_record.exchange_file = False
self._check_exchange_generate(exchange_record, force=force)
output = self._exchange_generate(exchange_record, **kw)
message = None
Expand Down
4 changes: 4 additions & 0 deletions edi_oca/models/edi_exchange_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,10 @@ def _retry_exchange_action(self):
self._execute_next_action()
return True

def action_regenerate(self):
for rec in self:
rec.action_exchange_generate(force=True)

def action_open_related_record(self):
self.ensure_one()
if not self.related_record_exists:
Expand Down
25 changes: 25 additions & 0 deletions edi_oca/tests/test_backend_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,28 @@ def test_generate_validate_record_error(self):
],
)
self.assertIn("Data seems wrong!", self.record_out.exchange_error)

def test_validate_record_error_regenerate(self):
self.record_out.write({"edi_exchange_state": "new"})
exc = EDIValidationError("Data seems wrong!")
self.backend.with_context(test_break_validate=exc).exchange_generate(
self.record_out
)
self.assertRecordValues(
self.record_out,
[
{
"edi_exchange_state": "validate_error",
}
],
)
self.record_out.with_context(fake_output="yeah!").action_regenerate()
self.assertEqual(self.record_out._get_file_content(), "yeah!")
self.assertRecordValues(
self.record_out,
[
{
"edi_exchange_state": "output_pending",
}
],
)
6 changes: 6 additions & 0 deletions edi_oca/views/edi_exchange_record_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@
string="Retry"
attrs="{'invisible': [('retryable', '=', False)]}"
/>
<button
name="action_regenerate"
type="object"
string="Regenerate"
attrs="{'invisible': ['|', ('direction', 'in', ('input', False)), ('edi_exchange_state', '!=', 'validate_error')]}"
/>
<!-- FIXME: colors are ignored...
and can't find how they are supposed to work.
Probably not supported at all. -->
Expand Down
Loading