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 13, 2023
1 parent e51061a commit de64ecc
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions account_ux/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,10 @@ 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.move_type in ('out_invoice', 'out_refund', 'out_receipt') and x.date!=x.invoice_date if x.date and x.invoice_date else False)
if invoices_to_check:
raise UserError(_(('The date and invoice date of a sale invoice must be the same: %s') % (', '.join(invoices_to_check.mapped('name')))))

0 comments on commit de64ecc

Please sign in to comment.