Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/tw automatic group order invoice generation #907

Open
wants to merge 31 commits into
base: master
Choose a base branch
from

Conversation

Viehlieb
Copy link
Contributor

@Viehlieb Viehlieb commented Dec 23, 2021

Offers the possibility to generate Invoices for given Group Orders.
Generation is possible after an order is closed.
If order is 'settled' then there's additionally the possibility to let the software send e-mails automatically on button press. The corresponding invoices will be sent as attachment via mail to the order group members.

Notes:
To use automatic sending of invoices, select option in "Admin/Finance" config
You can enter a "payment method " in "Admin/Finance"
To make things work, it is mandatory to enter a tax_number in "Admin/Foodcoop" config

As for now "payment method" determines the "body" of the invoice.
An example of new options and the resulting invoice can be found here:

tax_number
finance
Screenshot from 2022-03-28 16-16-01

Additionally for older and already settled orders, group order invoices can be generated manually under "finance/balancing"
generate
download

Invoices will be generated given the momentarily given information about invoicee and invoicer (tax_number, contact details...). SO take care when delting an invoice.

@wvengen
Copy link
Member

wvengen commented Dec 24, 2021

This seems like a great feature. Thanks for taking the time to draft this!
What exactly is the use of removing an invoice?

@Viehlieb
Copy link
Contributor Author

Hey. Excuse my late reply.
When incorrect settings are set in the admin configs, there should be the possibility to delete the old and generate a new invoice with correct settings applied.

Copy link
Contributor Author

@Viehlieb Viehlieb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When a link was provided for article details, it was not possible to follow the link because of the :hover feature.
Behavior before commit:
Hover over articles would render the article infos and if no article is hovered there's a green box showing
Behavior after commit:
Hover won't do anything.
Click article will render background of the article green and article details will be shown in green box in the footer
So it is possible to follow links to article details in the green box

Screenshot from 2022-04-07 16-27-52

@Viehlieb
Copy link
Contributor Author

Viehlieb commented Apr 7, 2022

Is there anything more needed to merge this feature into master branch?

@paroga
Copy link
Member

paroga commented May 27, 2022

first: sorry for the late reply
second: thanks for the contribution
third: this is a huge change and therefore hard to review: could split it smaller self-containing parts? e.g.: change the model in a separate commit

there are a bunch of style violations and i have no idea why they are not marked by the CI system 😞
if i'm not wrong there are a bunch of changes which require cleanup before merge. it seams there a some dummy "hello world" files and debug outputs introduces.
please feel free to correct my if i'm wrong. i just skimmed the PR

@Viehlieb
Copy link
Contributor Author

Viehlieb commented Sep 7, 2022

Hey. Thanks for the hints.
It made me look into the code again and I am working on fixing the points you mentioned.

  1. I noticed, there was no authentication clause to deal wirth group order invoices.
    With b6854bc I added a neccessary update of the group_order_invoice_controller.
    :authenticate_finance, so only for finance authenticated users can see/download and generate group_order_invoices.
  2. Removed the "Hello World" Dummy files.
  3. Todo Style issues
    Let me know, if there is anything more you notice.

Copy link
Member

@paroga paroga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i looked only into the first commit of your PR for now

rescue => error
redirect_back fallback_location: root_path, notice: 'Something went wrong', :alert => I18n.t('errors.general_msg', :msg => error)
end
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a newline at the end of the file

end
end
else raise RecordInvalid
redirect_back fallback_location: root_path, notice: 'Something went wrong', :alert => I18n.t('errors.general_msg', :msg => "#{error} " + I18n.t('errors.check_tax_number'))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • what kind of error do you want to catch here?
  • please use translations for user visible strings.
  • please do not use notice and alert at the same time
  • there is usually no need to use I18n.t and you could use just t in the controllers
  • please use newer syntax name: value instead of :name => value

if FoodsoftConfig[:contact][:tax_number]
respond_to do |format|
format.pdf do
send_group_order_invoice_pdf @group_order_invoice if FoodsoftConfig[:contact][:tax_number]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you check already for the tax_number in line 6. what's the purpose of the second check here?


def show
@group_order_invoice = GroupOrderInvoice.find(params[:id])
if FoodsoftConfig[:contact][:tax_number]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why can't we show an invoice without an tax number?


def destroy
goi = GroupOrderInvoice.find(params[:id])
@order = goi.group_order.order
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the purpose of @order here?

Comment on lines +19 to +21
if FoodsoftConfig[:contact][:tax_number].blank?
errors.add(:group_order_invoice, "Keine Steuernummer in FoodsoftConfig :contact gesetzt")
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method does not access the database and therefore should be removed from the model and move to a better location (BTW: there are user visible string which are not translated)

def init
self.invoice_number = generate_invoice_number(1) unless self.invoice_number
self.invoice_date = Time.now unless self.invoice_date
self.payment_method = FoodsoftConfig[:group_order_invoices]&.[](:payment_method) || I18n.t('activerecord.attributes.group_order_invoice.payment_method') unless self.payment_method
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is the payment method stored in FoodsoftConfig?
please do not use translated strings in the model. depending on the locale of the current user different data would be used and stored in the database

end

def init
self.invoice_number = generate_invoice_number(1) unless self.invoice_number
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use a before_validation hook instead (see e.g. set_password in the User model)

end

def name
I18n.t('activerecord.attributes.group_order_invoice.name') + "_#{invoice_number}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the translation should be moved from the model to a controller, since the model should be language independent

I18n.t('activerecord.attributes.group_order_invoice.name') + "_#{invoice_number}"
end

def load_data_for_invoice
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you copy everything here? usually working with a GroupOrderInvoice instance should be the way to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants