Skip to content

Commit

Permalink
[IMP] mejoras en el funcionamiento e integracion de la localizacion d…
Browse files Browse the repository at this point in the history
…ominicana con la localizacion plus.
  • Loading branch information
alexcape14 committed Nov 19, 2023
1 parent 2a7fe24 commit 9183260
Show file tree
Hide file tree
Showing 6 changed files with 231 additions and 137 deletions.
2 changes: 1 addition & 1 deletion l10n_do_accounting_plus/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"data": [
"views/account_fiscal_sequence.xml",
"views/account_journal_views.xml",
# "views/account_move_views.xml",
"views/account_move_views.xml",
"views/account_payment.xml",
# "views/res_company_views.xml",
"views/res_config_settings_view.xml",
Expand Down
272 changes: 147 additions & 125 deletions l10n_do_accounting_plus/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,39 @@ def call_name_type_fiscal(self):
for rec in self:
rec.fiscal_type_name = rec.l10n_latam_document_type_id.id

def get_invoice_payment_widget(self, invoice_id):
j = json.loads(invoice_id.invoice_payments_widget)
return j['content'] if j else []

def convert_to_fiscal_invoice(self):
for invoice in self:
if invoice.jounal_id.l10n_latam_use_documents:
print(invoice.state)
else:
payments = []
if invoice.journal_id.l10n_latam_use_documents:
raise ValidationError(
"This invoice is associated with a fiscal journal %s," % invoice.journal_id.name /
"you cannot convert it to fiscal again.")
"This invoice is associated with a fiscal journal %s you cannot convert it to fiscal again." % invoice.journal_id.name)
else:
if invoice.get_invoice_payment_widget(invoice):
for payment in invoice.get_invoice_payment_widget(invoice):
payments.append(payment['payment_id'])
print(payment)
invoice.button_cancel()
new_invoice = invoice.copy()
new_invoice.invoice_date = invoice.invoice_date
new_invoice.journal_id = invoice.company_id.fiscal_journal_sale
new_invoice.action_post()
action = self.env["ir.actions.actions"]._for_xml_id("account.action_move_journal_line")
action['views'] = [(self.env.ref('account.view_move_form').id, 'form')]
action['res_id'] = new_invoice.id
else:
invoice.button_cancel()
new_invoice = invoice.copy()
new_invoice.invoice_date = invoice.invoice_date
new_invoice.journal_id = invoice.company_id.fiscal_journal_sale
new_invoice.action_post()
action = self.env["ir.actions.actions"]._for_xml_id("account.action_move_journal_line")
action['views'] = [(self.env.ref('account.view_move_form').id, 'form')]
action['res_id'] = new_invoice.id
return action

def calculo_total_descontado(self):
total = 0
Expand All @@ -48,30 +73,30 @@ def calculo_total_descontado(self):
else:
self.total_descontado = 0.00

def action_post(self):
result = super(AccountMove, self).action_post()
control = self.env['ir.config_parameter'].sudo().get_param('l10n_dominicana.with_localization_control')
if control != 'False':
limit_date = self.env['ir.config_parameter'].sudo().get_param(
'l10n_dominicana.expiration_date_localization')
for rec in self:
latam_use = rec.journal_id.l10n_latam_use_documents
if latam_use:
actual_date = fields.Date.today()
expiration_date = datetime.strptime(limit_date, '%Y-%m-%d').date()
if actual_date > expiration_date:
raise ValidationError(
_(
"Please Contact the Administrator, "
"The Dominican Localization Plan is Expired"
)
)
if self.partner_id:
invoice_totals = json.loads(self.tax_totals_json)
if invoice_totals['amount_total'] == 0.0:
raise ValidationError(
"Para confirmar la factura debe ser mayor que %s" % invoice_totals['amount_total'])
return result
# def action_post(self):
# result = super(AccountMove, self).action_post()
# control = self.env['ir.config_parameter'].sudo().get_param('l10n_dominicana.with_localization_control')
# if control != 'False':
# limit_date = self.env['ir.config_parameter'].sudo().get_param(
# 'l10n_dominicana.expiration_date_localization')
# for rec in self:
# latam_use = rec.journal_id.l10n_latam_use_documents
# if latam_use:
# actual_date = fields.Date.today()
# expiration_date = datetime.strptime(limit_date, '%Y-%m-%d').date()
# if actual_date > expiration_date:
# raise ValidationError(
# _(
# "Please Contact the Administrator, "
# "The Dominican Localization Plan is Expired"
# )
# )
# if self.partner_id:
# invoice_totals = json.loads(self.tax_totals_json)
# if invoice_totals['amount_total'] == 0.0:
# raise ValidationError(
# "Para confirmar la factura debe ser mayor que %s" % invoice_totals['amount_total'])
# return result

def get_received_delivered(self):
self.received_delivered = False
Expand All @@ -88,99 +113,96 @@ def get_received_delivered(self):
self.label_report_one = params_label_one.value
self.label_report_two = params_label_two.value

def _get_sequence_format_param(self, previous):

if not self._context.get("is_l10n_do_seq", False):
return super(AccountMove, self)._get_sequence_format_param(previous)

regex = self._l10n_do_sequence_fixed_regex

format_values = re.match(regex, previous).groupdict()
format_values["seq_length"] = len(format_values["seq"])
format_values["seq"] = int(format_values.get("seq") or 0)
if self.l10n_do_fiscal_number:
format_fiscal_number = re.match(regex, self.l10n_do_fiscal_number).groupdict()
if self.l10n_latam_document_type_id.doc_code_prefix != format_fiscal_number["prefix1"]:
raise ValidationError(_("You can't change the document type, please verify your selections"))

placeholders = re.findall(r"(prefix\d|seq\d?)", regex)
format = "".join(
"{seq:0{seq_length}d}" if s == "seq" else "{%s}" % s for s in placeholders
)
return format, format_values

def _set_next_sequence(self):
self.ensure_one()

if not self._context.get("is_l10n_do_seq", False):
return super(AccountMove, self)._set_next_sequence()

last_sequence = self._get_last_sequence()
new = not last_sequence
if new:
last_sequence = (
self._get_last_sequence(relaxed=True) or self._get_starting_sequence()
)

format, format_values = self._get_sequence_format_param(last_sequence)
if new:
format_values["seq"] = 0
format_values["seq"] = format_values["seq"] + 1

if self.company_id.l10n_do_fiscal_sequence_control:
if self.state != "draft" and not self[self._l10n_do_sequence_field]:
for inv in self:
new_seq = format_values["seq"]
doc_type = self.env['account.fiscal.sequence'].search(
[('document_type', '=', inv.l10n_latam_document_type_id.id)])

limit_set = int(doc_type.l10n_do_limit_vouchers)
warning_seq = int(doc_type.l10n_do_warning_vouchers)
if new_seq == warning_seq:
inv.notification_warning_seq()
elif new_seq > limit_set:
raise ValidationError(
_("Fiscal invoices sequence is not available, please contact the Administrator"))

if (
self.env.context.get("prefetch_seq")
or self.state != "draft"
and not self[self._l10n_do_sequence_field]
):
self[
self._l10n_do_sequence_field
] = self.l10n_latam_document_type_id._format_document_number(
format.format(**format_values)
)
self._compute_split_sequence()

@api.onchange("l10n_latam_document_type_id", "l10n_latam_document_number")
def _inverse_l10n_latam_document_number(self):
for con in self:
if con.move_type != 'entry':
con.ref = con.l10n_latam_document_number
for rec in self.filtered("l10n_latam_document_type_id"):
if not rec.l10n_latam_document_number:
rec.l10n_do_fiscal_number = ""
else:
document_type_id = rec.l10n_latam_document_type_id
if self.fiscal_type_name == str(document_type_id.id) or self.name == "/":
if document_type_id.l10n_do_ncf_type:
document_number = document_type_id._format_document_number(
rec.l10n_latam_document_number
)
else:
document_number = rec.l10n_latam_document_number

if rec.l10n_latam_document_number != document_number:
rec.l10n_latam_document_number = document_number
rec.l10n_do_fiscal_number = document_number
else:
self.l10n_latam_document_number = ""
self.fiscal_type_name = self.l10n_latam_document_type_id.id
super(
AccountMove, self.filtered(lambda m: m.country_code != "DO")
)._inverse_l10n_latam_document_number()



# def _get_sequence_format_param(self, previous):
#
# if not self._context.get("is_l10n_do_seq", False):
# return super(AccountMove, self)._get_sequence_format_param(previous)
#
# regex = self._l10n_do_sequence_fixed_regex
#
# format_values = re.match(regex, previous).groupdict()
# format_values["seq_length"] = len(format_values["seq"])
# format_values["seq"] = int(format_values.get("seq") or 0)
# if self.l10n_do_fiscal_number:
# format_fiscal_number = re.match(regex, self.l10n_do_fiscal_number).groupdict()
# if self.l10n_latam_document_type_id.doc_code_prefix != format_fiscal_number["prefix1"]:
# raise ValidationError(_("You can't change the document type, please verify your selections"))
#
# placeholders = re.findall(r"(prefix\d|seq\d?)", regex)
# format = "".join(
# "{seq:0{seq_length}d}" if s == "seq" else "{%s}" % s for s in placeholders
# )
# return format, format_values
#
# def _set_next_sequence(self):
# self.ensure_one()
#
# if not self._context.get("is_l10n_do_seq", False):
# return super(AccountMove, self)._set_next_sequence()
#
# last_sequence = self._get_last_sequence()
# new = not last_sequence
# if new:
# last_sequence = (
# self._get_last_sequence(relaxed=True) or self._get_starting_sequence()
# )
#
# format, format_values = self._get_sequence_format_param(last_sequence)
# if new:
# format_values["seq"] = 0
# format_values["seq"] = format_values["seq"] + 1
#
# if self.company_id.l10n_do_fiscal_sequence_control:
# if self.state != "draft" and not self[self._l10n_do_sequence_field]:
# for inv in self:
# new_seq = format_values["seq"]
# doc_type = self.env['account.fiscal.sequence'].search(
# [('document_type', '=', inv.l10n_latam_document_type_id.id)])
#
# limit_set = int(doc_type.l10n_do_limit_vouchers)
# warning_seq = int(doc_type.l10n_do_warning_vouchers)
# if new_seq == warning_seq:
# inv.notification_warning_seq()
# elif new_seq > limit_set:
# raise ValidationError(
# _("Fiscal invoices sequence is not available, please contact the Administrator"))
#
# if (
# self.env.context.get("prefetch_seq")
# or self.state != "draft"
# and not self[self._l10n_do_sequence_field]
# ):
# self[
# self._l10n_do_sequence_field
# ] = self.l10n_latam_document_type_id._format_document_number(
# format.format(**format_values)
# )
# self._compute_split_sequence()
#
# @api.onchange("l10n_latam_document_type_id", "l10n_latam_document_number")
# def _inverse_l10n_latam_document_number(self):
# for con in self:
# if con.move_type != 'entry':
# con.ref = con.l10n_latam_document_number
# for rec in self.filtered("l10n_latam_document_type_id"):
# if not rec.l10n_latam_document_number:
# rec.l10n_do_fiscal_number = ""
# else:
# document_type_id = rec.l10n_latam_document_type_id
# if self.fiscal_type_name == str(document_type_id.id) or self.name == "/":
# if document_type_id.l10n_do_ncf_type:
# document_number = document_type_id._format_document_number(
# rec.l10n_latam_document_number
# )
# else:
# document_number = rec.l10n_latam_document_number
#
# if rec.l10n_latam_document_number != document_number:
# rec.l10n_latam_document_number = document_number
# rec.l10n_do_fiscal_number = document_number
# else:
# self.l10n_latam_document_number = ""
# self.fiscal_type_name = self.l10n_latam_document_type_id.id
# super(
# AccountMove, self.filtered(lambda m: m.country_code != "DO")
# )._inverse_l10n_latam_document_number()
7 changes: 5 additions & 2 deletions l10n_do_accounting_plus/models/res_company.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from odoo import fields, models
# from wsmovildgii import get_contribuyentes


class ResCompany(models.Model):
Expand All @@ -7,5 +8,7 @@ class ResCompany(models.Model):
financial_currency = fields.Boolean(string='Financial Currency')
manual_change_currency = fields.Boolean(string='Manual Change Currency')
date_equal_to_invoice_retention = fields.Boolean(string='Date Retention Equal to Date Invoice')
l10n_do_fiscal_sequence_control = fields.Boolean(string='Activate Fiscal Sequence Control')

l10n_do_fiscal_sequence_control = fields.Boolean(string='Activate Fiscal Sequence Control', readonly=False)
fiscal_journal_sale = fields.Many2one(comodel_name='account.journal',
domain=([('type', '=', 'sale'),
('l10n_latam_use_documents', '=', True)]))
9 changes: 9 additions & 0 deletions l10n_do_accounting_plus/models/res_config_setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class ResConfigSettings(models.TransientModel):

l10n_do_fiscal_sequence_control = fields.Boolean(
string='Activate Fiscal Sequence Control',
readonly=False,
related='company_id.l10n_do_fiscal_sequence_control')

view_discount_in_account = fields.Boolean(
Expand All @@ -35,3 +36,11 @@ class ResConfigSettings(models.TransientModel):
label_one_report_2 = fields.Char(
string='Show name in report label right',
config_parameter='l10n_do_accounting.label_one_report_2')

Check warning on line 39 in l10n_do_accounting_plus/models/res_config_setting.py

View workflow job for this annotation

GitHub Actions / flake8

blank line contains whitespace
fiscal_journal_sale = fields.Many2one(
comodel_name='account.journal',
domain=([('type', '=', 'sale'),
('l10n_latam_use_documents', '=', True)]),
readonly=False,
related='company_id.fiscal_journal_sale',
string='Fiscal_journal_sale')
48 changes: 48 additions & 0 deletions l10n_do_accounting_plus/views/account_move_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_account_invoice_filter_inherit" model="ir.ui.view">
<field name="name">account.invoice.select.inherit.plus</field>
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_account_invoice_filter"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='name']" position="after">
<field name="l10n_do_fiscal_number"/>
</xpath>
</field>
</record>
<record id="view_move_form_plus" model="ir.ui.view">
<field name="name">account.move.form.plus</field>
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_move_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='partner_id']" position="after">
<field name="fiscal_type_name" invisible="1"/>
<field name="total_descontado" invisible="1"/>
<field name="total_without_discount" invisible="1"/>
<field name="received_delivered" invisible="1"/>
<field name="label_report_one" invisible="1"/>
<field name="label_report_two" invisible="1"/>
</xpath>
<xpath expr="//field[@name='tax_lock_date_message']/.." position="after">
<div class="alert alert-warning"
role="alert" style="margin-bottom:0px;"
attrs="{'invisible': ['|', '|', '|',
('move_type', '=', 'entry'),
('country_code', '!=', 'DO'),
('l10n_do_company_in_contingency', '=', False),
('state', '!=', 'draft')]}">
Notice. This company is in a transient state of contingency for Electronic Invoice issuing. NCF
issuing has been enabled.
</div>
</xpath>
<!-- TODO no esta aplicando bien los atributos de invisible-->
<xpath expr="//button[@name='button_draft']" position="after">
<button name="convert_to_fiscal_invoice" type="object" string="Convert To Fiscal"
attrs="{'invisible': ['|', '|',
('state', 'in', ('draft', 'cancel')),
('move_type', '!=', 'out_invoice'),
('l10n_latam_use_documents', '=', True)]}"/>
</xpath>
</field>
</record>
</odoo>
Loading

0 comments on commit 9183260

Please sign in to comment.