Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9168615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:40:02+00:00 2026-06-17T15:40:02+00:00

def self.build_prior_month(payee, as_of = Time.current, opts = {}) start_date, end_date, year, month = effective_dates(as_of)

  • 0
  def self.build_prior_month(payee, as_of = Time.current, opts = {})    
    start_date, end_date, year, month = effective_dates(as_of)

    statement = payee.earnings_statements.build(
      :year => year,
      :month => month,
      :balance => 0,
      :revenue => 0
    )

    statement.generate(start_date, end_date, year, month)
    statement.update_totals

    statement
  end

That’s a function that I have in a model of mine. It returns statement properly, but doesn’t save to the database. Why is that?

The generate function looks like:

  def generate_ledger_items(start_date, end_date, year, month)
    payee.ledger_entries.for_month_and_year(month, year).each do |entry|
      earnings_statement_items.build(
        :items => entry.item_group,
        :units => entry.units,
        :net_revenue => entry.net_revenue,
        :net_revenue_per_unit => [entry.net_revenue, entry.units].all? ? (entry.net_revenue / entry.units).round(2) : nil,
        :fees => entry.service_fees,
        :payments_collected => entry.spendings,
        :fee_terms => entry.terms || entry.description, # When would terms be set?
        :due => entry.credit || -entry.debit
      )
    end
  end

  def update_totals
    self.revenue  = earnings_statement_items.net_revenue
    self.balance = earnings_statement_items.total
  end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T15:40:03+00:00Added an answer on June 17, 2026 at 3:40 pm

    The build method on your association does not actually save the record into the database. create will. It is similar to the difference between new and create on your models.

    statement = payee.earnings_statements.create(
      :year => year,
      :month => month,
      :balance => 0,
      :revenue => 0
    )
    

    Will save your record. See the documentation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

def self.jq_column_models COLUMN_NAME.collect {|x| {:name => x.to_s, :width => 80, :format => 'integer' if
def self.get(server) return unless server server = server.to_s if klass = @handlers[server] obj =
Best Guess: method - def(self, maybeSomeVariables); lines of code which achieve some purpose Function
module Test def self.model_method puts this is a module method end end class A
I have my mongoid query in the model def self.get_result collection_name, hash_params, page, per_page
I have a class that contains this class method: def self.get_event_record(row, participant) event =
If I have the following piece of Ruby code: class Blah def self.bleh @blih
So I have this code inside my lib/ folder: class GlobalConfig::SetHelper def self.yes_no_input(configuration) value
My model: class User has_many :items end class Item belongs_to :user def self.with_color(color, is_loaded)
I was wondering what those meant: class ChangeTimeColumns < ActiveRecord::Migration def self.up end def

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.