refactor: remove manual customer sync functionality and associated UI button
This commit is contained in:
parent
fce0369533
commit
97f8a889f7
@ -17,55 +17,4 @@ patch(PartnerList.prototype, {
|
|||||||
return super.clickPartner(...arguments);
|
return super.clickPartner(...arguments);
|
||||||
},
|
},
|
||||||
|
|
||||||
async updateCustomerData() {
|
|
||||||
if (!navigator.onLine) {
|
|
||||||
if (this.notification) {
|
|
||||||
this.notification.add("You must be online to update customer data.", 3000);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
this.state.loading = true;
|
|
||||||
// console.log("[pos_loyalty_multi_level] Fetching the latest 100 customers from the backend...");
|
|
||||||
|
|
||||||
// In Odoo 19, data.searchRead fetches data AND creates/updates the local reactive models invisibly
|
|
||||||
const newPartners = await this.pos.data.searchRead(
|
|
||||||
"res.partner",
|
|
||||||
[["active", "=", true]],
|
|
||||||
this.pos.data.fields["res.partner"],
|
|
||||||
{ limit: 25, order: 'id desc' }
|
|
||||||
);
|
|
||||||
|
|
||||||
let addedCount = 0;
|
|
||||||
for (const partner of newPartners) {
|
|
||||||
// Fetch the instantiated local model proxy instead of the raw data dict
|
|
||||||
const localPartner = this.pos.models["res.partner"].get(partner.id);
|
|
||||||
if (localPartner && !this.loadedPartnerIds.has(localPartner.id)) {
|
|
||||||
this.loadedPartnerIds.add(localPartner.id);
|
|
||||||
this.state.loadedPartners.push(localPartner);
|
|
||||||
addedCount++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Refresh initial view
|
|
||||||
this.state.initialPartners = this.pos.models["res.partner"].filter((p) => {
|
|
||||||
const par = p.property_account_receivable_id;
|
|
||||||
return !par || par.non_trade !== true;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (this.notification) {
|
|
||||||
this.notification.add(`Successfully synced list. Found ${addedCount} new customers.`, 3000);
|
|
||||||
}
|
|
||||||
// console.log(`[pos_loyalty_multi_level] Fetch complete. Added ${addedCount} customers to the session.`);
|
|
||||||
|
|
||||||
} catch (e) {
|
|
||||||
console.warn("[pos_loyalty_multi_level] Failed to update customer data:", e);
|
|
||||||
if (this.notification) {
|
|
||||||
this.notification.add("Failed to fetch customer data from server.", 3000);
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
this.state.loading = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,12 +1,3 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<templates id="template" xml:space="preserve">
|
<templates id="template" xml:space="preserve">
|
||||||
<t t-name="pos_loyalty_multi_level.PartnerList" t-inherit="point_of_sale.PartnerList" t-inherit-mode="extension">
|
|
||||||
<xpath expr="//t[@t-set-slot='header']/button" position="after">
|
|
||||||
<button class="btn btn-secondary btn-lg lh-lg me-2 ms-2" role="img" aria-label="Update Customer Data"
|
|
||||||
t-on-click="() => this.updateCustomerData()"
|
|
||||||
title="Fetch newly registered customers from the backend">
|
|
||||||
<i class="fa fa-refresh"></i> Update Data
|
|
||||||
</button>
|
|
||||||
</xpath>
|
|
||||||
</t>
|
|
||||||
</templates>
|
</templates>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user