Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@kernie
Copy link
Contributor

@kernie kernie commented Feb 6, 2025

Description

When creating an invoice from command line the parameter --template is only considered, if the customer doesn't have defined a default invoice template.

Closes #5337

Test have been adapted.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I verified that my code applies to the guidelines (composer code-check)
  • I updated the documentation (see here)
  • I agree that this code is used in Kimai (see license)

@kernie
Copy link
Contributor Author

kernie commented Feb 6, 2025

Sorry for the mess... I created a new PR with only my changes.

One observation from my test:
When I create an invoice via command line for a HTML template like bin/console kimai:invoice:create --user=susan_super --project=1 --start=2025-01-01 --end=2025-01-31 --preview=/opt/kimai/var/data/invoices --preview-unique --template=2 the stored file hasn't a file suffix

+--------------- Created 1 invoice(s) ---------------+
| Filename                                           |
+----------------------------------------------------+
| /opt/kimai/var/data/invoices/invoice_67a4c69b685be |
+----------------------------------------------------+

It is however valid HTML.

@kernie
Copy link
Contributor Author

kernie commented Feb 7, 2025

I made a dedicated test, for which I added a second invoice template in the fixture. The customer's default template is HTML, via console I define the second template and get a PDF file.

The php tests revealed then another problem in the tests/Controller/InvoiceControllerTest, where I corrected the number of invoice templates.

As mentioned the CI failure is related to a Twig security issue solved in branch 2.29.

That's my proposal, happy to get feedback.

@kernie kernie marked this pull request as ready for review February 8, 2025 19:29
@codecov
Copy link

codecov bot commented Feb 10, 2025

Codecov Report

Attention: Patch coverage is 85.18519% with 4 lines in your changes missing coverage. Please review.

Project coverage is 87.20%. Comparing base (14cdcd3) to head (236a76b).

Files with missing lines Patch % Lines
src/Command/InvoiceCreateCommand.php 85.18% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #5339      +/-   ##
============================================
- Coverage     87.21%   87.20%   -0.02%     
- Complexity     9222     9228       +6     
============================================
  Files           824      824              
  Lines         30528    30542      +14     
============================================
+ Hits          26625    26634       +9     
- Misses         3903     3908       +5     
Files with missing lines Coverage Δ
src/Command/InvoiceCreateCommand.php 87.84% <85.18%> (+0.70%) ⬆️

... and 3 files with indirect coverage changes

@kernie
Copy link
Contributor Author

kernie commented Feb 14, 2025

This is unrelated to the feature enhancement in this PR, but since I started to complete the test cases for this, I got the impression, that there is a design decision to get an invoice document with success message, even if there wasn't any billable timesheet.

When creating the invoice in the browser the page wouldn't offer the choice to create the invoice if no timesheet was found. This makes sense to me, because we would create also an invoice number for an invoice that doesn't contain billable entries.

Maybe one could provide a check after the InvoiceModel was created, if there are any entries? I could add that here or in a separate PR.

Copy link
Member

@kevinpapst kevinpapst left a comment

Choose a reason for hiding this comment

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

Thanks 👍 I had a look and have a few comments

@kernie kernie requested a review from kevinpapst February 28, 2025 21:05
@codecov-commenter
Copy link

codecov-commenter commented Mar 12, 2025

Codecov Report

Attention: Patch coverage is 85.18519% with 4 lines in your changes missing coverage. Please review.

Project coverage is 87.40%. Comparing base (da10099) to head (97b1faa).

Files with missing lines Patch % Lines
src/Command/InvoiceCreateCommand.php 85.18% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #5339      +/-   ##
============================================
- Coverage     87.41%   87.40%   -0.01%     
- Complexity     9477     9483       +6     
============================================
  Files           844      844              
  Lines         31260    31274      +14     
============================================
+ Hits          27325    27336      +11     
- Misses         3935     3938       +3     
Files with missing lines Coverage Δ
src/Command/InvoiceCreateCommand.php 87.84% <85.18%> (+0.70%) ⬆️

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@kernie
Copy link
Contributor Author

kernie commented Mar 17, 2025

Hello @kevinpapst, I'm not sure, if the answer to the review was sufficient. Can you tell me if you expect more to change in this PR from my side?

@kevinpapst
Copy link
Member

Nope, there is nothing you should do. I will review and integrate it at some point.
You can't do anything to speed up that process.

@kevinpapst kevinpapst requested a review from Copilot May 18, 2025 19:34
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for overwriting a customer’s default invoice template via the --template CLI option.

  • Introduces --template processing in the invoice create command (by name or ID)
  • Adds new fixtures and tests to cover overwriting behavior
  • Refactors template lookup logic in InvoiceCreateCommand

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
tests/DataFixtures/InvoiceTemplateFixtures.php Adds a second sample invoice template for overwrite tests
tests/Controller/InvoiceControllerTest.php Updates expected template count after deletion
tests/Command/InvoiceCreateCommandTest.php Adapts invalid-case tests and adds new overwrite scenarios
src/Command/InvoiceCreateCommand.php Implements --template option handling and refactors lookup logic
Comments suppressed due to low confidence (3)

src/Command/InvoiceCreateCommand.php:211

  • [nitpick] This message could be clearer; for example: "The --template option must be a template name or numeric ID."
                $io->error('Option --template must be string or int');

src/Command/InvoiceCreateCommand.php:461

  • [nitpick] Method name is very long and ties it to the command-line context. Consider renaming to findTemplateByArgument() or similar for clarity.
getCommandLineArgumentTemplateForCustomer

src/Command/InvoiceCreateCommand.php:188

  • [nitpick] Mixing Yoda conditions (null !==) with non-Yoda elsewhere can hurt readability. Consider using a consistent style (e.g. $input->getOption('preview') !== null).
if (null !== $input->getOption('preview')) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: In progress

Development

Successfully merging this pull request may close these issues.

Unexpected behavior when defining template input parameter in "console kimai:invoice:create" command

3 participants