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

[FW][FIX] point_of_sale: keeping failed to sync orders as an attachment #157119

Closed

Conversation

fw-bot
Copy link
Contributor

@fw-bot fw-bot commented Mar 8, 2024

(wrote by LSE)

Before this commit:
If an error happened when trying to synchronise a PoS order nothing is saved on the backend to inform the user regarding the error.
Note: Odoo logs would contain the information, but it is out of reach for certain clients (on odoo online for instance).

In theory, we can't lose any information as, if the sync process raise an exception, the order is still on the PoS browser cache that will then try to be resync when another order sync happen.
But, in practice, the support received some cases of "missing PoS orders". Which can happen as we fully rely on the client browser cache that can be cleared or use another computer/browser/session.

After this commit:
If an order can not be processed in the backend:

  • the PoS order data is saved in the PoS session attachments
  • a scheduled activity is created in the PoS session

As an un-synced keep being tried to be sync (and will likely fail each time), we compare it with the already attached one to avoid having the content repeated multiple times.
If the order was modified in between, a new attachment with the same name is created.

Note: draft orders that will fail to validate are NOT stored

The attachment and activity are automatically removed when the order of same reference is validated

image

opw-3650239

Forward-Port-Of: #155401
Forward-Port-Of: #147130

@robodoo
Copy link
Contributor

robodoo commented Mar 8, 2024

Pull request status dashboard.

@fw-bot
Copy link
Contributor Author

fw-bot commented Mar 8, 2024

@pedrambiria @caburj cherrypicking of pull request #147130 failed.

stdout:

Auto-merging addons/point_of_sale/models/pos_order.py
CONFLICT (content): Merge conflict in addons/point_of_sale/models/pos_order.py
Auto-merging addons/point_of_sale/models/pos_session.py
Auto-merging addons/point_of_sale/tests/__init__.py
Auto-merging addons/point_of_sale/tests/common.py

stderr:

16:40:17.729473 git.c:463               trace: built-in: git cherry-pick 823db558340d60c881b117352280bcc4a098d4d3
error: could not apply 823db558340d... [FIX] point_of_sale: keeping failed to sync orders as an attachment
hint: After resolving the conflicts, mark them with
hint: "git add/rm <pathspec>", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".
----------
status:

Either perform the forward-port manually (and push to this branch, proceeding as usual) or close this PR (maybe?).

In the former case, you may want to edit this PR message as well.

⚠️ after resolving this conflict, you will need to merge it via @robodoo.

More info at https://github.com/odoo/odoo/wiki/Mergebot#forward-port

@robodoo robodoo added forwardport This PR was created by @fw-bot conflict There was an error while creating this forward-port PR labels Mar 8, 2024
@C3POdoo C3POdoo added the OE the report is linked to a support ticket (opw-...) label Mar 8, 2024
@lse-odoo lse-odoo self-assigned this Mar 11, 2024
@lse-odoo lse-odoo force-pushed the 17.0-16.0-pos-opw-3650239-pebr-Ov_4-fw branch from 7e80000 to db9a792 Compare March 12, 2024 15:35
@C3POdoo C3POdoo requested review from a team and vlst-odoo and removed request for a team March 12, 2024 15:37
@lse-odoo
Copy link
Contributor

@xmo-odoo security override due to conflict (once once once again) please 🙏

@pedrambiria I propose to r+ the PR later when you will more available as 17.0 is used a lot

@xmo-odoo
Copy link
Collaborator

@lse-odoo

security override due to conflict (once once once again) please 🙏

https://docs.python.org/3/library/traceback.html#traceback.format_exception

Changed in version 3.5: The etype argument is ignored and inferred from the type of value.

As far as I can see from 3.5 onwards if there are 3 arguments the first one is just ignored, so you can pas None as first parameter, no need for the type() call.

@lse-odoo lse-odoo force-pushed the 17.0-16.0-pos-opw-3650239-pebr-Ov_4-fw branch from db9a792 to c802a13 Compare March 19, 2024 15:09
@lse-odoo
Copy link
Contributor

lse-odoo commented Mar 19, 2024

https://docs.python.org/3/library/traceback.html#traceback.format_exception

Changed in version 3.5: The etype argument is ignored and inferred from the type of value.

As far as I can see from 3.5 onwards if there are 3 arguments the first one is just ignored, so you can pas None as first parameter, no need for the type() call.

Indeed nice catch!
And I think we can go even further, as Odoo requires Python >= 3.10 to run, we can benefit from the new syntax of this function:

Changed in version 3.10: This function’s behavior and signature were modified to match [print_exception()](https://docs.python.org/3/library/traceback.html#traceback.print_exception).

On which we can just give the exception as a parameter

@lse-odoo
Copy link
Contributor

@xmo-odoo is there still some security check that you would like to check ?

@lse-odoo lse-odoo force-pushed the 17.0-16.0-pos-opw-3650239-pebr-Ov_4-fw branch from 443512f to 582ff0a Compare April 9, 2024 15:35
@lse-odoo
Copy link
Contributor

lse-odoo commented Apr 9, 2024

TODO: see how we handle the order remove from the front end after failed to sync (as no call to the backend is done). Probably garbage collect them

Copy link
Collaborator

@xmo-odoo xmo-odoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@robodoo override=ci/security

@lse-odoo
Copy link
Contributor

TODO 2: may be able to use: #161250 to distinguish for TODO1

@lse-odoo
Copy link
Contributor

TODO-main: discussed with JCB: only orders that are NOT converted to draft interest us to keep. Others can be not stored (so just ignored like restaurant draft orders) as they are considered not fully validated. Depends on PEBR previous PR, so wait for it to be merged

@lse-odoo lse-odoo force-pushed the 17.0-16.0-pos-opw-3650239-pebr-Ov_4-fw branch 4 times, most recently from f44c94f to 76da46a Compare May 20, 2024 15:21
@lse-odoo
Copy link
Contributor

@pedrambiria would you mind reviewing the PR please ? :)

I used the option that you introduced on this part of the code to forward the information to the backend:
https://github.com/odoo/odoo/pull/157119/files#diff-86ab5d4b3803e1a7fa3373b7225bc610cfdcfc70fb413673b71d52a752706137R1266
( I could have used it in the orm call (like the draft parameter), but it was sounding quite unstable)

@lse-odoo
Copy link
Contributor

@xmo-odoo would you mind giving me your opinion on this part of the code:

https://github.com/odoo/odoo/pull/157119/files#diff-86db45bc09231ecbc49a64405de92e0a022a6833980f46a9111501f8c8832760R2394

I'm pretty sure there is a cleaner/better way to do so. Would it be better to make the whole message a Markup maybe ?

@lse-odoo lse-odoo force-pushed the 17.0-16.0-pos-opw-3650239-pebr-Ov_4-fw branch 2 times, most recently from d37de6d to bdf3e59 Compare May 20, 2024 15:31
@xmo-odoo
Copy link
Collaborator

would you mind giving me your opinion on this part of the code:

https://github.com/odoo/odoo/pull/157119/files#diff-86db45bc09231ecbc49a64405de92e0a022a6833980f46a9111501f8c8832760R2394

I'm pretty sure there is a cleaner/better way to do so. Would it be better to make the whole message a Markup maybe ?

You can use nl2br_enclose(message, 'code'), it will perform newline to <br> conversion (safely, by first escaping the message) then enclose that in a <code> tag.

@pedrambiria
Copy link
Contributor

@lse-odoo you can add it to the context in _getCreateOrderContext

@lse-odoo lse-odoo force-pushed the 17.0-16.0-pos-opw-3650239-pebr-Ov_4-fw branch 2 times, most recently from 931a1a6 to 5d93052 Compare May 27, 2024 13:14
@lse-odoo
Copy link
Contributor

would you mind giving me your opinion on this part of the code:
https://github.com/odoo/odoo/pull/157119/files#diff-86db45bc09231ecbc49a64405de92e0a022a6833980f46a9111501f8c8832760R2394
I'm pretty sure there is a cleaner/better way to do so. Would it be better to make the whole message a Markup maybe ?

You can use nl2br_enclose(message, 'code'), it will perform newline to <br> conversion (safely, by first escaping the message) then enclose that in a <code> tag.

I was not able to find a good way to use nl2br_enclose according to its code it break line for the string content you give it to it which will be encapsulated into the given tag. In my case there is no point as it only contains the string of the PoS reference which will never contain breaklines. I used instead nl2br on the overall Markup which looks more relevant. What do you think of this ?

@lse-odoo lse-odoo force-pushed the 17.0-16.0-pos-opw-3650239-pebr-Ov_4-fw branch 5 times, most recently from d67e59c to df0dc1b Compare May 27, 2024 14:05
@C3POdoo C3POdoo requested review from a team, xmo-odoo, rco-odoo and Julien00859 and removed request for a team May 27, 2024 14:07
Before this commit:
 If an error happened when trying to process a PoS order nothing
 is saved on the backend to inform the user regarding the error.
 Note: Odoo logs would contain the information, but it is out of reach
 for certain clients (on odoo online for instance).

 In theory, we can't lose any information as, if the sync process raise
 an exception, the order is still on the PoS browser cache that will
 then try to be resync when another order sync happen.
 But, in practice, the support received some cases of "missing PoS
 orders". Which can happen as we fully rely on the client browser
 cache that can be cleared or use another computer/browser/session.

After this commit:
 If an order can not be processed in the backend:
  - the PoS order data is saved in the PoS session attachments
  - a scheduled activity is created in the PoS session

 As an un-synced keep being tried to be sync (and will likely fail
 each time), we compare it with the already attached one to avoid having
 the content repeated multiple times.
 If the order was modified in between, a new attachment with the same
 name is created.

 Note: draft orders that will fail to validate are NOT stored

 The attachment and activity are automatically removed when the order
 of same reference is validated

We also add logs when a PoS order start/finish to synchronise

opw-3650239

X-original-commit: 44fff0a
@lse-odoo lse-odoo force-pushed the 17.0-16.0-pos-opw-3650239-pebr-Ov_4-fw branch from df0dc1b to 8868f47 Compare May 27, 2024 15:31
@xmo-odoo
Copy link
Collaborator

I was not able to find a good way to use nl2br_enclose according to its code it break line for the string content you give it to it which will be encapsulated into the given tag. In my case there is no point as it only contains the string of the PoS reference which will never contain breaklines. I used instead nl2br on the overall Markup which looks more relevant. What do you think of this ?

I might have misread the order of operation in the original, sorry.

Looks good to me.

@lse-odoo
Copy link
Contributor

@pedrambiria could you forward bot r+ this PR if you agree with the changes ? :)

@pedrambiria
Copy link
Contributor

robodoo r+

@robodoo robodoo closed this in 5f2693e May 29, 2024
lohwswilson pushed a commit to lohwswilson/odoo that referenced this pull request Jun 5, 2024
Before this commit:
 If an error happened when trying to process a PoS order nothing
 is saved on the backend to inform the user regarding the error.
 Note: Odoo logs would contain the information, but it is out of reach
 for certain clients (on odoo online for instance).

 In theory, we can't lose any information as, if the sync process raise
 an exception, the order is still on the PoS browser cache that will
 then try to be resync when another order sync happen.
 But, in practice, the support received some cases of "missing PoS
 orders". Which can happen as we fully rely on the client browser
 cache that can be cleared or use another computer/browser/session.

After this commit:
 If an order can not be processed in the backend:
  - the PoS order data is saved in the PoS session attachments
  - a scheduled activity is created in the PoS session

 As an un-synced keep being tried to be sync (and will likely fail
 each time), we compare it with the already attached one to avoid having
 the content repeated multiple times.
 If the order was modified in between, a new attachment with the same
 name is created.

 Note: draft orders that will fail to validate are NOT stored

 The attachment and activity are automatically removed when the order
 of same reference is validated

We also add logs when a PoS order start/finish to synchronise

opw-3650239

closes odoo#157119

X-original-commit: 44fff0a
Signed-off-by: Joseph Caburnay (jcb) <jcb@odoo.com>
Signed-off-by: Pedram Bi Ria (pebr) <pebr@odoo.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conflict There was an error while creating this forward-port PR forwardport This PR was created by @fw-bot OE the report is linked to a support ticket (opw-...)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants