- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
class Invoice
def Invoice.generate(order_id, charge_amount, credited_amount = 0.0)
Invoice.new(:order_id => order_id, :amount => charge_amount, :invoice_type => PURCHASE, :credited_amount => credited_amount)
end
end
为什么要在 Invoice
类中创建 Invoice.generate
而不是 self.generate
?
最佳答案
self.generate
更容易使用,而 Invoice.generate
可以说更明确。除此之外,两者之间没有区别。
您可以使用这种形式在任何实例上定义方法
def receiver.method(args)
end
检查一下
class Foo
end
def Foo.bar
"bar"
end
Foo.bar # => "bar"
是的,我指的是任何实例。绝对有可能一个实例有某种方法而另一个实例没有
f = Foo.new
def f.quux
'quux'
end
f2 = Foo.new
f.quux # => "quux"
f2.quux # => # ~> -:20:in `<main>': undefined method `quux' for #<Foo:0x007fe4e904a6c0> (NoMethodError)
提醒:在类定义内部(但在方法定义外部)self
指向该类。
class Foo
# self is Foo
end
因此,有了这些知识,self.generate
和 Invoice.generate
之间的区别就很明显了。
关于ruby - self.generate 和 Invoice.generate 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13448154/
我在月度发票中添加发票项目时遇到问题。这是我的计费实现。 收到 invoice.created 后来自 Stripe 的 webhook,我计算了额外的付款金额并尝试通过添加发票项目来更新当前发票。这
有一个网站曾经销售实体产品......现在他们想要销售一些完全不同的服务之王......比如信用套餐来向用户帐户收费(购买产品)或购买短信..诸如此类 所以数据库以前是这样的 order : user
我正在扩展员工模块以列出员工从公司获得的所有设备。下面是我的 models.py : # -*- coding: utf-8 -*- from odoo import models, fields,
我正在使用此代码在 Magento 中创建发票: $invoiceId = Mage::getModel('sales/order_invoice_api')->create($order->getI
我正在尝试使用 Stripe 构建一个包含三到四个不同计划的简单订阅网站。 在应用程序中,当用户注册时,会分配一个 Stripe 客户 ID。然后,在订阅计划时,我正在收听这些 webhook 事件:
我正在创建一个 .NET 簿记应用程序,并且认为从其他人那里听取我的数据库表应该是什么样子是个好主意。 我有一个“产品”和一个“发票”表以及一些与我的问题无关的其他表。 除了计算机语言之外,大多数情况
我对泰勒 ( https://github.com/laravel/cashier ) 的收银包裹有疑问。当我尝试获取用户的发票时,返回的对象为空。有关信息,我已将收银员数据库列设置到成员(membe
我正在实现发票系统和我的应用程序表。让我们说发票是由网站管理员开具的。然后客户点击支付链接并转发到支付网关。 同时管理员发现价格不正确并决定编辑价格,但客户已经在支付网关页面上并且正在根据之前的价格付
我正在尝试开具发票,在产品中我使用了自动完成功能从数据库中获取产品名称和价格。 第一行很容易,但第二行根本不起作用。 索引.php Untitled Document
对不起我的英语 我正在编写一个自定义 Odoo 模块,我的目标是在 account.invoice 中添加一个自定义计算字段,其中包含存储在tax_line_ids amount 字段中的每个税值的总
简短问题:使用get_invoices endpoint ,当我尝试从 InvoiceFiles.pdfFileUrl 响应访问 URL 时,它会弹出一个 api.zuora 登录表单。我需要我的客户
我尝试将付款集成到我的电报机器人中。 我使用电报库工作。 所以我创建了一张发票 const invoice = { provider_token: payment_tocken, st
我有以下架构,但我不确定如何在 Firestore 中对其建模。 我会有客户和发票。客户“有”发票。我需要能够执行这两个查询: 显示客户拥有的发票 更新系统中的所有发票(将 boolean 属性从 t
Stripe 文档对此含糊不清: https://stripe.com/docs/billing/webhooks A few days prior to renewal, your site rec
Stripe 文档对此含糊不清: https://stripe.com/docs/billing/webhooks A few days prior to renewal, your site rec
我需要在为采购发票生成的 LedgerTrans 文本中更改文本“采购发票某物”。 更具体地说,需要缩短它,因为它通过接口(interface)在另一个系统中使用。 很明显,此文本必须在某处进行参数化
我无法让 MySQL 查询为我工作。这是设置。 一位客户要求我根据一些会计数据编制一份报告。他想选择一个日期(可能还有其他条件)并让它返回以下所有内容(一个 OR 语句):1.) 在该日期或之后插入的
我正在使用 Stripe(测试模式)在我的应用程序中开发支付模块。我做了以下, 使用 Customer.create(customerParams) 为客户订阅在 stripe 中创建的现有计划。据我
我已经安装了InvoicePlane v1.4.6 在我的共享主机帐户上。能够执行常规任务,例如制作报价并将其转换为发票以及几乎所有预期的功能。 现在,我的发票需要显示该特定发票发生的交易,例如。已收
我确实被阻止了,我想隐藏“创建发票”按钮,但基于一个条件,我的条件是如果订单行有服务,则该按钮被隐藏。我创建了一个字段和一个函数,但最终总是出现模型中不存在该字段的错误,这是我的代码: 错误: Fie
我是一名优秀的程序员,十分优秀!