Skip to content

Commit

Permalink
Merge branch 'pu/pm/SalesTbEvalDimCostCenter' into '2024.11'
Browse files Browse the repository at this point in the history
tweak(TB CostCenter/Sales) move from relation to tb eval dim

See merge request tine20/tine20!4879
  • Loading branch information
paulmhh committed Feb 1, 2024
2 parents da0e83d + dff56b6 commit 0614a3f
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 71 deletions.
2 changes: 1 addition & 1 deletion phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3652,7 +3652,7 @@ parameters:

-
message: "#^Access to an undefined property Sales_Controller_PurchaseInvoice\\:\\:\\$_currentBillingContract\\.$#"
count: 3
count: 7
path: tine20/Sales/Controller/PurchaseInvoice.php

-
Expand Down
14 changes: 1 addition & 13 deletions tests/tine20/Sales/InvoiceControllerTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,9 @@ protected function _createFailingContracts()
'start_date' => $this->_referenceDate,
'end_date' => NULL,
'billing_address_id' => $this->_addressRecords->filter('customer_id', $this->_customerRecords->filter('name', 'Customer3')->getFirstRecord()->getId())->filter('type', 'billing')->getFirstRecord()->getId(),
'eval_dim_cost_center' => $this->_costcenterRecords->getFirstRecord()->getId(),
));

$contract->relations = array(
array(
'own_model' => Sales_Model_Contract::class,
'own_backend' => Tinebase_Model_Relation::DEFAULT_RECORD_BACKEND,
'own_id' => NULL,
'related_degree' => Tinebase_Model_Relation::DEGREE_SIBLING,
'related_model' => Tinebase_Model_EvaluationDimensionItem::class,
'related_backend' => Tinebase_Model_Relation::DEFAULT_RECORD_BACKEND,
'related_id' => $this->_costcenterRecords->getFirstRecord()->getId(),
'type' => 'LEAD_COST_CENTER'
),
);

$this->_contractRecords->addRecord($this->_contractController->create($contract));

// add contract without address
Expand Down
2 changes: 1 addition & 1 deletion tests/tine20/Tinebase/Relation/RelationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ public function testTransfer()
*/
public function testGetConstraintsConfigs() {
$result = Tinebase_Relations::getConstraintsConfigs('Sales_Model_Contract');
$this->assertEquals(12, count($result));
$this->assertEquals(10, count($result));

foreach($result as $item) {
if ($item['ownRecordClassName'] == 'Sales_Model_Contract' && $item['relatedRecordClassName'] == 'Timetracker_Model_Timeaccount') {
Expand Down
13 changes: 4 additions & 9 deletions tine20/Sales/Controller/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,18 +199,13 @@ protected function _getRelationDefaults()

/**
* finds the costcenter of $this->_currentContract
*
* @return Tinebase_Model_EvaluationDimensionItem|NULL
*/
protected function _findCurrentCostCenter()
protected function _findCurrentCostCenter(): ?Tinebase_Model_EvaluationDimensionItem
{
$this->_currentBillingCostCenter = NULL;

foreach ($this->_currentBillingContract->relations as $relation) {
if ($relation->type == 'LEAD_COST_CENTER' && $relation->related_model == Tinebase_Model_EvaluationDimensionItem::class) {
$this->_currentBillingCostCenter = $relation->related_record;
}
if ($this->_currentBillingContract->eval_dim_cost_center && !$this->_currentBillingContract->eval_dim_cost_center instanceof Tinebase_Model_EvaluationDimensionItem) {
$this->_currentBillingContract->eval_dim_cost_center = Tinebase_Controller_EvaluationDimensionItem::getInstance()->get($this->_currentBillingContract->eval_dim_cost_center);
}
$this->_currentBillingCostCenter = $this->_currentBillingContract->eval_dim_cost_center;

return $this->_currentBillingCostCenter;
}
Expand Down
13 changes: 4 additions & 9 deletions tine20/Sales/Controller/PurchaseInvoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,18 +137,13 @@ protected function _getRelationDefaults()

/**
* finds the costcenter of $this->_currentContract
*
* @return Tinebase_Model_EvaluationDimensionItem|NULL
*/
protected function _findCurrentCostCenter()
protected function _findCurrentCostCenter(): ?Tinebase_Model_EvaluationDimensionItem
{
$this->_currentBillingCostCenter = NULL;

foreach ($this->_currentBillingContract->relations as $relation) {
if ($relation->type == 'LEAD_COST_CENTER' && $relation->related_model == Tinebase_Model_EvaluationDimensionItem::class) {
$this->_currentBillingCostCenter = $relation->related_record;
}
if ($this->_currentBillingContract->eval_dim_cost_center && !$this->_currentBillingContract->eval_dim_cost_center instanceof Tinebase_Model_EvaluationDimensionItem) {
$this->_currentBillingContract->eval_dim_cost_center = Tinebase_Controller_EvaluationDimensionItem::getInstance()->get($this->_currentBillingContract->eval_dim_cost_center);
}
$this->_currentBillingCostCenter = $this->_currentBillingContract->eval_dim_cost_center;

return $this->_currentBillingCostCenter;
}
Expand Down
12 changes: 1 addition & 11 deletions tine20/Sales/Import/Contract/Csv.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,7 @@ protected function _setCostCenter($result)
]));
foreach ($costCenters as $costCenter) {
if ($costCenter['name'] == $result['costcenter']) {
$result['relations'][] =
array(
'own_model' => Sales_Model_Contract::class,
'own_backend' => Tinebase_Model_Relation::DEFAULT_RECORD_BACKEND,
'own_id' => NULL,
'related_degree' => Tinebase_Model_Relation::DEGREE_SIBLING,
'related_model' => Tinebase_Model_EvaluationDimensionItem::class,
'related_backend' => Tinebase_Model_Relation::DEFAULT_RECORD_BACKEND,
'related_id' => $costCenter['id'],
'type' => 'LEAD_COST_CENTER'
);
$result['eval_dim_cost_center'] = $costCenter['id'];
break;
}
}
Expand Down
12 changes: 1 addition & 11 deletions tine20/Sales/Import/PurchaseInvoice/Csv.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,7 @@ protected function _setCostCenter($result)
]));
foreach ($costCenters as $costCenter) {
if ($costCenter['name'] == $result['costcenter']) {
$result['relations'][] =
array(
'own_model' => 'Sales_Model_PurchaseInvoice',
'own_backend' => Tinebase_Model_Relation::DEFAULT_RECORD_BACKEND,
'own_id' => NULL,
'related_degree' => Tinebase_Model_Relation::DEGREE_SIBLING,
'related_model' => Tinebase_Model_EvaluationDimensionItem::class,
'related_backend' => Tinebase_Model_Relation::DEFAULT_RECORD_BACKEND,
'related_id' => $costCenter['id'],
'type' => 'LEAD_COST_CENTER'
);
$result['eval_dim_cost_center'] = $costCenter['id'];
}
}
}
Expand Down
16 changes: 0 additions & 16 deletions tine20/Sales/Model/Contract.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,18 +238,6 @@ class Sales_Model_Contract extends Tinebase_Record_Abstract
)
)
),
'costcenter' => array(
'type' => 'virtual',
'config' => array(
'type' => 'relation',
'label' => 'Lead Cost Center', // _('Lead Cost Center')
'config' => array(
'appName' => Tinebase_Config::APP_NAME,
'modelName' => Tinebase_Model_EvaluationDimensionItem::MODEL_NAME_PART,
'type' => 'LEAD_COST_CENTER'
)
)
),
'products' => array(
'validators' => array(Zend_Filter_Input::ALLOW_EMPTY => TRUE, Zend_Filter_Input::DEFAULT_VALUE => NULL),
'label' => 'Products', // _('Products')
Expand Down Expand Up @@ -306,10 +294,6 @@ public function setFromArray(array &$_data)
array('type' => 'PRODUCT', 'degree' => 'sibling', 'text' => 'Product', 'max' => '0:0'),
), 'defaultType' => ''
),
array('relatedApp' => 'Tinebase', 'relatedModel' => Tinebase_Model_EvaluationDimensionItem::class, 'config' => array(
array('type' => 'LEAD_COST_CENTER', 'degree' => 'sibling', 'text' => 'Lead Cost Center', 'max' => '1:0'), // _('Lead Cost Center')
), 'defaultType' => ''
),
array('relatedApp' => 'Timetracker', 'relatedModel' => 'Timeaccount', 'config' => array(
array('type' => 'TIME_ACCOUNT', 'degree' => 'sibling', 'text' => 'Time Account', 'max' => '0:1'), // _('Time Account')
), 'defaultType' => ''
Expand Down

0 comments on commit 0614a3f

Please sign in to comment.