【问题标题】:Get Line Items in an Invoice logic hook in SuiteCRM在 SuiteCRM 的发票逻辑挂钩中获取行项目
【发布时间】:2017-06-17 19:56:42
【问题描述】:

在保存发票后,我试图通过逻辑挂钩更新我的产品字段。

到目前为止,我的理解是,我需要获取与发票相关的 AOS_Products_Quotes,然后我可以从那里获取产品、更新必填字段并保存产品。听起来对吗?

正在触发逻辑挂钩,但不会加载关系。

  function decrement_stocks ( $bean, $event, $arguments) {
   //$bean->product_value_c = $bean->$product_unit_price * $bean->product_qty;

    $file = 'custom/modules/AOS_Invoices/decrement.txt';

    // Get the Invoice ID:
    $sInvoiceID = $bean->id;
    $oInvoice = new AOS_Invoices();
    $oInvoice->retrieve($sInvoiceID);
    $oInvoice->load_relationship('aos_invoices_aos_product_quotes');
    $aProductQuotes = $oInvoice->aos_invoices_aos_product_quotes->getBeans();

    /*
    $aLineItemslist = array();
    foreach ($oInvoice->aos_invoices_aos_product_quotes->getBeans() as $lineitem) {
        $aLineItemslist[$lineitem->id] = $lineitem;
    }
    */
    $sBean = var_export($bean, true);
    $sInvoice = var_export($oInvoice, true);
    $sProductQuotes = var_export($aProductQuotes, true);

    $current = $sProductQuotes . "\n\n\n------\n\n\n" . $sInvoice . "\n\n\n------\n\n\n" . $sBean;

    file_put_contents($file, $current);

  }

发票正在检索中。但要么load_relationship 没有做任何事情($sInvoice 不会改变或没有它)和$aProductQuotes 是 Null。

我正在开发 SuiteCRM 7.8.3,并在 7.9.1 上进行了尝试,但没有成功。我做错了什么?

【问题讨论】:

    标签: sugarcrm suitecrm


    【解决方案1】:

    我不熟悉 SuiteCRM 的细节,但我总是建议检查一下:

    • retrieve() 的返回值:bean 还是 null? 如果 null,则没有找到具有给定 ID 的 bean。 在这种情况下,$oInvoice 将保持空白(但您的评论表明情况并非如此)

    • load_relationship() 的返回值:true(成功)或 false(失败,查看日志)

    我想知道,你为什么不使用 $bean?

    相反,您似乎收到了 $bean 的另一个副本/引用(并称其为 $oInvoice)?为什么? 或者您的意思是接收一个以某种方式连接到 $bean 的 不同类型 bean?

    那么它肯定没有与 $bean 相同的 id,除非你专门这样编码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-09
      • 1970-01-01
      • 1970-01-01
      • 2020-05-08
      • 2015-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多