Merge pull request #19947 from aspangaro/14p30

FIX Invoice - Clone - Don't report contacts on an another thirdparty
This commit is contained in:
Laurent Destailleur 2022-01-28 18:10:28 +01:00 committed by GitHub
commit 38fd7f9b66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,6 +17,7 @@
* Copyright (C) 2016 Ferran Marcet <fmarcet@2byte.es> * Copyright (C) 2016 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2018 Alexandre Spangaro <aspangaro@open-dsi.fr> * Copyright (C) 2018 Alexandre Spangaro <aspangaro@open-dsi.fr>
* Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com> * Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
* Copyright (C) 2022 Sylvain Legrand <contact@infras.fr>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -1159,6 +1160,9 @@ class Facture extends CommonInvoice
$object->fetch($fromid); $object->fetch($fromid);
// Load source object
$objFrom = clone $object;
// Change socid if needed // Change socid if needed
if (!empty($this->socid) && $this->socid != $object->socid) { if (!empty($this->socid) && $this->socid != $object->socid) {
$objsoc = new Societe($this->db); $objsoc = new Societe($this->db);
@ -1239,13 +1243,13 @@ class Facture extends CommonInvoice
$this->errors = $object->errors; $this->errors = $object->errors;
} else { } else {
// copy internal contacts // copy internal contacts
if ($object->copy_linked_contact($this, 'internal') < 0) { if ($object->copy_linked_contact($objFrom, 'internal') < 0) {
$error++; $error++;
$this->error = $object->error; $this->error = $object->error;
$this->errors = $object->errors; $this->errors = $object->errors;
} elseif ($this->socid == $object->socid) { } elseif ($object->socid == $objFrom->socid) {
// copy external contacts if same company // copy external contacts if same company
if ($object->copy_linked_contact($this, 'external') < 0) { if ($object->copy_linked_contact($objFrom, 'external') < 0) {
$error++; $error++;
$this->error = $object->error; $this->error = $object->error;
$this->errors = $object->errors; $this->errors = $object->errors;
@ -1256,7 +1260,7 @@ class Facture extends CommonInvoice
if (!$error) { if (!$error) {
// Hook of thirdparty module // Hook of thirdparty module
if (is_object($hookmanager)) { if (is_object($hookmanager)) {
$parameters = array('objFrom'=>$this); $parameters = array('objFrom'=>$objFrom);
$action = ''; $action = '';
$reshook = $hookmanager->executeHooks('createFrom', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks $reshook = $hookmanager->executeHooks('createFrom', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) { if ($reshook < 0) {