/** * DM2 creation callback, binds to the current content topic. */ public function &dm2_create_callback(&$controller) { $this->_deliverable = new org_openpsa_sales_salesproject_deliverable_dba(); $this->_deliverable->salesproject = $this->_salesproject->id; $this->_deliverable->state = org_openpsa_sales_salesproject_deliverable_dba::STATUS_NEW; $this->_deliverable->orgOpenpsaObtype = $this->_product->delivery; if (!$this->_deliverable->create()) { debug_print_r('We operated on this object:', $this->_deliverable); throw new midcom_error('Failed to create a new deliverable. Last Midgard error was: ' . midcom_connection::get_error_string()); } return $this->_deliverable; }
public function testCRUD() { midcom::get('auth')->request_sudo('org.openpsa.sales'); $deliverable = new org_openpsa_sales_salesproject_deliverable_dba(); $deliverable->salesproject = $this->_salesproject->id; $deliverable->plannedUnits = 2.5; $deliverable->pricePerUnit = 100; $stat = $deliverable->create(); $this->assertTrue($stat, midcom_connection::get_error_string()); $this->register_object($deliverable); $this->assertEquals($deliverable->price, 250); $parent = $deliverable->get_parent(); $this->assertEquals($parent->guid, $this->_salesproject->guid); $this->_salesproject->refresh(); $this->assertEquals($this->_salesproject->value, 250); $this->assertEquals($this->_salesproject->profit, 250); $deliverable->plannedUnits = 2; $stat = $deliverable->update(); $this->assertTrue($stat); $this->_salesproject->refresh(); $this->assertEquals($this->_salesproject->value, 200); $this->assertEquals($this->_salesproject->profit, 200); $stat = $deliverable->delete(); $this->assertTrue($stat); $this->_salesproject->calculate_price(); $this->assertEquals($this->_salesproject->value, 0); $this->assertEquals($this->_salesproject->profit, 0); midcom::get('auth')->drop_sudo(); }