Skip to content

Commit

Permalink
[IMP] Add new module l10n_ar_pos
Browse files Browse the repository at this point in the history
  • Loading branch information
maq-adhoc committed May 6, 2024
1 parent 07a5090 commit 4cefeee
Show file tree
Hide file tree
Showing 13 changed files with 281 additions and 0 deletions.
2 changes: 2 additions & 0 deletions l10n_ar_pos/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
from . import models
29 changes: 29 additions & 0 deletions l10n_ar_pos/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
{
'name': 'Argentinean - Point of Sale with AR Doc',
'version': '1.0',
'category': 'Accounting/Localizations/Point of Sale',
'description': """
This module brings the technical requirement for the Argentinean regulation.
Install this if you are using the Point of Sale app in Argentina.
""",
'depends': [
'l10n_ar',
'point_of_sale',
],
'demo': [
'demo/point_of_sale_demo.xml'
],
'data': [
#'views/templates.xml',
],
'assets': {
'point_of_sale.assets': [
'l10n_ar_pos/static/src/**/*'
],
},
'installable': True,
'auto_install': True,
'license': 'LGPL-3',
}
9 changes: 9 additions & 0 deletions l10n_ar_pos/demo/point_of_sale_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<record model="pos.config" context="{'allowed_company_ids': [ref('l10n_ar.company_ri')]}" id="pos_config_l10n_ar">
<field name="name">Shop Argentina</field>
</record>
<function model="pos.config" name="post_install_pos_localisation" />
</data>
</odoo>
4 changes: 4 additions & 0 deletions l10n_ar_pos/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
from . import pos_session
from . import pos_order
from . import res_partner
22 changes: 22 additions & 0 deletions l10n_ar_pos/models/pos_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from odoo import models, fields, api, _
from odoo.exceptions import UserError
import base64


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

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

invoice_ids = self.refunded_order_ids.mapped("account_move").filtered(
lambda x: x.company_id.country_id.code == "AR"
and x.is_invoice()
and x.move_type in ["out_invoice"]
)
if len(invoice_ids) > 1:
raise UserError(_("Only can refund one invoice at a time"))

elif len(invoice_ids) == 1:
vals["reversed_entry_id"] = invoice_ids[0].id
return vals
54 changes: 54 additions & 0 deletions l10n_ar_pos/models/pos_session.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# -*- coding: utf-8 -*-
from odoo import models, api


class PosSession(models.Model):

_inherit = 'pos.session'


def _loader_params_res_company(self):
params = super()._loader_params_res_company()
if self.company_id.country_code == 'AR':
params['search_params']['fields'] += ['l10n_ar_gross_income_number', 'l10n_ar_gross_income_type','l10n_ar_afip_responsibility_type_id',
'l10n_ar_company_requires_vat','l10n_ar_afip_start_date']
return params

def _loader_params_res_partner(self):
params = super()._loader_params_res_partner()
if self.company_id.country_code == 'AR':
params['search_params']['fields'] += ['l10n_ar_afip_responsibility_type_id', 'l10n_latam_identification_type_id']
return params

def _pos_data_process(self, loaded_data):
super()._pos_data_process(loaded_data)
if self.company_id.country_code == 'AR':
loaded_data['consumidor_final_anonimo_id'] = self.env.ref('l10n_ar.par_cfa').id

@api.model
def _pos_ui_models_to_load(self):
models_to_load = super()._pos_ui_models_to_load()
models_to_load += ['l10n_ar.afip.responsibility.type','l10n_latam.identification.type']
return models_to_load

def _get_pos_ui_l10n_ar_afip_responsibility_type(self, params):
return self.env['l10n_ar.afip.responsibility.type'].search_read(**params['search_params'])

def _loader_params_l10n_ar_afip_responsibility_type(self):
return {
'search_params': {
'domain': [],
'fields': ['name', 'code'],
},
}

def _get_pos_ui_l10n_latam_identification_type(self, params):
return self.env['l10n_latam.identification.type'].search_read(**params['search_params'])

def _loader_params_l10n_latam_identification_type(self):
return {
'search_params': {
'domain': [('l10n_ar_afip_code', '!=', False), ('active', '=', True)],
'fields': ['name']
},
}
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 models, api, _
from odoo.exceptions import UserError


class ResPartner(models.Model):

_inherit = 'res.partner'

@api.ondelete(at_uninstall=False)
def _ar_unlink_except_master_data(self):
consumidor_final_anonimo = self.env.ref('l10n_ar.par_cfa').id
for partner in self.ids:
if partner == consumidor_final_anonimo:
raise UserError(_('Deleting this partner is not allowed.'))
19 changes: 19 additions & 0 deletions l10n_ar_pos/static/src/js/PartnerDetailsEdit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
odoo.define("l10n_ar_pos.PartnerDetailsEdit", function (require) {
"use strict";
const PartnerDetailsEdit = require("point_of_sale.PartnerDetailsEdit");
const { patch } = require("web.utils");

patch(PartnerDetailsEdit.prototype, "l10n_ar_pos", {
setup() {
this._super(...arguments);
if (this.env.pos.isArgentineanCompany()) {
const partner = this.props.partner;
this.intFields.push("l10n_ar_afip_responsibility_type_id");
this.intFields.push("l10n_latam_identification_type_id");
this.changes.l10n_ar_afip_responsibility_type_id = partner.l10n_ar_afip_responsibility_type_id && partner.l10n_ar_afip_responsibility_type_id[0];
this.changes.l10n_latam_identification_type_id = partner.l10n_latam_identification_type_id && partner.l10n_latam_identification_type_id[0];
}
},
});

});
35 changes: 35 additions & 0 deletions l10n_ar_pos/static/src/js/models.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
odoo.define('l10n_ar_pos.models', function (require) {
"use strict";

var { PosGlobalState, Order } = require('point_of_sale.models');
const Registries = require('point_of_sale.Registries');


const PosL10nArPosGlobalState = (PosGlobalState) => class PosL10nArPosGlobalState extends PosGlobalState {
async _processData(loadedData) {
await super._processData(...arguments);
this.consumidorFinalAnonimoId = loadedData['consumidor_final_anonimo_id'];
this.l10n_ar_afip_responsibility_type = loadedData['l10n_ar.afip.responsibility.type'];
this.l10n_latam_identification_type = loadedData['l10n_latam.identification.type'];
}
isArgentineanCompany(){
return this.company.country.code === 'AR';
}
}
Registries.Model.extend(PosGlobalState, PosL10nArPosGlobalState);

const L10nARPosOrder = (Order) => class L10nARPosOrder extends Order {
constructor(obj, options) {
super(...arguments);
if (!options.json && this.pos.isArgentineanCompany()) {
if (this.pos.isArgentineanCompany()) {
if (!this.partner) {
this.partner = this.pos.db.partner_by_id[this.pos.consumidorFinalAnonimoId];
}
}
}
}
}
Registries.Model.extend(Order, L10nARPosOrder);

});
31 changes: 31 additions & 0 deletions l10n_ar_pos/static/src/xml/PartnerDetailsEdit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-name="PartnerDetailsEdit" t-inherit="point_of_sale.PartnerDetailsEdit" owl="1" t-inherit-mode="extension">
<xpath expr="//div[hasclass('partner-details-right')]" position="inside">
<t t-if="env.pos.isArgentineanCompany()">
<div class="partner-detail">
<label class="label" for="art">AFIP Responsibility</label>
<select class="detail" t-model="changes.l10n_ar_afip_responsibility_type_id" name="l10n_ar_afip_responsibility_type_id" id="art"
t-on-change="captureChange">
<t t-foreach="env.pos.l10n_ar_afip_responsibility_type" t-as="afip_responsibility" t-key="afip_responsibility.id">
<option t-att-value="afip_responsibility.id">
<t t-esc="afip_responsibility.name" />
</option>
</t>
</select>
</div>
<div class="partner-detail">
<label class="label" for="id_type">Identification Type</label>
<select class="detail" t-model="changes.l10n_latam_identification_type_id" name="l10n_latam_identification_type_id" id="id_type"
t-on-change="captureChange">
<t t-foreach="env.pos.l10n_latam_identification_type" t-as="l10n_latam_identification_type" t-key="l10n_latam_identification_type.id">
<option t-att-value="l10n_latam_identification_type.id">
<t t-esc="l10n_latam_identification_type.name" />
</option>
</t>
</select>
</div>
</t>
</xpath>
</t>
</templates>
16 changes: 16 additions & 0 deletions l10n_ar_pos/static/src/xml/PartnerLine.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">

<t t-name="PartnerLine" t-inherit="point_of_sale.PartnerLine" owl="1">
<div class="company-field" position="after">
<t t-if="env.pos.isArgentineanCompany()">
<div class="afip-field">
<t t-esc="props.partner.l10n_ar_afip_responsibility_type_id[1] or ''" />
</div>
<div class="vat-field">
<t t-esc="props.partner.l10n_latam_identification_type_id[1] or ''" />
<t t-esc="props.partner.vat or ''" />
</div>
</t>
</div>
</t>
18 changes: 18 additions & 0 deletions l10n_ar_pos/static/src/xml/templates.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-inherit="point_of_sale.OrderReceipt" t-inherit-mode="extension" owl="1">
<xpath expr="//div[hasclass('pos-receipt-contact')]/t[@t-if='receipt.company.vat']" position="after">
<t t-if="receipt.company.l10n_ar_afip_responsibility_type_id">
<div>
<t t-esc="receipt.company.l10n_ar_afip_responsibility_type_id[1]" />
</div>
</t>
<div>IBB: <t t-esc="receipt.company.l10n_ar_gross_income_number" />
<t t-esc="receipt.company.l10n_ar_gross_income_type" />
</div>
<div>Inicio actividades: <t t-esc="receipt.company.l10n_ar_afip_start_date" />
</div>

</xpath>
</t>
</templates>
27 changes: 27 additions & 0 deletions l10n_ar_pos/template.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<template id="ticket_validation_screen" inherit_id="point_of_sale.ticket_validation_screen">

<!-- We do not let the user create the invoice by then self. That is why we hide the "Get my Invoice" button -->
<xpath expr="//div[@id='get_my_invoice']" position="attributes">
<attribute name="t-if">pos_order.company_id.country_code != 'AR'</attribute>
</xpath>
<xpath expr="//div[@id='get_my_invoice']/.." position="after">
<h4 class="text-danger" t-if="pos_order.company_id.country_code == 'AR' and not pos_order.is_invoiced">Invoice not available. You can contact us for more info</h4>
</xpath>

<!-- If the user is NOT log in we should hide the partner form, this one lost functionality because the get my invoice button is not shown and then the partner info is never save. In they want they can sign up and fill data from there -->
<xpath expr="//div[hasclass('o_portal_details')]" position="attributes">
<attribute name="t-if">pos_order.company_id.country_code != 'AR'</attribute>
</xpath>
<xpath expr="//div[@id='get_info_div']" position="attributes">
<attribute name="t-if">pos_order.company_id.country_code != 'AR'</attribute>
</xpath>
<xpath expr="//div[@id='get_info_div']" position="after">
<t t-else="">
<h4> Please
<a role="button" t-att-href="'/web/login?redirect=/pos/ticket/validate?access_token=%s' % access_token" style="margin-top: -11px"> Sign in</a>
in order to save your contact info</h4>
</t>
</xpath>

</template>

0 comments on commit 4cefeee

Please sign in to comment.