在laravel Query中获取ABS(绝对值)

时间:2015-09-18 09:01:45

标签: mysql laravel laravel-5

我是Laravel框架的新手,我正在寻找如何编写Query以获得绝对值(简而言之,忽略+和 - 符号以及只显示数据库中的数字。 我知道我们可以使用Abs来获得它。但我不知道怎么做。 看看我的代码:

$users = DB::table('transaction_details')->

Join('ledger','transaction_details.ledger','=','ledger.Name')->

groupBy('ledger.Name')->select(
    'ledger.CrDr as CrDr',
    'transaction_details.ledger as Name',
    'transaction_details.amount as Debit',
    'ledger.OpeningBalance as openingBalance'
)->get();

在上面的查询中,我希望ledger.openingBalance值是绝对的。 我该怎么做?

1 个答案:

答案 0 :(得分:1)

您可以对class Modulotest(models.Model): _inherit = 'account.invoice' def fields_view_get(self, cr, uid, view_id=None, view_type='form', context={}, toolbar=False): result = super(Modulotest, self).fields_view_get(cr, uid, view_id, view_type, context=context, toolbar=toolbar) if view_type=='tree' and result['name']=='account.invoice.tree': currUtente=self.pool.get('res.users').browse(cr,uid,uid,context) if currUtente.alt_view==True: result['arch']=self.getAltView() return result def getAltView(self): return ''' <tree create="true" colors="blue:state == 'draft';black:state in ('proforma','proforma2','open');gray:state == 'cancel'" string="Fattura" visible="false"> <field name="number" modifiers="{&quot;readonly&quot;: true}"/> <field name="date_invoice" modifiers="{&quot;readonly&quot;: [[&quot;state&quot;, &quot;not in&quot;, [&quot;draft&quot;]]]}"/> <field name="partner_id" on_change="1" modifiers="{&quot;readonly&quot;: [[&quot;state&quot;, &quot;not in&quot;, [&quot;draft&quot;]]], &quot;required&quot;: true}" string="Cliente"/> <field name="commercial_partner_id" invisible="1" modifiers="{&quot;readonly&quot;: true, &quot;tree_invisible&quot;: true}"/> <field name="reference" invisible="1" modifiers="{&quot;tree_invisible&quot;: true}"/> <field name="name" invisible="1" modifiers="{&quot;readonly&quot;: [[&quot;state&quot;, &quot;not in&quot;, [&quot;draft&quot;]]], &quot;tree_invisible&quot;: true}"/> <field name="journal_id" invisible="1" modifiers="{&quot;readonly&quot;: [[&quot;state&quot;, &quot;not in&quot;, [&quot;draft&quot;]]], &quot;required&quot;: true, &quot;tree_invisible&quot;: true}"/> <field name="period_id" invisible="1" modifiers="{&quot;invisible&quot;: true, &quot;readonly&quot;: [[&quot;state&quot;, &quot;not in&quot;, [&quot;draft&quot;]]], &quot;tree_invisible&quot;: true}"/> <field name="currency_id" invisible="1" modifiers="{&quot;invisible&quot;: true, &quot;readonly&quot;: [[&quot;state&quot;, &quot;not in&quot;, [&quot;draft&quot;]]], &quot;required&quot;: true, &quot;tree_invisible&quot;: true}"/> <field name="amount_total" sum="Importo Totale" modifiers="{&quot;readonly&quot;: true}"/> <field name="amount_tax" sum="IVA" modifiers="{&quot;readonly&quot;: true}"/> <field name="state" modifiers="{&quot;readonly&quot;: true}"/> <field name="comment" modifiers="{}"/> <field name="type" invisible="context.get('type',True)" modifiers="{&quot;readonly&quot;: true, &quot;tree_invisible&quot;: true}"/> </tree> '''; class UtenteEsteso(models.Model): _inherit = 'res.users' alt_view=fields.Boolean("Vista alternativa", default=False) 选择列使用DB::raw,以避免被查询构建器引用:

ledger.openingBalance