-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] l10n_ar_account_withholding: Wizard to ...
... upload padron ARBA closes #658 X-original-commit: f34ed9f Signed-off-by: Nacho Cainelli <ica@adhoc.com.ar> Signed-off-by: Nicolas Mac Rouillon <nmr@adhoc.com.ar>
- Loading branch information
Showing
7 changed files
with
208 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
l10n_ar_account_withholding/models/res_company_jurisdiction_padron.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
from odoo import models, fields, api, _ | ||
from odoo.exceptions import UserError, ValidationError | ||
from io import BytesIO | ||
import zipfile | ||
import tempfile | ||
import os | ||
import re | ||
import logging | ||
import base64 | ||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
class ResCompanyJurisdictionPadron(models.Model): | ||
_name = "res.company.jurisdiction.padron" | ||
_description = "res.company.jurisdiction.padron" | ||
|
||
company_id = fields.Many2one( | ||
"res.company", | ||
required=True, | ||
default=lambda self: self.env.company, | ||
) | ||
jurisdiction_id = fields.Many2one( | ||
"account.account.tag", | ||
domain="[('applicability', '=', 'taxes'),('jurisdiction_code', '!=', False)]", | ||
required=True, | ||
) | ||
|
||
file_padron = fields.Binary( | ||
"File", | ||
required=True, | ||
) | ||
l10n_ar_padron_from_date = fields.Date( | ||
"From Date", | ||
required=True, | ||
) | ||
l10n_ar_padron_to_date = fields.Date( | ||
"To Date", | ||
required=True, | ||
) | ||
|
||
@api.constrains('jurisdiction_id') | ||
def check_jurisdiction_id(self): | ||
arba_tag = self.env.ref('l10n_ar_ux.tag_tax_jurisdiccion_902') | ||
for rec in self: | ||
if rec.jurisdiction_id != arba_tag: | ||
raise ValidationError("El padron para (%s) no está implementado." % rec.jurisdiction_id.name) | ||
|
||
@api.depends('company_id', 'jurisdiction_id') | ||
def name_get(self): | ||
res = [] | ||
for padron in self: | ||
name = "%s: %s" % (padron.company_id.name, | ||
padron.jurisdiction_id.name) | ||
res += [(padron.id, name)] | ||
return res | ||
|
||
def descompress_file(self, file_padron): | ||
_logger.log(25, "Descompress zip file") | ||
ruta_extraccion = "/tmp" | ||
file = base64.decodestring(file_padron) | ||
fobj = tempfile.NamedTemporaryFile(delete=False) | ||
fname = fobj.name | ||
fobj.write(file) | ||
fobj.close() | ||
f = open(fname, 'r+b') | ||
data = f.read() | ||
f.write(base64.b64decode(file_padron)) | ||
with zipfile.ZipFile(f, 'r') as zip_file: | ||
zip_file.extractall(path=ruta_extraccion) | ||
zip_file.close() | ||
|
||
def find_aliquot(self, path, cuit): | ||
"""We try to find aliqut and number for a partner given | ||
""" | ||
with open(path, "r") as fp: | ||
aliq = False | ||
nro = False | ||
for line in fp.readlines(): | ||
values = line.split(";") | ||
if values[4] == cuit: | ||
aliq = values[8] | ||
nro = values[3] | ||
break | ||
return nro, aliq | ||
|
||
def find_file(self, rootdir, type_code): | ||
res = False | ||
date = str(self.l10n_ar_padron_from_date.month) + \ | ||
str(self.l10n_ar_padron_from_date.year) | ||
pattern = "%s.{1}|.TXT\Z" % type_code + date | ||
for subdir, dirs, files in os.walk(rootdir): | ||
for f in files: | ||
if re.search(pattern, f): | ||
res = f | ||
break | ||
return res | ||
|
||
def _get_aliquit(self, partner): | ||
padron_types = ["Per", "Ret"] | ||
nro = False | ||
aliquot_ret = 0.0 | ||
aliquot_per = 0.0 | ||
for padron_type in padron_types: | ||
path_file = self.find_file("/tmp/", padron_type) | ||
if not path_file: | ||
self.descompress_file(self.file_padron) | ||
path_file = self.find_file("/tmp/", padron_type) | ||
nro, aliquot = self.find_aliquot("/tmp/" + path_file, partner.vat) | ||
if padron_type == "Per": | ||
aliquot_per = aliquot and aliquot.replace(",", ".") | ||
else: | ||
aliquot_ret = aliquot and aliquot.replace(",", ".") | ||
return nro, aliquot_ret, aliquot_per |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
l10n_ar_account_withholding/views/res_company_jurisdiction_padron_view.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
|
||
<record model="ir.ui.view" id="view_res_company_jurisdiction_padron_tree"> | ||
<field name="name">res.company.jurisdiction.padron.tree.inherit</field> | ||
<field name="model">res.company.jurisdiction.padron</field> | ||
<field name="arch" type="xml"> | ||
<tree string="Padron Alicuotas"> | ||
<field name="jurisdiction_id"/> | ||
<field name="company_id"/> | ||
<field name="l10n_ar_padron_from_date"/> | ||
<field name="l10n_ar_padron_to_date"/> | ||
</tree> | ||
</field> | ||
</record> | ||
|
||
<record model="ir.ui.view" id="view_res_company_jurisdiction_padron_form"> | ||
<field name="name">res.company.jurisdiction.padron.form.inherit</field> | ||
<field name="model">res.company.jurisdiction.padron</field> | ||
<field name="arch" type="xml"> | ||
<form string="Padron Alicuotas"> | ||
<sheet> | ||
|
||
<group> | ||
<group> | ||
<field name="company_id"/> | ||
<field name="jurisdiction_id"/> | ||
<field name="file_padron"/> | ||
</group> | ||
<group> | ||
<field name="l10n_ar_padron_from_date"/> | ||
<field name="l10n_ar_padron_to_date"/> | ||
</group> | ||
</group> | ||
<p class="alert alert-info" role="alert" style="margin-bottom:0px;"> | ||
Padrones implementados: | ||
<ul> | ||
<li>ARBA: por lo general no es necesario cargarlo aquí ya que las alícuotas se obtienen automáticamente mediante webservice. | ||
Si igualmente desea cargarlo, debe subir el archivo zip que descarga de arba y que tiene nombre de forma "PadronRGSMMAAAA.zip | ||
</li> | ||
</ul> | ||
</p> | ||
</sheet> | ||
</form> | ||
</field> | ||
</record> | ||
|
||
<record model="ir.actions.act_window" id="act_company_jurisdiction_padron"> | ||
<field name="name">Padron Alicuotas</field> | ||
<field name="type">ir.actions.act_window</field> | ||
<field name="res_model">res.company.jurisdiction.padron</field> | ||
<field name="view_mode">tree,form</field> | ||
</record> | ||
|
||
<menuitem name="Padron de Alicuotas por compania" action="act_company_jurisdiction_padron" id="menu_action_company_jurisdiction_padron" sequence="100" parent="l10n_ar.menu_afip_config"/> | ||
|
||
</odoo> |