From 0035399e98817d8dc0583147fb8dddf0bf9952d3 Mon Sep 17 00:00:00 2001 From: DoDo Date: Mon, 8 Jan 2024 12:43:09 +0100 Subject: [PATCH] [FIX]pos_partner_firstname: create or change partner in pos --- .../static/src/js/PartnerDetailsEdit.js | 57 ++++++------------- pos_partner_firstname/static/src/xml/pos.xml | 14 ++--- 2 files changed, 24 insertions(+), 47 deletions(-) diff --git a/pos_partner_firstname/static/src/js/PartnerDetailsEdit.js b/pos_partner_firstname/static/src/js/PartnerDetailsEdit.js index 6e93c708db..1cf0efdf31 100644 --- a/pos_partner_firstname/static/src/js/PartnerDetailsEdit.js +++ b/pos_partner_firstname/static/src/js/PartnerDetailsEdit.js @@ -1,12 +1,22 @@ odoo.define("pos_partner_firstname.PartnerDetailsEdit", function (require) { "use strict"; + const {useState} = owl; const {_t} = require("web.core"); const PartnerDetailsEdit = require("point_of_sale.PartnerDetailsEdit"); const Registries = require("point_of_sale.Registries"); const PosPartnerDetailsEdit = (PartnerDetailsEdit) => class extends PartnerDetailsEdit { + setup() { + super.setup(); + this.changes = useState({ + ...this.changes, + firstname: this.props.partner.firstname || null, + lastname: this.props.partner.lastname || null, + is_company: this.props.partner.is_company || false, + }); + } constructor() { super(...arguments); this.rpc({ @@ -35,7 +45,7 @@ odoo.define("pos_partner_firstname.PartnerDetailsEdit", function (require) { processedChanges[key] = value; } } - const checked = $(".is_company").is(":checked"); + const checked = this.changes.is_company; if (!checked) { if ( (!this.props.partner.firstname && @@ -48,49 +58,16 @@ odoo.define("pos_partner_firstname.PartnerDetailsEdit", function (require) { title: _t("Both Customer First and Last Name Are Required"), }); } - if ( - (!this.props.partner.name && !processedChanges.name) || - processedChanges.name === "" - ) { - this.props.partner.name = this._update_partner_name( - processedChanges.lastname, - processedChanges.firstname - ); - } - } else if ( - processedChanges.is_company && - (processedChanges.firstname || processedChanges.lastname) - ) { + this.changes.name = this._update_partner_name( + processedChanges.lastname, + processedChanges.firstname + ); + processedChanges.name = this.changes.name; + } else if (checked) { this.changes.lastname = this.changes.firstname = undefined; } super.saveChanges(); } - captureChange(event) { - super.captureChange(event); - if (event.target.name === "is_company") { - const checked = event.currentTarget.checked; - $(".is_person") - .toArray() - .forEach(function (el) { - $(el).css("display", !checked ? "block" : "none"); - }); - - this.changes[event.target.name] = checked; - $(".client-name").attr("readonly", !checked); - if (!checked) { - const lastname = this.props.partner.lastname - ? this.props.partner.lastname - : ""; - const firstname = this.props.partner.firstname - ? this.props.partner.firstname - : ""; - this.props.partner.name = this._update_partner_name( - lastname, - firstname - ); - } - } - } }; Registries.Component.extend(PartnerDetailsEdit, PosPartnerDetailsEdit); diff --git a/pos_partner_firstname/static/src/xml/pos.xml b/pos_partner_firstname/static/src/xml/pos.xml index 9b65c880ce..b9fbd37a8d 100644 --- a/pos_partner_firstname/static/src/xml/pos.xml +++ b/pos_partner_firstname/static/src/xml/pos.xml @@ -3,7 +3,7 @@ - !props.partner.is_company + !changes.is_company
@@ -12,14 +12,14 @@ type='checkbox' class='detail o_checkbox checkbox is_company' name='is_company' - t-att-checked="props.partner.is_company ? 'checked' : null" + t-att-checked="changes.is_company ? 'checked' : null" t-on-change="captureChange" - t-att-value="props.partner.is_company" + t-model="changes.is_company" />
Last Name @@ -27,7 +27,7 @@ class='detail lastname person' name="lastname" t-on-change="captureChange" - t-att-value="props.partner.lastname || ''" + t-model="changes.lastname" placeholder="LastName" />
@@ -36,7 +36,7 @@
First Name @@ -44,7 +44,7 @@ class='detail firstname person' name="firstname" t-on-change="captureChange" - t-att-value="props.partner.firstname || ''" + t-model="changes.firstname" placeholder="FirstName" />