Skip to content

Commit

Permalink
[IMP] account_ux: check date and invoice date in sale documents
Browse files Browse the repository at this point in the history
Task: 34851
Prevenir que en facturas de cliente queden distintos los campos de factura/recibo y fecha (date e invoice date). Pueden quedar distintos si se modifica alguna de esas fechas a través de edición masiva por ejemplo, entonces con esta constrains queremos prevenir que eso suceda.
  • Loading branch information
pablohmontenegro committed Nov 17, 2023
1 parent e51061a commit 08ad94c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions account_ux/i18n/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -507,3 +507,4 @@ msgstr ""
#: model_terms:ir.ui.view,arch_db:account_ux.view_account_change_currency
msgid "or"
msgstr "o"

10 changes: 10 additions & 0 deletions account_ux/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,13 @@ def _compute_currency_id(self):
""" Si la factura tenía currency_id no queremos cambiarla si cambia el diario """
invoices_with_currency_id = self.filtered(lambda x: x.currency_id)
return super(AccountMove, self - invoices_with_currency_id)._compute_currency_id()

@api.constrains('date', 'invoice_date')
def _check_dates_on_invoices(self):
""" Prevenir que en facturas de cliente queden distintos los campos de factura/recibo y fecha (date e invoice date). Pueden quedar distintos si se modifica alguna de esas fechas a través de edición masiva por ejemplo, entonces con esta constrains queremos prevenir que eso suceda. """
invoices_to_check = self.filtered(lambda x: x.date!=x.invoice_date if x.is_sale_document() and x.date and x.invoice_date else False)
if invoices_to_check:
error_msg = _('\nDate\t\t\tInvoice Date\t\tInvoice\n')
for rec in invoices_to_check:
error_msg += str(rec.date) + '\t'*2 + str(rec.invoice_date) + '\t'*3 + rec.display_name + '\n'
raise UserError(_('The date and invoice date of a sale invoice must be the same: %s') % (error_msg))

0 comments on commit 08ad94c

Please sign in to comment.