我是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
值是绝对的。
我该怎么做?
答案 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="{"readonly": true}"/>
<field name="date_invoice" modifiers="{"readonly": [["state", "not in", ["draft"]]]}"/>
<field name="partner_id" on_change="1" modifiers="{"readonly": [["state", "not in", ["draft"]]], "required": true}" string="Cliente"/>
<field name="commercial_partner_id" invisible="1" modifiers="{"readonly": true, "tree_invisible": true}"/>
<field name="reference" invisible="1" modifiers="{"tree_invisible": true}"/>
<field name="name" invisible="1" modifiers="{"readonly": [["state", "not in", ["draft"]]], "tree_invisible": true}"/>
<field name="journal_id" invisible="1" modifiers="{"readonly": [["state", "not in", ["draft"]]], "required": true, "tree_invisible": true}"/>
<field name="period_id" invisible="1" modifiers="{"invisible": true, "readonly": [["state", "not in", ["draft"]]], "tree_invisible": true}"/>
<field name="currency_id" invisible="1" modifiers="{"invisible": true, "readonly": [["state", "not in", ["draft"]]], "required": true, "tree_invisible": true}"/>
<field name="amount_total" sum="Importo Totale" modifiers="{"readonly": true}"/>
<field name="amount_tax" sum="IVA" modifiers="{"readonly": true}"/>
<field name="state" modifiers="{"readonly": true}"/>
<field name="comment" modifiers="{}"/>
<field name="type" invisible="context.get('type',True)" modifiers="{"readonly": true, "tree_invisible": true}"/>
</tree>
''';
class UtenteEsteso(models.Model):
_inherit = 'res.users'
alt_view=fields.Boolean("Vista alternativa", default=False)
选择列使用DB::raw
,以避免被查询构建器引用:
ledger.openingBalance