Skip to content

Commit

Permalink
[MIG] pos_partner_firstname: Migration 17.0
Browse files Browse the repository at this point in the history
Refactoring to OWL 2.0
Disabling an extra connection to server
  • Loading branch information
etobella committed Jan 17, 2024
1 parent b951f8c commit 3ba9a89
Show file tree
Hide file tree
Showing 13 changed files with 140 additions and 193 deletions.
1 change: 1 addition & 0 deletions pos_partner_firstname/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ Contributors
- Lorenzo Battistini
(`https://takobi.online <https://takobi.online>`__)
- Dhara Solanki <[email protected]>
- Enric Tobella (`https://www.dixmit.com <https://www.dixmit.com>`__)

Maintainers
-----------
Expand Down
10 changes: 5 additions & 5 deletions pos_partner_firstname/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"name": "POS Partner Firstname",
"summary": "POS Support of partner firstname",
"version": "16.0.1.0.0",
"version": "17.0.1.0.0",
"development_status": "Beta",
"category": "Point Of Sale",
"website": "https://github.com/OCA/pos",
Expand All @@ -20,10 +20,10 @@
"partner_firstname",
],
"assets": {
"point_of_sale.assets": [
"pos_partner_firstname/static/src/js/PartnerDetailsEdit.js",
"pos_partner_firstname/static/src/js/PartnerScreen.js",
"pos_partner_firstname/static/src/xml/pos.xml",
"point_of_sale._assets_pos": [
"pos_partner_firstname/static/src/app/PartnerDetailsEdit.esm.js",
"pos_partner_firstname/static/src/app/PartnerDetailsEdit.xml",
"pos_partner_firstname/static/src/app/PartnerDetailsEdit.scss",
],
},
}
2 changes: 1 addition & 1 deletion pos_partner_firstname/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from . import res_partner
from . import pos_session
from . import pos_config
16 changes: 16 additions & 0 deletions pos_partner_firstname/models/pos_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2024 Dixmit
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class PosConfig(models.Model):
_inherit = "pos.config"

partner_names_order = fields.Char(compute="_compute_partner_names_order")

@api.depends()
def _compute_partner_names_order(self):
order = self.env["res.partner"]._get_names_order()
for record in self:
record.partner_names_order = order
13 changes: 0 additions & 13 deletions pos_partner_firstname/models/res_partner.py

This file was deleted.

1 change: 1 addition & 0 deletions pos_partner_firstname/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- Roberto Fichera \<<[email protected]>\>
- Lorenzo Battistini (<https://takobi.online>)
- Dhara Solanki \<<[email protected]>\>
- Enric Tobella (<https://www.dixmit.com>)
1 change: 1 addition & 0 deletions pos_partner_firstname/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<li>Lorenzo Battistini
(<a class="reference external" href="https://takobi.online">https://takobi.online</a>)</li>
<li>Dhara Solanki &lt;<a class="reference external" href="mailto:dhara.solanki&#64;initos.com">dhara.solanki&#64;initos.com</a>&gt;</li>
<li>Enric Tobella (<a class="reference external" href="https://www.dixmit.com">https://www.dixmit.com</a>)</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
61 changes: 61 additions & 0 deletions pos_partner_firstname/static/src/app/PartnerDetailsEdit.esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/** @odoo-module **/
import {ErrorPopup} from "@point_of_sale/app/errors/popups/error_popup";
import {PartnerDetailsEdit} from "@point_of_sale/app/screens/partner_list/partner_editor/partner_editor";
import {_t} from "@web/core/l10n/translation";
import {patch} from "@web/core/utils/patch";
import {useService} from "@web/core/utils/hooks";

patch(PartnerDetailsEdit.prototype, {
setup() {
super.setup(...arguments);
this.popup = useService("popup");
this.partner_names_order = this.pos.config.partner_names_order;
this.changes.is_company = this.props.partner.is_company;
this.changes.firstname = this.props.partner.firstname;
this.changes.lastname = this.props.partner.lastname;
},
get isCompanyIcon() {
if (this.changes.is_company) {
return "fa-building";
}
return "fa-user";
},
toggleIsCompany() {
this.changes.is_company = !this.changes.is_company;
},
checkPartnerPersonName() {
/* We add this hook in order to check second last name later */
return !this.changes.firstname && !this.changes.lastname;
},
saveChanges() {
if (this.changes.is_company) {
this.changes.lastname = this.changes.firstname = undefined;
} else {
if (this.checkPartnerPersonName()) {
return this.popup.add(ErrorPopup, {
title: _t("Missing information"),
body: _t("Customer firstname or lastname is required"),
});
}
this.changes.name = this._updatePartnerName(this.changes);
}
super.saveChanges();
},
_updatePartnerName({lastname, firstname}) {
let name = null;
if (!lastname) {
return firstname;
}
if (!firstname) {
return lastname;
}
if (this.partner_names_order === "last_first_comma") {
name = lastname + ", " + firstname;
} else if (this.partner_names_order === "first_last") {
name = firstname + " " + lastname;
} else {
name = lastname + " " + firstname;
}
return name.trim();
},
});
3 changes: 3 additions & 0 deletions pos_partner_firstname/static/src/app/PartnerDetailsEdit.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.partner_is_company {
width: 64px;
}
51 changes: 51 additions & 0 deletions pos_partner_firstname/static/src/app/PartnerDetailsEdit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates id="template" xml:space="preserve">

<t t-inherit="point_of_sale.PartnerDetailsEdit" t-inherit-mode="extension">
<xpath expr="//input[@name='name']" position="attributes">
<attribute name="t-att-readonly">!changes.is_company</attribute>
</xpath>
<xpath expr="//div[hasclass('partner-details-header')]" position="inside">
<img
t-attf-class="fa {{isCompanyIcon}} fa-4x partner_is_company"
t-on-click="toggleIsCompany"
/>
</xpath>

<xpath expr="//div[hasclass('partner-details-box')]/t" position="before">
<!--
<div class="partner-detail col">
<label class="form-label label" for="is_company">Is Company</label>
<input
type='checkbox'
class="detail form-control"
name='is_company'
t-att-checked="changes.is_company ? 'checked' : null"
t-model="changes.is_company"
/>
</div>
-->
<div class="partner-detail col" t-if="!changes.is_company">
<label class="form-label label" for="is_company">Lastname</label>
<input
class="detail form-control"
name="lastname"
t-model="changes.lastname"
t-att-value="changes.lastname || ''"
placeholder="Lastname"
/>
</div>
<div class="partner-detail col" t-if="!changes.is_company">
<label class="form-label label" for="is_company">Firstname</label>
<input
class="detail form-control"
name="firstname"
t-model="changes.firstname"
t-att-value="changes.firstname || ''"
placeholder="Firstname"
/>
</div>
</xpath>
</t>

</templates>
99 changes: 0 additions & 99 deletions pos_partner_firstname/static/src/js/PartnerDetailsEdit.js

This file was deleted.

20 changes: 0 additions & 20 deletions pos_partner_firstname/static/src/js/PartnerScreen.js

This file was deleted.

55 changes: 0 additions & 55 deletions pos_partner_firstname/static/src/xml/pos.xml

This file was deleted.

0 comments on commit 3ba9a89

Please sign in to comment.