Skip to content

Commit

Permalink
[ADD] l10n_ar_pos: New module l10n_ar_pos
Browse files Browse the repository at this point in the history
Inherit all the functionalities of Odoo POS and adapt to the Argentinean localization.
  • Loading branch information
bruno-zanotti committed Jun 4, 2021
1 parent 76c1506 commit 533f8c5
Show file tree
Hide file tree
Showing 13 changed files with 975 additions and 0 deletions.
3 changes: 3 additions & 0 deletions l10n_ar_pos/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from . import models
26 changes: 26 additions & 0 deletions l10n_ar_pos/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
{
'name': 'Argentinian Point of Sale',
'version': "1.0",
'description': "Adapt the Point of Sale to Argentinean localization.",
'author': 'ADHOC SA, Ing. Gabriela Rivero',
'category': 'Localization',
'depends': [
'l10n_ar_edi',
'point_of_sale',
],
'data': [
'views/assets_backend.xml',
'views/pos_config.xml',
],
'demo': [
],
'qweb': [
'static/src/xml/pos.xml',
'static/src/xml/xml_receipt.xml',
],
'installable': True,
'auto_install': False,
'application': False,
}
2 changes: 2 additions & 0 deletions l10n_ar_pos/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import res_partner
from . import pos_config
21 changes: 21 additions & 0 deletions l10n_ar_pos/models/pos_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
from odoo import fields, models, _


class pos_config(models.Model):

_inherit = "pos.config"

pos_auto_invoice = fields.Boolean(
'POS auto invoice',
help='POS auto to checked to invoice button',
default=True,
)
receipt_invoice_number = fields.Boolean(
'Receipt show invoice number',
default=True,
)
receipt_customer_vat = fields.Boolean(
'Receipt show customer VAT',
default=True,
)
15 changes: 15 additions & 0 deletions l10n_ar_pos/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# -*- coding: utf-8 -*-
from odoo import api, models


class ResPartner(models.Model):
_inherit = "res.partner"

# TODO: sin esto sale un error al guardar un nuevo cliente. Revisar.
@api.constrains('vat', 'l10n_latam_identification_type_id')
def check_vat(self):
type_id = int(self.l10n_latam_identification_type_id.id)
l10n_ar_partners = self.filtered(lambda self: self.env['l10n_latam.identification.type'].browse(type_id).l10n_ar_afip_code)
l10n_ar_partners.l10n_ar_identification_validation()
return super(ResPartner, self - l10n_ar_partners).check_vat()

Binary file added l10n_ar_pos/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions l10n_ar_pos/static/src/css/pos_receipts.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

.pos-receipt .pos-receipt-contact {
text-align: left;
font-size: 95%;
}
130 changes: 130 additions & 0 deletions l10n_ar_pos/static/src/js/models.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
odoo.define('l10n_ar_pos.models', function (require) {
"use strict";

var models = require('point_of_sale.models');

models.load_fields('res.partner', ['l10n_latam_identification_type_id', 'l10n_ar_afip_responsibility_type_id']);

models.load_models([
{
model: 'l10n_latam.identification.type',
label: "AFIP Identification Types",
fields: ['id', 'name'],
loaded: function (self, category_id) {
self.category_id = [];
for (var i in category_id){
self.category_id.push(category_id[i]);
}
},
},
{
model: 'l10n_ar.afip.responsibility.type',
label: "AFIP Responsibility Types",
fields: ['id', 'name'],
loaded: function (self, responsibility_type) {
self.responsibility_type = [];
for (var i in responsibility_type){
self.responsibility_type.push(responsibility_type[i]);
}
},
},
]);

var _super_order = models.Order.prototype;
models.Order = models.Order.extend({
initialize: function (attributes, options) {
_super_order.initialize.apply(this, arguments);
if (this.pos.config.pos_auto_invoice) {
this.to_invoice = true;
}
},
init_from_JSON: function (json) {
var res = _super_order.init_from_JSON.apply(this, arguments);
if (json.to_invoice) {
this.to_invoice = json.to_invoice;
}
}
});
// Este metodo es el mas importante para habilitar los campos que se necesitan usar
// por ejemplo "vat" fue sustituido por main_id_number
// En v13 se saca main_id_number y se empieza a usar vat

// esto quiere decir que agregamos funcionalidad (EXTEND)
// a traves de la var models

var _super_posmodel = models.PosModel.prototype;
models.PosModel = models.PosModel.extend({
initialize: function (session, attributes) {
var partner_model = _.find(this.models, function (model) {
return model.model === 'res.partner';
});

partner_model.fields.push('vat');
partner_model.fields.push('website');
partner_model.fields.push('l10n_ar_afip_responsibility_type_id');

_super_posmodel.initialize.apply(this, arguments);

},

push_and_invoice_order: function (order) {
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();
});

// on success, get the order id generated by the server
transfer.then(function(order_server_id){
// generate the pdf and download it
if (order_server_id.length && !order.is_to_email()) {
debugger;
self.chrome.do_action('point_of_sale.pos_invoice_report',{additional_context:{
active_ids:order_server_id,
}}).then(function () {
resolveInvoiced(order_server_id);
resolveDone();
}).guardedCatch(function (error) {
rejectInvoiced({code:401, message:'Backend Invoice', data:{order: order}});
rejectDone();
});
} else 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;
},

});

});
Loading

0 comments on commit 533f8c5

Please sign in to comment.