8000 [REF] pos_loyalty, pos*: real time syncing adaptation for loyalty by paan-odoo · Pull Request #4684 · odoo-dev/odoo · GitHub
[go: up one dir, main page]

Skip to content

[REF] pos_loyalty, pos*: real time syncing adaptation for loyalty #4684

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

Open
wants to merge 6 commits into
base: master-pos_ref_syncing_team-branch
Choose a base branch
from

Conversation

paan-odoo
Copy link
@paan-odoo paan-odoo commented May 15, 2025

pos*: point_of_sale, pos_event, pos_restaurant_loaylty, pos_sale_loyalty

In this commit:

  • We are adding real-time synchronisation for loyalty for real-time loyalty card creation. Created loyalty cards from pos will be updated on order validation with the confirm_coupon_programs method call. We will update the loyalty cards' original ID with UUID in order's couponChangePoints uiState before the method call, so that it will be easy to maintain loyalty cards in pos.
  • We are removing extra fields from orderlines.
  • Updating start_tour with start_pos_tour in test cases.
  • Added test case test_physical_gift_card_return_from_floor to test the physical gift card in the restaurant.
  • We are replacing module names typo loyality with loyalty in pos_restaurant_loyalty and pos_sale_loyalty modules.
  • Also, we are fixing test cases in the pos_event module.

task-4766756

@robodoo
8000
Copy link
robodoo commented May 15, 2025

This PR targets the un-managed branch odoo-dev/odoo:master-pos_ref_syncing_team-branch, it needs to be retargeted before it can be merged.

@paan-odoo paan-odoo force-pushed the master-pos_ref_syncing_team-branch-paan branch 5 times, most recently from c1ab495 to e4137ed Compare May 15, 2025 08:44
@vlst-odoo vlst-odoo force-pushed the master-pos_ref_syncing_team-branch branch from e37abd3 to 2ce244a Compare May 15, 2025 09:28
@paan-odoo paan-odoo force-pushed the master-pos_ref_syncing_team-branch-paan branch 3 times, most recently from 9896110 to bafc7eb Compare May 15, 2025 13:32
@vlst-odoo vlst-odoo force-pushed the master-pos_ref_syncing_team-branch branch from be34796 to 3c3236c Compare May 15, 2025 15:36
@paan-odoo paan-odoo force-pushed the master-pos_ref_syncing_team-branch-paan branch 2 times, most recently from 52727f9 to 14e5701 Compare May 16, 2025 04:44
@paan-odoo paan-odoo marked this pull request as ready for review May 16, 2025 06:14
@robodoo
Copy link
robodoo commented May 16, 2025

This PR targets the un-managed branch odoo-dev/odoo:master-pos_ref_syncing_team-branch, it needs to be retargeted before it can be merged.

@paan-odoo paan-odoo force-pushed the master-pos_ref_syncing_team-branch-paan branch from 14e5701 to 75e684d Compare May 16, 2025 06:58
@paan-odoo paan-odoo changed the title [REF] pos_loyalty: real time syncing adaptation for loyalty [REF] pos_loyalty, pos*: real time syncing adaptation for loyalty May 16, 2025
@paan-odoo paan-odoo force-pushed the master-pos_ref_syncing_team-branch-paan branch from 75e684d to fd1c2a7 Compare May 16, 2025 07:25
@@ -129,7 +129,7 @@ def test_selling_multislot_event_in_pos(self):
self.main_pos_config.with_user(self.pos_user).open_ui()
self.start_pos_tour('SellingMultiSlotEventInPos')

order = self.env['pos.order'].search([], order='id desc', limit=1)
order = self.env['pos.order'].search([])[1]

Choose a reason for hiding this comment

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

is this because now there is an extra draft order at the end ? If so, can you add a comment about that ?

@@ -2,7 +2,7 @@


{
'name': 'POS - Restaurant Loyality',
'name': 'POS - Restaurant Loyalty',

Choose a reason for hiding this comment

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

can you put this in a new commit ? Same for pos_sale_loyalty

"PosLoyaltyTour12",
login="pos_user",
)
self.start_pos_tour("PosLoyaltyTour12")

Choose a reason for hiding this comment

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

can you put the changes to start_tour in a separate commit? This way we have one for renaming the methods and one for start_tour


id_updates = {}

for [operation, *data] in queue:
match operation:
case "CREATE":
model, vals = data
new_record = self.env[model].create([replace_uuid_with_id(model, vals)])
new_record = self.env[model].sudo().create([replace_uuid_with_id(model, vals)])

Choose a reason for hiding this comment

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

we definitely cannot do this.
We cannot have a public method that allows anyone to create any record.
For the specific cases where we need to create records and need higher privileges you can create special methods that you can call from pos. In these methods you have to properly verify that sudo is used correctly

@@ -247,15 +247,15 @@ def adapt_value(model, key, value):
return [(6, 0, [get_record(self.env[model]._fields[key].comodel_name, val).id for val in value])]
case _:
return value
return {key: adapt_value(model, key, value) for key, value in vals.items()}
return {key: adapt_value(model, key, value) for key, value in vals.items() if self.env[model]._fields.get(key)}
Copy link
@vlst-odoo vlst-odoo May 16, 2025

Choose a reason for hiding this comment

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

why do you need this ?
Why would you have here keys that don't exist? Ideally the pos should only send valid data via flush. Perhaps we can do this filtering in the frontend.

The idea is that if you send data that you will just ignore, you can be more resource efficient by not sending the data in the first place

Copy link
Author

Choose a reason for hiding this comment

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

In loyalty, extra fields are created from the front end, like _reward_product_id and _code_activated_coupon_ids, which are not available in the backend. In that case, we have to remove those fields from creation.

Copy link
@vlst-odoo vlst-odoo May 16, 2025

Choose a reason for hiding this comment

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

that makes sense. Can you remove the extra fields in js tough ?

Comment on lines +349 to +351
if (this.currentOrder.waitForPushOrder()) {
await this.postPushOrderResolve([this.currentOrder.id]);
}

Choose a reason for hiding this comment

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

do we still need this postPush mechanism ?
Whenever you use data.call you will force a flush anyways ?

Maybe this can be done in a later task though

@@ -280,7 +280,7 @@ export class PosData extends Reactive {
if (!ids.length) {
return;
}
const vals = models[modelName].getBy("uuid", ids[0]).raw;
const vals = models[modelName].getBy("uuid", ids[0])?.raw || {};

Choose a reason for hiding this comment

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

what are the cases where .raw returns undefined ?

Comment on lines 663 to 672
if (this.queue.length > 0) {
throw new Error("There are unsynced changes in the queue.");
}

Choose a reason for hiding this comment

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

can you replace the error with a console.error ?

@@ -50,6 +50,7 @@ export class DataServiceOptions {
"pos.pack.operation.lot": ["uuid"],
"event.registration": ["uuid"],
"event.registration.answer": ["uuid"],
"loyalty.card": ["uuid", "id"],

Choose a reason for hiding this comment

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

ideally we would have added this in an override in loyalty but as it has been the pattern to just add in pos we can also do it here.

On a different note, isn't the id index created by default? Do you need to manually add it ?

@vlst-odoo vlst-odoo force-pushed the master-pos_ref_syncing_team-branch branch from 3c3236c to 1952c76 Compare May 16, 2025 10:07
paan-odoo added 2 commits May 16, 2025 18:02
In this commit:

- We are adding real-time synchronisation for loyalty for real-time
  loyalty card creation. Created loyalty cards from pos will be updated on order
  validation with the `confirm_coupon_programs` method call. We will update the
  loyalty cards' original ID with UUID in order's couponChangePoints uiState
  Before the method call, so that it will be easy to maintain loyalty cards in pos.

task-4766756
In this commit:

- We are replacing start_tour with strat_pos_tour,

task-4766756
paan-odoo added 2 commits May 16, 2025 18:02
In this commit:

- We are renaming methods `_get_reward_lines` with `_getRewardLines` and
  `_get_regular_order_lines` with `_getRegularOrderLines`.

task-4766756
In this commit:

- We are replacing `loyality` with `loyalty` in pos_restaurant_loyalty
  module name.

task-4766756
@paan-odoo paan-odoo force-pushed the master-pos_ref_syncing_team-branch-paan branch from fd1c2a7 to ae28f15 Compare May 16, 2025 12:32
paan-odoo added 2 commits May 16, 2025 18:04
In this commit:

- We are replacing `loyality` with `loyalty` in pos_sale_loyalty
  module name.

task-4766756
In this commit:

- We are fixing test cases for pos_event.

task-4766756
@paan-odoo paan-odoo force-pushed the master-pos_ref_syncing_team-branch-paan branch from ae28f15 to 8770973 Compare May 16, 2025 12:34
@@ -0,0 +1,181 @@
# Query: start_pos_tour

Choose a reason for hiding this comment

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

?

@@ -144,7 +144,7 @@ def test_pos_loyalty_tour_basic(self):
(4, self.env.ref('stock.group_stock_user').id),
]
})
self.start_pos_tour("PosLoyaltyTour1")
self.start_pos_tour("PosLoyaltyTour1", login="pos_admin")

Choose a reason for hiding this comment

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

why do you have to use admin now ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0