diff --git a/l10n_do_accounting_plus/__manifest__.py b/l10n_do_accounting_plus/__manifest__.py index 99418eefd..5be2e4b6f 100644 --- a/l10n_do_accounting_plus/__manifest__.py +++ b/l10n_do_accounting_plus/__manifest__.py @@ -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", diff --git a/l10n_do_accounting_plus/models/account_move.py b/l10n_do_accounting_plus/models/account_move.py index 0febd62bf..9b885421d 100644 --- a/l10n_do_accounting_plus/models/account_move.py +++ b/l10n_do_accounting_plus/models/account_move.py @@ -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 @@ -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 @@ -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() diff --git a/l10n_do_accounting_plus/models/res_company.py b/l10n_do_accounting_plus/models/res_company.py index db40a93ad..e986e4aaf 100644 --- a/l10n_do_accounting_plus/models/res_company.py +++ b/l10n_do_accounting_plus/models/res_company.py @@ -1,4 +1,5 @@ from odoo import fields, models +# from wsmovildgii import get_contribuyentes class ResCompany(models.Model): @@ -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)])) diff --git a/l10n_do_accounting_plus/models/res_config_setting.py b/l10n_do_accounting_plus/models/res_config_setting.py index d40fcb3f8..b237fdacc 100644 --- a/l10n_do_accounting_plus/models/res_config_setting.py +++ b/l10n_do_accounting_plus/models/res_config_setting.py @@ -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( @@ -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') + + 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') diff --git a/l10n_do_accounting_plus/views/account_move_views.xml b/l10n_do_accounting_plus/views/account_move_views.xml new file mode 100644 index 000000000..5e21fafc8 --- /dev/null +++ b/l10n_do_accounting_plus/views/account_move_views.xml @@ -0,0 +1,48 @@ + + + + account.invoice.select.inherit.plus + account.move + + + + + + + + + account.move.form.plus + account.move + + + + + + + + + + + + + Notice. This company is in a transient state of contingency for Electronic Invoice issuing. NCF + issuing has been enabled. + + + + + + + + + \ No newline at end of file diff --git a/l10n_do_accounting_plus/views/res_config_settings_view.xml b/l10n_do_accounting_plus/views/res_config_settings_view.xml index d0fd798db..2abcad1fd 100644 --- a/l10n_do_accounting_plus/views/res_config_settings_view.xml +++ b/l10n_do_accounting_plus/views/res_config_settings_view.xml @@ -1,16 +1,15 @@ - res.config.settings.view.form.inherited + res.config.settings.view.form.inherit.plus res.config.settings - + - - + + Dominican Localization - + @@ -22,12 +21,27 @@ + + + + + + + + + Diario de Venta para Generacion de Factura con Valor Fiscal. + + + + + + - + Habilitar la opcion de control de sequencia de comprobantes. @@ -60,8 +74,6 @@ -