Jump to content

error new Invoice


Recommended Posts

Hi,

 

I update my prestashop at 1.6.1.0 and when i create new invoice have this error:

 

[PrestaShopException]

Property OrderInvoice->number is empty
at line 881 in file classes/ObjectModel.php

876. 877. 			$message = $this->validateField($field, $this->$field);878. 			if ($message !== true)879. 			{880. 				if ($die)881. 					throw new PrestaShopException($message);882. 				return $error_return ? $message : false;883. 			}884. 		}885. 886. 		return true;
  • ObjectModelCore->validateFields - [line 245 - classes/ObjectModel.php]
    240. 	 * @return array All object fields241. 	 * @throws PrestaShopException242. 	 */243. 	public function getFields()244. 	{245. 		$this->validateFields();246. 		$fields = $this->formatFields(self::FORMAT_COMMON);247. 248. 		// For retro compatibility249. 		if (Shop::isTableAssociated($this->def['table']))250. 			$fields = array_merge($fields, $this->getFieldsShop());
  • ObjectModelCore->getFields - [line 469 - classes/ObjectModel.php]
    464. 		}465. 466. 		// Database insertion467. 		if (Shop::checkIdShopDefault($this->def['table']))468. 			$this->id_shop_default = (in_array(Configuration::get('PS_SHOP_DEFAULT'), $id_shop_list) == true) ? Configuration::get('PS_SHOP_DEFAULT') : min($id_shop_list);469. 		if (!$result = Db::getInstance()->insert($this->def['table'], $this->getFields(), $null_values))470. 			return false;471. 472. 		// Get object id in database473. 		$this->id = Db::getInstance()->Insert_ID();474. 
  • ObjectModelCore->add - [line 152 - classes/order/OrderInvoice.php]
    147. 148. 		$delivery_address = new Address((int)$order->id_address_delivery);149.         $deliveryAddressPatternRules = Tools::jsonDecode(Configuration::get('PS_INVCE_DELIVERY_ADDR_RULES'), true);150.         $this->delivery_address = AddressFormat::generateAddress($delivery_address, $deliveryAddressPatternRules, '<br />', ' ');151. 152. 		return parent::add();153. 	}154. 155. 	public function getProductsDetail()156. 	{157. 		return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
  • OrderInvoiceCore->add - [line 431 - classes/ObjectModel.php] - [2 Arguments]
    426. 	 * @return bool Insertion result427. 	 * @throws PrestaShopException428. 	 */429. 	public function save($null_values = false, $auto_date = true)430. 	{431. 		return (int)$this->id > 0 ? $this->update($null_values) : $this->add($auto_date, $null_values);432. 	}433. 434. 	/**435. 	 * Adds current object to the database436. 	 *
  • ObjectModelCore->save - [line 1214 - classes/order/Order.php]
    1209. 			$order_invoice->total_wrapping_tax_excl = $this->total_wrapping_tax_excl;1210. 			$order_invoice->total_wrapping_tax_incl = $this->total_wrapping_tax_incl;1211. 1212. 			// Save Order invoice1213. 1214. 			$order_invoice->save();1215. 			if (Configuration::get('PS_INVOICE'))1216. 				$this->setLastInvoiceNumber($order_invoice->id, $this->id_shop);1217. 1218. 			if (Configuration::get('PS_ATCP_SHIPWRAP'))1219. 			{
  • OrderCore->setInvoice - [line 295 - classes/order/OrderHistory.php] - [1 Arguments]
    290. 		$order->current_state = $this->id_order_state;291. 		$order->valid = $new_os->logable;292. 		$order->update();293. 294. 		if ($new_os->invoice && !$order->invoice_number)295. 			$order->setInvoice($use_existing_payment);296. 		elseif ($new_os->delivery && !$order->delivery_number)297. 			$order->setDeliverySlip();298. 299. 		// set orders as paid300. 		if ($new_os->paid == 1)
  • OrderHistoryCore->changeIdOrderState - [line 525 - controllers/admin/AdminOrdersController.php] - [3 Arguments]
    520. 						$history->id_employee = (int)$this->context->employee->id;521. 522. 						$use_existings_payment = false;523. 						if (!$order->hasInvoice())524. 							$use_existings_payment = true;525. 						$history->changeIdOrderState((int)$order_state->id, $order, $use_existings_payment);526. 527. 						$carrier = new Carrier($order->id_carrier, $order->id_lang);528. 						$templateVars = array();529. 						if ($history->id_order_state == Configuration::get('PS_OS_SHIPPING') && $order->shipping_number)530. 							$templateVars = array('{followup}' => str_replace('@', $order->shipping_number, $carrier->url));
  • AdminOrdersControllerCore->postProcess - [line 171 - classes/controller/Controller.php]
    166. 			// setMedia MUST be called before postProcess167. 			if (!$this->content_only && ($this->display_header || (isset($this->className) && $this->className)))168. 				$this->setMedia();169. 170. 			// postProcess handles ajaxProcess171. 			$this->postProcess();172. 173. 			if (!empty($this->redirect_after))174. 				$this->redirect();175. 176. 			if (!$this->content_only && ($this->display_header || (isset($this->className) && $this->className)))
  • ControllerCore->run - [line 373 - classes/Dispatcher.php]
    368. 			// Execute hook dispatcher369. 			if (isset($params_hook_action_dispatcher))370. 				Hook::exec('actionDispatcher', $params_hook_action_dispatcher);371. 372. 			// Running controller373. 			$controller->run();374. 		}375. 		catch (PrestaShopException $e)376. 		{377. 			$e->displayMessage();378. 		}
  • DispatcherCore->dispatch - [line 54 - admin/index.php]
    49. 	$_POST['controller'] = strtolower($_POST['tab']);50. if (!isset($_REQUEST['controller']) && isset($_REQUEST['tab']))51. 	$_REQUEST['controller'] = strtolower($_REQUEST['tab']);52. 53. // Prepare and trigger admin dispatcher54. Dispatcher::getInstance()->dispatch();

     

     

     

     

    How can repair this?

     

    Thanks a lot!

     

 

Link to comment
Share on other sites

Uops, sorry UnMail, mobile version of this forum not show the code in messages.

 

Please, can you access to your phpMyAdmin list the table prefix_order_invoice and paste here?, The number is a field that you have got in this table, search the order id in the field id_order.

 

The number is the value that PrestaShops uses to show the order number in PDF.

 

I can't reproduce the error but could be a solution verify if id_order_invoice is the same that number in other cases and copy the value from id_order_invoice to number.

 

Tell me something.
Link to comment
Share on other sites

  • 2 weeks later...

Hi everybody, i understood the problem!

 

i think it's a bug of the last version of PS (1.6.1), there is an error in the code

 

in function setInvoice (in my 1.6.1.1) there is 

if ($id = (int)$this->hasDelivery()) {
   $order_invoice = new OrderInvoice($id);
} else {
   $order_invoice = new OrderInvoice();
}

but the only $id value returned by $this->hasDelivery() can be 1 because in that method the result is casted to bool. 

 

so if in DB there is an OrderInvoice with id 1, this will be wrongly fetched (for every order will be always fetched the invoice with id = 1). Instead if in DB there isn't an OrderInvoice with id = 1 you'll have the error described in this topic: Property OrderInvoice->number is empty

 

I'll comunicate this problem to presta developers, for the moment i solved making an override (attached to the post) to put in /override/classes/order/ (remember to erase the file /cache/class_index.php after has put the file in the override)

 

i hope this will help you too.

 

I also created an issue on the bugtracker: http://forge.prestashop.com/browse/PSCSX-6832

Order.php

Edited by scotch86 (see edit history)
Link to comment
Share on other sites

  • 2 weeks later...
  • 6 months later...

I have this problem too on ps 1.6.1.0, and this solution not working for me, after put this file in overrides/classes/order and delete file /cache/class_index, i make order, in databes still dont have new record in invoices, when i go to Back office in Orders and try to change status i have blank page with Your file, when i delete this file i can change order status but still have this error about empty invoice number

 

Dou You know if this bug its still in ps 1.6.1.5?

 

edit: i think i solved problem, i dont have entry in DB with id = 1, after change second entry to '1' i can change status without error and correct number invoice

Edited by mudol (see edit history)
Link to comment
Share on other sites

  • 1 year later...

If I compare the two error messages, it's different:

 

Property OrderInvoice->number is empty
at line 881 in file classes/ObjectModel.php

Property StockMvt->id_employee is empty
at line 917 in file classes/ObjectModel.php

 

Hence the cause is also different. The initial error refers to the order invoice number, yours is employee ID.

Link to comment
Share on other sites

  • 2 weeks later...

Up

I ha ve the same problem with the upgrade to 1.6.1.16 version 

A little diference:

 

[PrestaShopException]

Property StockMvt->id_employee is empty

at line 917 in file classes/ObjectModel.php

 

Can you help me please

 

 

 

StockMvt->id_employee is required so this problem is in the database. Something caused it. A module or a fatal error (timeout). I think you can only fix this value in the ps_stock_mvt table and hope it won't appear again.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...