Merge pull request #20864 from thomas-Ngr/develop_fix_allow_modify_validated_draft_invoice

allow to modify invoices that have been validated in the past
This commit is contained in:
Laurent Destailleur 2022-05-16 21:02:53 +02:00 committed by GitHub
commit fe7483ccce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 4 deletions

View File

@ -305,7 +305,7 @@ if (empty($reshook)) {
$object->fetch($id);
if (!empty($conf->global-> INVOICE_CHECK_POSTERIOR_DATE)) {
$last_of_type = $object->willBeLastOfSameType();
$last_of_type = $object->willBeLastOfSameType(true);
if (empty($object->date_validation) && !$last_of_type[0]) {
setEventMessages($langs->transnoentities("ErrorInvoiceIsNotLastOfSameType", $object->ref, dol_print_date($object->date, 'day'), dol_print_date($last_of_type[1], 'day')), null, 'errors');
$action = '';

View File

@ -3009,7 +3009,7 @@ class Facture extends CommonInvoice
return -1;
}
if (!empty($conf->global-> INVOICE_CHECK_POSTERIOR_DATE)) {
$last_of_type = $this->willBeLastOfSameType();
$last_of_type = $this->willBeLastOfSameType(true);
if (!$last_of_type[0]) {
$this->error = $langs->transnoentities("ErrorInvoiceIsNotLastOfSameType", $this->ref, dol_print_date($this->date, 'day'), dol_print_date($last_of_type[1], 'day'));
return -1;
@ -5567,9 +5567,10 @@ class Facture extends CommonInvoice
/**
* See if current invoice date is posterior to the last invoice date among validated invoices of same type.
* @param boolean $allow_validated_drafts return true if the invoice has been validated before returning to DRAFT state.
* @return boolean
*/
public function willBeLastOfSameType()
public function willBeLastOfSameType($allow_validated_drafts = false)
{
// get date of last validated invoices of same type
$sql = "SELECT datef";
@ -5586,7 +5587,12 @@ class Facture extends CommonInvoice
$last_date = $this->db->jdate($obj->datef);
$invoice_date = $this->date;
return [$invoice_date >= $last_date, $last_date];
$is_last_of_same_type = $invoice_date >= $last_date;
if ($allow_validated_drafts) {
$is_last_of_same_type = $is_last_of_same_type || (!strpos($this->ref, 'PROV') && $this->status == self::STATUS_DRAFT);
}
return [$is_last_of_same_type, $last_date];
} else {
// element is first of type to be validated
return [true];