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

Barcode format rework #2797

Merged
merged 2 commits into from Apr 23, 2020
Merged

Barcode format rework #2797

merged 2 commits into from Apr 23, 2020

Conversation

jekkos
Copy link
Member

@jekkos jekkos commented Apr 17, 2020

This rework allows us to use barcode formats with the token system originally developed by @SteveIreland . Also an extra $price variable was added that can be used with a barcode scanner to fill in item parameters in sales and receivings directly.

Also added a couple of units tests to show how the functionality is working.

@jekkos jekkos self-assigned this Apr 18, 2020
Copy link
Member

@WebShells WebShells left a comment

Choose a reason for hiding this comment

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

For price barcode parsing... as set by the barcode format -> "02{P:2}{W:6}{I:3}"
Usually in digital scales, the price comes at the end of the barcode replacing W: so the final format will be something like 02{ID:5}{P:6} or as it was set before 02(\d{5})(\w{6}).
Setting the price for 2 digits might only work with USD currency so also might vary upto 5 or 6 digits.

@SteveIreland
Copy link
Collaborator

I started to test it, but when I entered the format @WebShells gave as an example ("02{P:2}{W:6}{I:3}") into the Input Format ended up being rendered as follows. Is this correct?
image

@WebShells
Copy link
Member

@SteveIreland I guess jekkos changed the format after the rework to "02{P:2}{W:6}{I:3}"
The old barcode format we used to set was 02(\d{5})(\w{6}) d standing for item barcode and w stands for weight/qty...

@@ -78,6 +78,24 @@ public function scan($text)
return $token_tree;
}

Copy link
Member

Choose a reason for hiding this comment

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

This is more a philosophical question than a statement. What are our best practices for function comments? I've been trying to generally use this (https://make.wordpress.org/core/handbook/best-practices/inline-documentation-standards/php/#1-functions-class-methods) but I noticed that it isn't consistent throughout the code. Should we be asking everyone to comment their non-obvious functions in PR's?

Copy link
Member Author

Choose a reason for hiding this comment

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

Well I would say better to have no comments at all (except if you really have no other choice). Code should be self explanatory where possible. Most of the time it's considered a code smell.
But for most php formatting I think we try to follow the CI guidelines.

@@ -78,6 +78,24 @@ public function scan($text)
return $token_tree;
}

public function parse_barcode(&$quantity, &$price, &$item_id_or_number_or_item_kit_or_receipt)
Copy link
Member

Choose a reason for hiding this comment

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

Is the reason for passing these by reference instead of a return value because there are multiple values being modified and you would have to put them into an array or object if you used return?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes indeed that's the reason.

@@ -0,0 +1,73 @@
<?php
Copy link
Member

Choose a reason for hiding this comment

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

Sorry, another philosophical question. Do we want to begin asking the PR submitter to have Unit Tests written when new methods are being submitted?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I would hope it would only be for areas that are delicate and complicated by configuration options so that we can have confidence that when someone makes a change in those areas that the appropriate unit tests can be run to cover all possible configuration permutations. I don't see a need to make simple changes so burdensome that we need to have unit tests for stuff that only have a single test scenario.

Copy link
Member Author

@jekkos jekkos Apr 20, 2020

Choose a reason for hiding this comment

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

I think that adding unit tests really adds a lot of value, we can only do it step by step from now on and it really helps to detect regressions early on, especially in more complex and critical sections of the code (eg calculations).

I think we should really try to add more unit tests. It's just a more effective way of writing code (test driven development) and validating features in the code. Probably not everything is testable in this project, like logic in the views is probably out of scope. But queries in the datamodel, functions in libraries and helpers all seem to be good and easy testable components.

@jekkos
Copy link
Member Author

jekkos commented Apr 20, 2020

I started to test it, but when I entered the format @WebShells gave as an example ("02{P:2}{W:6}{I:3}") into the Input Format ended up being rendered as follows. Is this correct?
image

Not sure if it works as expected, I'll have to review .

@jekkos jekkos merged commit 99fb550 into master Apr 23, 2020
@daN4cat daN4cat added this to the 3.3.2 milestone Apr 24, 2020
@objecttothis objecttothis deleted the barcode-format-rework branch May 8, 2020 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants