Skip to content

Commit

Permalink
[FIX]pos_partner_firstname: create or change partner in pos
Browse files Browse the repository at this point in the history
  • Loading branch information
DorianMAG committed Jan 8, 2024
1 parent b75888c commit 0035399
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 47 deletions.
57 changes: 17 additions & 40 deletions pos_partner_firstname/static/src/js/PartnerDetailsEdit.js
Original file line number Diff line number Diff line change
@@ -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({
Expand Down Expand Up @@ -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 &&
Expand All @@ -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);
Expand Down
14 changes: 7 additions & 7 deletions pos_partner_firstname/static/src/xml/pos.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<t t-inherit="point_of_sale.PartnerDetailsEdit" t-inherit-mode="extension">
<xpath expr="//input[@name='name']" position="attributes">
<attribute name="t-att-readonly">!props.partner.is_company</attribute>
<attribute name="t-att-readonly">!changes.is_company</attribute>
</xpath>
<xpath expr="//div[@class='partner-details-left']/div[1]" position="before">
<div class="partner-detail">
Expand All @@ -12,22 +12,22 @@
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"
/>
<div
class="is_person"
t-on-change="captureChange"
t-attf-style="display: {{!props.partner.is_company ? 'block': 'none'}};"
t-attf-style="display: {{!changes.is_company ? 'block': 'none'}};"
>
<div class='partner-detail'>
<span class='label'>Last Name</span>
<input
class='detail lastname person'
name="lastname"
t-on-change="captureChange"
t-att-value="props.partner.lastname || ''"
t-model="changes.lastname"
placeholder="LastName"
/>
</div>
Expand All @@ -36,15 +36,15 @@
<div
class="is_person"
t-on-change="captureChange"
t-attf-style="display: {{!props.partner.is_company ? 'block': 'none'}};"
t-attf-style="display: {{!changes.is_company ? 'block': 'none'}};"
>
<div class='partner-detail'>
<span class='label'>First Name</span>
<input
class='detail firstname person'
name="firstname"
t-on-change="captureChange"
t-att-value="props.partner.firstname || ''"
t-model="changes.firstname"
placeholder="FirstName"
/>
</div>
Expand Down

0 comments on commit 0035399

Please sign in to comment.