我有模型报价和模型发票。每个模型的数据库都有以下列:日期、公司、产品和价格。当客户批准报价时,我想将该报价转换为具有相同值但具有当前日期和自己的 invoice_id 的发票。
我应该在我的 Invoice 模型中包含哪些代码,以便记录“重复”或“更改”状态?
谢谢
我有模型报价和模型发票。每个模型的数据库都有以下列:日期、公司、产品和价格。当客户批准报价时,我想将该报价转换为具有相同值但具有当前日期和自己的 invoice_id 的发票。
我应该在我的 Invoice 模型中包含哪些代码,以便记录“重复”或“更改”状态?
谢谢
在报价中,您可以使用以下代码
after_save :generate_invoice, :if => :approved?
def approved?
# your code to return true or false, this method should return true only one time, handle it carefully.
end
def generate_invoice
Invoice.create!(date: Time.now, company: self.company, product: self.product, price: self.price)
end