Skip to content

Commit

Permalink
Merge branch '2024.11'
Browse files Browse the repository at this point in the history
  • Loading branch information
gitlabci committed Jan 10, 2025
2 parents c27d6ab + 5069cee commit 3daf7c9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
4 changes: 3 additions & 1 deletion tests/tine20/Sales/CustomersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @package Sales
* @license http://www.gnu.org/licenses/agpl.html
* @copyright Copyright (c) 2013-2024 Metaways Infosystems GmbH (http://www.metaways.de)
* @copyright Copyright (c) 2013-2025 Metaways Infosystems GmbH (http://www.metaways.de)
* @author Alexander Stintzing <[email protected]>
*
*/
Expand Down Expand Up @@ -321,6 +321,8 @@ public function testDeleteUsedBillingAddress()
'billing_address_id' => $customer['debitors'][0]['billing'][0]['id'],
)));

$this->assertInstanceOf(Sales_Model_Address::class, $contract->billing_address_id);

// if the property is set to null, no handling of this dependent records must be done
$customer['debitors'][0]['billing'] = NULL;
$customer = $this->_json->saveCustomer($customer);
Expand Down
19 changes: 14 additions & 5 deletions tine20/Sales/Controller/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @subpackage Controller
* @license http://www.gnu.org/licenses/agpl.html AGPL Version 3
* @author Alexander Stintzing <[email protected]>
* @copyright Copyright (c) 2013-2018 Metaways Infosystems GmbH (http://www.metaways.de)
* @copyright Copyright (c) 2013-2025 Metaways Infosystems GmbH (http://www.metaways.de)
*
*/

Expand Down Expand Up @@ -1512,10 +1512,18 @@ public function createXRechnungsAttachment(Sales_Model_Invoice $invoice): void
}
try {
$customer = $this->_getCustomerFromInvoiceRelations($invoice) ?? throw new Tinebase_Exception_SystemGeneric('invoice does not have a customer');
/** @var Sales_Model_Contract $contract */
$contract = $invoice->relations->find('type', 'CONTRACT')?->related_record;
Tinebase_Record_Expander::expandRecord($customer);
$debitor = $customer->{Sales_Model_Customer::FLD_DEBITORS}->getFirstRecord();
if ($contract = $invoice->relations->find('type', 'CONTRACT')?->related_record) {
Tinebase_Record_Expander::expandRecord($contract);
}
$debitor = null;
/** @var Sales_Model_Contract $contract */
if ($contract?->billing_address_id) {
$debitor = $customer->{Sales_Model_Customer::FLD_DEBITORS}->find(fn($deb) => $deb->{Sales_Model_Debitor::FLD_BILLING}->getById($contract->getIdFromProperty('billing_address_id')), null);
}
if (null === $debitor) {
$debitor = $customer->{Sales_Model_Customer::FLD_DEBITORS}->getFirstRecord();
}

// type (invoice_type) => REVERSAL => storno gibt verknüpfung

Expand All @@ -1530,7 +1538,8 @@ public function createXRechnungsAttachment(Sales_Model_Invoice $invoice): void
Sales_Model_Document_Invoice::FLD_CUSTOMER_ID => $customer,
Sales_Model_Document_Invoice::FLD_CONTRACT_ID => $contract,
Sales_Model_Document_Invoice::FLD_RECIPIENT_ID => new Sales_Model_Document_Address(
$debitor->{Sales_Model_Debitor::FLD_BILLING}->getFirstRecord()->toArray(), true
($contract?->billing_address_id ?:
$debitor->{Sales_Model_Debitor::FLD_BILLING}->getFirstRecord())->toArray(), true
),
// TODO FIXME do we have a FLD_CONTACT_ID?
Sales_Model_Document_Invoice::FLD_DOCUMENT_LANGUAGE => 'de',
Expand Down
3 changes: 2 additions & 1 deletion tine20/Sales/Model/Contract.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @package Sales
* @license http://www.gnu.org/licenses/agpl.html AGPL Version 3
* @author Philipp Schüle <[email protected]>
* @copyright Copyright (c) 2007-2024 Metaways Infosystems GmbH (http://www.metaways.de)
* @copyright Copyright (c) 2007-2025 Metaways Infosystems GmbH (http://www.metaways.de)
*/

/**
Expand Down Expand Up @@ -99,6 +99,7 @@ class Sales_Model_Contract extends Tinebase_Record_Abstract

self::JSON_EXPANDER => [
Tinebase_Record_Expander::EXPANDER_PROPERTIES => [
'billing_address_id' => [],
'products' => [
Tinebase_Record_Expander::EXPANDER_PROPERTIES => [
'product_id' => [
Expand Down

0 comments on commit 3daf7c9

Please sign in to comment.