Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

14.0 mig l10n br pos nfce #151

Open
wants to merge 3 commits into
base: 14.0-mig-l10n_br_pos
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions l10n_br_pos/static/src/js/Screens/PaymentScreen/PaymentScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,20 @@ odoo.define("l10n_br_pos.PaymentScreen", function (require) {

async _isOrderValid(isForceValidate) {
var result = super._isOrderValid(isForceValidate);
var order = this.env.pos.get_order();
const valid_cpf_cnpj = this.check_valid_cpf_cnpj(order);
if (valid_cpf_cnpj) {
result = await order.document_send(this);
return result;
if (this.env.pos.config.simplified_document_type) {
var order = this.env.pos.get_order();
const valid_cpf_cnpj = this.check_valid_cpf_cnpj(order);
if (valid_cpf_cnpj) {
result = await order.document_send(this);
} else {
Gui.showPopup("ErrorPopup", {
title: _t("Invalid CNPJ / CPF !"),
body: _t("Enter a valid CNPJ / CPF number"),
});
}
}
Gui.showPopup("ErrorPopup", {
title: _t("Invalid CNPJ / CPF !"),
body: _t("Enter a valid CNPJ / CPF number"),
});

return result;
}
};

Expand Down
2 changes: 1 addition & 1 deletion l10n_br_pos/static/src/js/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,6 @@ odoo.define("l10n_br_pos.models", function (require) {
label: "Iniciando Processo de Transmissão",
});
this.state_edoc = SITUACAO_EDOC_A_ENVIAR;
this._document_status_popup();
var result = false;
var processor_result = null;
// Verifica se os campos do documento fiscal são válidos
Expand All @@ -393,6 +392,7 @@ odoo.define("l10n_br_pos.models", function (require) {
// Obtem o responsável pelo envio do documento fiscal;
var processor = await this._document_get_processor();
if (processor) {
this._document_status_popup();
// Efetivamente envia o documento fiscal
processor_result = await processor.send_order(this);
// Valida se foi emitido corretamente e salva os dados do resulto
Expand Down
1 change: 1 addition & 0 deletions l10n_br_pos_nfce/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
3 changes: 3 additions & 0 deletions l10n_br_pos_nfce/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
"maintainers": ["mileo", "sadamo", "gabrielcardoso21", "lfdivino"],
"depends": [
"l10n_br_pos",
"l10n_br_account_nfe",
],
"data": [
"views/pos_payment_method.xml",
"views/pos_template.xml",
"views/pos_config_view.xml",
],
"demo": [],
"installable": True,
Expand Down
3 changes: 3 additions & 0 deletions l10n_br_pos_nfce/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import pos_config
from . import pos_order
from . import pos_payment_method
13 changes: 13 additions & 0 deletions l10n_br_pos_nfce/models/pos_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (C) 2023 Renato Lima - Akretion <[email protected]>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from odoo import fields, models


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

nfce_document_serie_id = fields.Many2one(
string="Document Serie",
comodel_name="l10n_br_fiscal.document.serie",
)
85 changes: 85 additions & 0 deletions l10n_br_pos_nfce/models/pos_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Copyright (C) 2023 Renato Lima - Akretion <[email protected]>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from odoo import models


class PosOrder(models.Model):
_inherit = "pos.order"

def _prepare_invoice_vals(self):
vals = super(PosOrder, self)._prepare_invoice_vals()

pos_config_id = self.session_id.config_id
payment_mode_id = self.payment_ids[0].payment_method_id.payment_mode_id

vals.update(
{
"document_type_id": pos_config_id.simplified_document_type_id.id,
"fiscal_operation_id": pos_config_id.out_pos_fiscal_operation_id.id,
"ind_pres": "1",
"document_serie_id": pos_config_id.nfce_document_serie_id.id,
"partner_id": pos_config_id.partner_id.id,
"payment_mode_id": payment_mode_id.id,
}
)

return vals

def _generate_pos_order_invoice(self):
res = super(PosOrder, self)._generate_pos_order_invoice()

self.account_move.fiscal_document_id.action_document_confirm()

return res

def _prepare_invoice_line(self, order_line):
vals = super(PosOrder, self)._prepare_invoice_line(order_line)
pos_fiscal_map_ids = order_line.product_id.pos_fiscal_map_ids
fiscal_tax_ids = [
(
6,
0,
[
pos_fiscal_map_ids.icms_tax_id.id,
pos_fiscal_map_ids.ipi_tax_id.id,
pos_fiscal_map_ids.cofins_tax_id.id,
pos_fiscal_map_ids.pis_tax_id.id,
],
)
]
vals.update(
{
"product_uom_id": order_line.product_uom_id.id,
"fiscal_operation_id": pos_fiscal_map_ids.fiscal_operation_id.id,
"tax_icms_or_issqn": "icms",
"uom_id": order_line.product_id.uom_id.id,
"ncm_id": order_line.product_id.ncm_id.id,
"fiscal_operation_line_id": pos_fiscal_map_ids.fiscal_operation_line_id.id,
"cfop_id": pos_fiscal_map_ids.cfop_id.id,
"uot_id": pos_fiscal_map_ids.uot_id.id,
"fiscal_genre_id": order_line.product_id.fiscal_genre_id.id,
"icms_tax_id": pos_fiscal_map_ids.icms_tax_id.id,
"icms_cst_id": pos_fiscal_map_ids.icms_cst_id.id,
"icms_base": pos_fiscal_map_ids.icms_base,
"icms_percent": pos_fiscal_map_ids.icms_percent,
"icms_value": pos_fiscal_map_ids.icms_value,
"ipi_tax_id": pos_fiscal_map_ids.ipi_tax_id.id,
"ipi_cst_id": pos_fiscal_map_ids.ipi_cst_id.id,
"ipi_base": pos_fiscal_map_ids.ipi_base,
"ipi_percent": pos_fiscal_map_ids.ipi_percent,
"ipi_value": pos_fiscal_map_ids.ipi_value,
"cofins_tax_id": pos_fiscal_map_ids.cofins_tax_id.id,
"cofins_cst_id": pos_fiscal_map_ids.cofins_cst_id.id,
"cofins_base": pos_fiscal_map_ids.cofins_base,
"cofins_percent": pos_fiscal_map_ids.cofins_percent,
"cofins_value": pos_fiscal_map_ids.cofins_value,
"pis_tax_id": pos_fiscal_map_ids.pis_tax_id.id,
"pis_cst_id": pos_fiscal_map_ids.pis_cst_id.id,
"pis_base": pos_fiscal_map_ids.pis_base,
"pis_percent": pos_fiscal_map_ids.pis_percent,
"pis_value": pos_fiscal_map_ids.pis_value,
"fiscal_tax_ids": fiscal_tax_ids,
}
)
return vals
15 changes: 15 additions & 0 deletions l10n_br_pos_nfce/models/pos_payment_method.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2023 KMEE
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class PosPaymentMethod(models.Model):

_inherit = "pos.payment.method"

payment_mode_id = fields.Many2one(
comodel_name="account.payment.mode",
required=True,
string="NFe Account Payment Mode",
)
26 changes: 26 additions & 0 deletions l10n_br_pos_nfce/static/src/js/Screens/PaymentScreen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
Copyright (C) 2016-Today KMEE (https://kmee.com.br)
@author: Luis Felipe Mileo <[email protected]>
@author: Luiz Felipe do Divino <[email protected]>
@author: Gabriel Cardoso <[email protected]>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
*/

odoo.define("l10n_br_pos_nfce.PaymentScreen", function (require) {
"use strict";

const PaymentScreen = require("point_of_sale.PaymentScreen");
const Registries = require("point_of_sale.Registries");

const L10nBrPosNFCePaymentScreen = (PaymentScreen) =>
class extends PaymentScreen {
toggleIsToInvoice() {
if (!this.document_type === "65") {
super.toggleIsToInvoice();
}
}
};
Registries.Component.extend(PaymentScreen, L10nBrPosNFCePaymentScreen);

return L10nBrPosNFCePaymentScreen;
});
91 changes: 90 additions & 1 deletion l10n_br_pos_nfce/static/src/js/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,96 @@ Copyright (C) 2022-Today KMEE (https://kmee.com.br)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
*/

odoo.define("l10n_br_pos.models", function () {
odoo.define("l10n_br_pos_nfce.models", function (require) {
"use strict";

const models = require("point_of_sale.models");

var _super_order = models.Order.prototype;
models.Order = models.Order.extend({
initialize: function (attributes, options) {
// CORE METHODS
_super_order.initialize.apply(this, arguments, options);
if (this.document_type === "65") {
this.to_invoice = true;
}
},
async document_send(component) {
if (this.document_type !== "65") {
return _super_order.document_send.apply(this, arguments);
}
if (!this.get_client()) {
const anonimous_partner = this.pos.db.get_partner_by_id(
this.pos.config.partner_id[0]
);
this.set_client(anonimous_partner);
component.trigger("close-popup");
}

return true;
},
});

var _super_posmodel = models.PosModel.prototype;
models.PosModel = models.PosModel.extend({
push_and_invoice_order(order) {
if (!this.document_type === "65") {
return _super_posmodel.push_and_invoice_order.call(this);
}
var self = this;
var invoiced = new Promise(function (resolveInvoiced, rejectInvoiced) {
if (!order.get_client()) {
rejectInvoiced({
code: 400,
message: "Missing Customer",
data: {},
});
} else {
var order_id = self.db.add_order(order.export_as_JSON());

self.flush_mutex.exec(function () {
var done = new Promise(function (resolveDone, rejectDone) {
// Send the order to the server
// we have a 30 seconds timeout on this push.
// FIXME: if the server takes more than 30 seconds to accept the order,
// the client will believe it wasn't successfully sent, and very bad
// things will happen as a duplicate will be sent next time
// so we must make sure the server detects and ignores duplicated orders

var transfer = self._flush_orders(
[self.db.get_order(order_id)],
{timeout: 30000, to_invoice: true}
);

transfer.catch(function (error) {
rejectInvoiced(error);
rejectDone();
});

transfer.then(function (order_server_id) {
if (order_server_id.length) {
resolveInvoiced(order_server_id);
resolveDone();
} else {
// The order has been pushed separately in batch when
// the connection came back.
// The user has to go to the backend to print the invoice
rejectInvoiced({
code: 401,
message: "Backend Invoice",
data: {order: order},
});
rejectDone();
}
});

return done;
});
});
}
});

return invoiced;
},
});
});
15 changes: 15 additions & 0 deletions l10n_br_pos_nfce/views/pos_config_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<record id="view_pos_config_form" model="ir.ui.view">
<field name="name">pos.config.form (in l10n_br_pos_nfce)</field>
<field name="model">pos.config</field>
<field name="inherit_id" ref="l10n_br_pos.view_pos_config_form" />
<field name="arch" type="xml">
<xpath expr="//page[@name='l10n_br_nfce']/group" postition="inside">
<field name="nfce_document_serie_id" />
</xpath>
</field>
</record>

</odoo>
22 changes: 22 additions & 0 deletions l10n_br_pos_nfce/views/pos_payment_method.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2023 KMEE
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>

<record model="ir.ui.view" id="pos_payment_method_form_view">
<field name="name">pos.payment.method.form (in l10n_br_pos_nfce)</field>
<field name="model">pos.payment.method</field>
<field
name="inherit_id"
ref="l10n_br_pos.view_l10n_br_pos_pos_method_term_form"
/>
<field name="arch" type="xml">
<xpath expr="//group[@name='l10n_br_pos']">
<field name="payment_mode_id" />
</xpath>
</field>
</record>



</odoo>
4 changes: 4 additions & 0 deletions l10n_br_pos_nfce/views/pos_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
<script
src="/l10n_br_pos_nfce/static/src/js/screens.js"
type="text/javascript"
/>
<script
src="/l10n_br_pos_nfce/static/src/js/Screens/PaymentScreen.js"
type="text/javascript"
/>
</xpath>
</template>
Expand Down
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ nfelib
num2words
phonenumbers
pycep_correios
satcomum
pyyaml
satcomum
unidecode
vcrpy
workalendar
xmldiff