Skip to content

Instantly share code, notes, and snippets.

@celm1990
Created July 5, 2023 17:49
Show Gist options
  • Select an option

  • Save celm1990/fcf25df367ccc2bb0cbcf34230f51665 to your computer and use it in GitHub Desktop.

Select an option

Save celm1990/fcf25df367ccc2bb0cbcf34230f51665 to your computer and use it in GitHub Desktop.
l10n_latam_pos(JS)
odoo.define("l10n_latam_pos.DocumentTypeButton", function (require) {
"use strict";
const PosComponent = require("point_of_sale.PosComponent");
const ProductScreen = require("point_of_sale.ProductScreen");
const {useListener} = require("@web/core/utils/hooks");
const Registries = require("point_of_sale.Registries");
class DocumentTypeButton extends PosComponent {
setup() {
super.setup();
useListener("click", this.onClick);
}
async onClick() {
const l10n_latam_document_type =
this.env.pos.get_l10n_latam_document_type();
const documentTypeList = this.env.pos.l10n_latam_document_types.map(
(document_type) => {
return {
id: document_type.id,
item: document_type,
label: document_type.name,
isSelected: l10n_latam_document_type
? l10n_latam_document_type.id === document_type.id
: false,
};
}
);
const {confirmed, payload: document_type} = await this.showPopup(
"SelectionPopup",
{
title: this.env._t("Tipo de documento"),
list: documentTypeList,
}
);
if (!confirmed) {
return;
}
if (document_type) {
this.env.pos.set_l10n_latam_document_type(document_type);
}
return document_type;
}
}
DocumentTypeButton.template = "DocumentTypeButton";
ProductScreen.addControlButton({
component: DocumentTypeButton,
condition: function () {
return this.env.pos.config.l10n_latam_document_type_ids.length;
},
});
Registries.Component.add(DocumentTypeButton);
return DocumentTypeButton;
});
<?xml version="1.0" encoding="UTF-8" ?>
<templates id="template" xml:space="preserve">
<t t-name="DocumentTypeButton" owl="1">
<div class="control-button">
<i class="fa fa-list" />
<t t-if="env.pos.get_l10n_latam_document_type()">
<t t-esc="env.pos.get_l10n_latam_document_type().name" />
</t>
<t t-else="">
Document Type
</t>
</div>
</t>
</templates>
odoo.define("l10n_latam_pos.document_types", function (require) {
"use strict";
var {PosGlobalState, Order} = require("point_of_sale.models");
const Registries = require("point_of_sale.Registries");
const PosClPosGlobalState = (PosGlobalState) =>
class PosClPosGlobalState extends PosGlobalState {
async _processData(loadedData) {
await super._processData(...arguments);
this.l10n_latam_identification_types =
loadedData["l10n_latam.identification.type"];
if (this.config.l10n_latam_document_type_ids.length) {
this.l10n_latam_document_types =
loadedData["l10n_latam.document.type"];
this.l10n_latam_document_type_by_id =
loadedData.l10n_latam_document_type_by_id;
}
}
set_l10n_latam_document_type(l10n_latam_document_type) {
this.l10n_latam_document_type = l10n_latam_document_type;
const selectedOrder = this.get_order();
if (selectedOrder) {
selectedOrder.l10n_latam_document_type = l10n_latam_document_type;
}
}
get_l10n_latam_document_type() {
let l10n_latam_document_type = {};
const selectedOrder = this.get_order();
if (selectedOrder) {
l10n_latam_document_type = selectedOrder.l10n_latam_document_type;
}
return l10n_latam_document_type;
}
};
Registries.Model.extend(PosGlobalState, PosClPosGlobalState);
const PosOrder = (Order) =>
class PosOrder extends Order {
constructor(obj, options) {
super(obj, options);
if (this.pos.config.l10n_latam_document_type_id) {
this.setup_latam_document_type(
this.pos.config.l10n_latam_document_type_id[0]
);
}
}
setup_latam_document_type(latam_document_type_id) {
this.l10n_latam_document_type =
this.pos.l10n_latam_document_type_by_id[latam_document_type_id];
}
init_from_JSON(json) {
super.init_from_JSON(...arguments);
if (
this.pos.config.l10n_latam_document_type_ids.length &&
json.l10n_latam_document_type_id
) {
this.l10n_latam_document_type =
this.pos.l10n_latam_document_type_by_id[
json.l10n_latam_document_type_id
];
}
}
export_as_JSON() {
const json = super.export_as_JSON(...arguments);
if (this.pos.config.l10n_latam_document_type_ids.length) {
json.l10n_latam_document_type_id = this.l10n_latam_document_type
? this.l10n_latam_document_type.id
: false;
}
return json;
}
};
Registries.Model.extend(Order, PosOrder);
});
<?xml version="1.0" encoding="UTF-8" ?>
<templates id="template" xml:space="preserve">
<t
t-name="TicketScreen"
t-inherit="point_of_sale.TicketScreen"
t-inherit-mode="extension"
owl="1"
>
<xpath
expr="//div[hasclass('header-row')]//div[position() = 1]"
position="before"
>
<div class="col wide">Tipo Doc.</div>
</xpath>
<xpath
expr="//div[hasclass('order-row')]//div[position() = 1]"
position="before"
>
<div class="col">
<div t-if="env.isMobile">Tipo Doc.</div>
<div><t t-esc="getL10nLatamDocumentType(order)" /></div>
</div>
</xpath>
</t>
</templates>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment