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

[16.0] [MIG] stock_barcodes #587

Closed
wants to merge 195 commits into from

Conversation

FranzPoize
Copy link

No description provided.

@angelmoya
Copy link
Member

Functional testing:

Set Barcode options:
Odoo-Picking-IN-options

Set this barcode option on incoming picking type.

Configura one product tracking as serial number.

Purchase this product to create a incoming picking.

Go to incoming picking and get this error trying to open barcode interface:

Traceback (most recent call last):
File "/opt/odoo/odoo/http.py", line 1633, in _serve_db
return service_model.retrying(self._serve_ir_http, self.env)
File "/opt/odoo/odoo/service/model.py", line 133, in retrying
result = func()
File "/opt/odoo/odoo/http.py", line 1660, in _serve_ir_http
response = self.dispatcher.dispatch(rule.endpoint, args)
File "/opt/odoo/odoo/http.py", line 1864, in dispatch
result = self.request.registry['ir.http']._dispatch(endpoint)
File "/opt/odoo/odoo/addons/base/models/ir_http.py", line 154, in _dispatch
result = endpoint(**request.params)
File "/opt/odoo/odoo/http.py", line 697, in route_wrapper
result = endpoint(self, *args, **params_ok)
File "/opt/odoo/addons/web/controllers/dataset.py", line 46, in call_button
action = self._call_kw(model, method, args, kwargs)
File "/opt/odoo/addons/web/controllers/dataset.py", line 33, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/opt/odoo/odoo/api.py", line 468, in call_kw
result = _call_kw_multi(method, model, args, kwargs)
File "/opt/odoo/odoo/api.py", line 453, in _call_kw_multi
result = method(recs, *args, **kwargs)
File "/mnt/data/odoo-addons-dir/stock_barcodes/models/stock_picking.py", line 35, in action_barcode_scan
wiz.determine_todo_action()
File "/mnt/data/odoo-addons-dir/stock_barcodes/wizard/stock_barcodes_read_picking.py", line 188, in determine_todo_action
self.fill_todo_records()
File "/mnt/data/odoo-addons-dir/stock_barcodes/wizard/stock_barcodes_read_picking.py", line 181, in fill_todo_records
self.env["wiz.stock.barcodes.read.todo"].fill_records(self, [move_lines])
File "/mnt/data/odoo-addons-dir/stock_barcodes/wizard/stock_barcodes_read_todo.py", line 163, in fill_records
todo_vals[key] = self._prepare_fill_record_values(
File "/mnt/data/odoo-addons-dir/stock_barcodes/wizard/stock_barcodes_read_todo.py", line 88, in _prepare_fill_record_values
"product_uom_qty": line.product_uom_qty,
AttributeError: 'stock.move.line' object has no attribute 'product_uom_qty'

@FranzPoize FranzPoize marked this pull request as ready for review March 26, 2024 12:55
@FranzPoize FranzPoize force-pushed the 16.0-mig-stock_barcodes branch 2 times, most recently from 5afdd8a to e873c36 Compare March 27, 2024 09:17
@FranzPoize FranzPoize mentioned this pull request Mar 27, 2024
8 tasks
Copy link
Member

@chienandalu chienandalu left a comment

Choose a reason for hiding this comment

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

Hi @FranzPoize Thanks for your work here.

I didn't go deep into the python logic, although it looks correct at first sight.

As a general comment, I'm finding hard to review the changes in the javascript logic:

  • There are no diffs
  • There's missing documentation from the former code and for the new it isn't explained.
  • There are overrides that copy the original method (a thus the inheritance is broken for those)

Some more specific comments:

"author": "Tecnativa, " "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-logistics-barcode",
"license": "AGPL-3",
"category": "Extra Tools",
"depends": ["barcodes", "stock", "web_widget_numeric_step"],
"depends": ["barcodes", "stock", "web_widget_numeric_step", "web"],
Copy link
Member

Choose a reason for hiding this comment

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

web_widget_numeric_step already depends on web

</div>
<div class="col-2">
<span
class="pull-right text-right text-muted"
Copy link
Member

Choose a reason for hiding this comment

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

Review your bootstrap classes as they should be migrated to BS5: https://getbootstrap.com/docs/5.0/migration/

You've got some tooling in openupgradelib to analyze your view code: https://github.com/OCA/openupgradelib/blob/master/openupgradelib/openupgrade_160.py

/* Copyright 2022 Tecnativa - Alexandre D. Díaz
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */

const barcodeModels = [
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const barcodeModels = [
export const barcodeModels = [

Copy link
Author

Choose a reason for hiding this comment

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

Yes thank you !

];

export function isAllowedBarcodeModel(modelName) {
return barcodeModels.indexOf(modelName) !== -1;
Copy link
Member

Choose a reason for hiding this comment

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

A little bit more expressive:

Suggested change
return barcodeModels.indexOf(modelName) !== -1;
return barcodeModels.includes(modelName);

Copy link
Author

Choose a reason for hiding this comment

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

Thank you ! Changed

Copy link
Member

Choose a reason for hiding this comment

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

Organize these source files at leat in functionality folders so it's more clear where to look what

Copy link
Author

@FranzPoize FranzPoize Apr 3, 2024

Choose a reason for hiding this comment

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

Tried to. Tell me if you thinks that's better

"wiz.stock.barcodes.read.todo",
];

export function isAllowedBarcodeModel(modelName) {
Copy link
Member

Choose a reason for hiding this comment

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

This also had a docstring

Copy link
Author

Choose a reason for hiding this comment

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

Added

import {registry} from "@web/core/registry";

class BarcodeBooleanToggleField extends BooleanToggleField {
onChange(newValue) {
Copy link
Member

Choose a reason for hiding this comment

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

Missing documentation from the original here as well where it was stated why this was needed...

Copy link
Author

Choose a reason for hiding this comment

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

Added !

import {patch} from "@web/core/utils/patch";

patch(FormController.prototype, "Allow display.controlPanel overriding", {
setup() {
Copy link
Member

Choose a reason for hiding this comment

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

Docs missing here as well

Copy link
Author

Choose a reason for hiding this comment

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

Added !

Comment on lines 67 to 81
// eslint-disable-next-line complexity
focusNextCard(area, direction) {
const {isGrouped} = this.props.list;
const closestCard = document.activeElement.closest(".o_kanban_record");
if (!closestCard) {
return;
}
const groups = isGrouped
? [...area.querySelectorAll(".o_kanban_group")]
: [area];
let cards = [...groups]
.map((group) => [...group.querySelectorAll(".o_kanban_record")])
.filter((group) => group.length);

if (isAllowedBarcodeModel(this.props.list.resModel)) {
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 yo need to copy the whole method if you're returning in the middle of it? Maybe you have to repeat some of it if it's encapsulated, but in the end you should try to return super. Just evaluate this first, and repeat as less as possible

Copy link
Author

Choose a reason for hiding this comment

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

The code is not returning in the if statement it's recomputing the cards variable.
I could call super and return its value but I would still have duplicate that code because nothing is returned from the parent function. I still need to compute the candidate cards still filter them and focus the correct one.

If you have a way to do it better I would need more information because I'm not sure how to go about it.

Comment on lines 14 to 16
const rootRef = useRef("root");
useHotkey(
"Enter",
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 this?

Copy link
Author

Choose a reason for hiding this comment

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

Not sure what you're referring to ? the rootRef or the useHotkey ?

@FranzPoize
Copy link
Author

FranzPoize commented Apr 3, 2024

Thank you @chienandalu for your review

  • There are no diffs

Yes unfortunately the differences in behavior between the legacy front and owl are truly unreconcialable...
First of all the file name are changed to use the new odoo-module.
Also for example most of the logic for hotkey management was in kanban renderer. In the new frontend there can be many kanban renderer instances which would have registered their own global management of hotkey this needed to be completely refactored.

  • There's missing documentation from the former code and for the new it isn't explained.

I hope it's fixed in the latest push

  • There are overrides that copy the original method (a thus the inheritance is broken for those)

Yes that is not inevitable but is the least ugly way to do what needs to be done I'll go in more detail in the review comment

Copy link
Member

@chienandalu chienandalu left a comment

Choose a reason for hiding this comment

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

Thanks @FranzPoize take also in consideration that there are lots of recent changes in the 15.0 that should be included as a base to the migration as well...

Copy link
Member

@chienandalu chienandalu left a comment

Choose a reason for hiding this comment

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

Also testing a manual entry, I found this error

File "/opt/odoo/auto/addons/stock_barcodes/wizard/stock_barcodes_read.py", line 744, in action_confirm
    res = self.action_done()
  File "/opt/odoo/auto/addons/stock_barcodes/wizard/stock_barcodes_read_picking.py", line 269, in action_done
    ).action_done()
  File "/opt/odoo/auto/addons/stock_barcodes/wizard/stock_barcodes_read.py", line 547, in action_done
    if not self.check_done_conditions():
  File "/opt/odoo/auto/addons/stock_barcodes/wizard/stock_barcodes_read_picking.py", line 670, in check_done_conditions
    and float_compare(
  File "/opt/odoo/custom/src/odoo/odoo/tools/float_utils.py", line 155, in float_compare
    rounding_factor = _float_check_precision(precision_digits=precision_digits,
  File "/opt/odoo/custom/src/odoo/odoo/tools/float_utils.py", line 29, in _float_check_precision
    assert precision_rounding is None or precision_rounding > 0,\
AssertionError: precision_rounding must be positive, got 0.0

The above server error caused the following client error:
RPC_ERROR: Odoo Server Error
    at makeErrorFromResponse (http://localhost:16069/web/assets/3930-e51fdb0/web.assets_backend.min.js:993:163)
    at XMLHttpRequest.<anonymous> (http://localhost:16069/web/assets/3930-e51fdb0/web.assets_backend.min.js:1001:13)

@FranzPoize
Copy link
Author

FranzPoize commented Apr 3, 2024

Yes this PR includes all the changes up to 28th of february not sure I'll have the bandwidth to add the more recent changes if somebody can help with that I'd be glad.

I'll fix the codecov issue

@chienandalu
Copy link
Member

Yes this PR includes all the changes up to 28th of february not sure I'll have the bandwidth to add the more recent changes if somebody can help with that I'd be glad.

I'll fix the codecov issue

We can do this: finish your ongoing fixes and then we can supersed the migration from the 15.0 branch and putting on top your migration commit fixing conflicts and finishing whatever needs to be fixed from there. What do you think?

}

def _create_new_lot(self):
StockProductionLot = self.env["stock.production.lot"]

Choose a reason for hiding this comment

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

Hi, you need to change this model to stock.lot

    StockProductionLot = self.env["stock.lot"]

@chienandalu
Copy link
Member

Hi, @FranzPoize what do you think about what I proposed?:

We can do this: finish your ongoing fixes and then we can supersed the migration from the 15.0 branch and putting on top your migration commit fixing conflicts and finishing whatever needs to be fixed from there. What do you think?

@FranzPoize FranzPoize force-pushed the 16.0-mig-stock_barcodes branch 2 times, most recently from 7ed52ba to 5f4dde5 Compare April 19, 2024 15:33
weblate and others added 11 commits April 19, 2024 17:40
Updated by "Update PO files to match POT (msgmerge)" hook in Weblate.

Translation: stock-logistics-barcode-15.0/stock-logistics-barcode-15.0-stock_barcodes
Translate-URL: https://translation.odoo-community.org/projects/stock-logistics-barcode-15-0/stock-logistics-barcode-15-0-stock_barcodes/
…t create lot option is checked.

Display notification for required field.
Updated by "Update PO files to match POT (msgmerge)" hook in Weblate.

Translation: stock-logistics-barcode-15.0/stock-logistics-barcode-15.0-stock_barcodes
Translate-URL: https://translation.odoo-community.org/projects/stock-logistics-barcode-15-0/stock-logistics-barcode-15-0-stock_barcodes/
Updated by "Update PO files to match POT (msgmerge)" hook in Weblate.

Translation: stock-logistics-barcode-15.0/stock-logistics-barcode-15.0-stock_barcodes
Translate-URL: https://translation.odoo-community.org/projects/stock-logistics-barcode-15-0/stock-logistics-barcode-15-0-stock_barcodes/
@FranzPoize
Copy link
Author

@chienandalu
I'm having a real trouble figuring how the code works.

When you use the barcode button on a picking type. It calls action_barcode_scan on the stock_picking_type models there is 3 methods that are called:

  • create
  • determine_todo_action
  • fill_pending_moves
  1. First called is create this call set_candidate_picking if there is a picking_id but there is no picking_id in the parameters (even when we click on the new button on a picking type). It then calls action_show_step which sets the correct step because most filled_default are still correctly set (by _prepare_barcode_wiz_vals)

  2. Second is determine_todo_action, if the barcode option is guided, this calls fill_todo_records if there is no todo_line_ids (and there isn't) which calls _get_stock_move_lines. Since there is no picking_id, _get_stock_move_lines has to return an empty list. In this method all the default are filled but since there is no todo_line_ids all those value are set to empty sets. This then calls action_show_step again which remove the properly set step because the default value are now all empty.

  3. Third a call to fill_pending_moves this call fill_todo_records again which still does nothing.

So during action_barcode_scan:

  • create sets the proper default values
  • action_show_step is called twice once it sets a step (during) create and the second time it undoes what it did because determine_todo_action unset all the default values
  • fill_todo_records is called twice and twice it does nothing

This means no step at the end in some case (which are real convoluted but not so much).

  • Set the barcode option as guided
  • Leave no step with a step number of 0 (if a step with a 0 selected is action_show_step it will trigger the lineself.step = options_required[:1].stepbecause not 0 is True).
  • And click on the barcode of the picking_type

Or simpler use the demo Picking internals barcode option on internal transfer and click on the barcode on the internal transfer picking type.

@rousseldenis
Copy link
Sponsor Contributor

/ocabot migration stock_barcodes

@FranzPoize
Copy link
Author

Found the commit that adds a new call to action_show_step in determine_todo_action 50b0c67

This seems to break the option/step finding since if there is no todo_line_ids ,which there isn't in all case where you click on a barcode button on a picking type.

My question is it suppose to work without a picking_id in the stock_barcodes_read_picking ? There is a picking_ids field but it is not used anywhere in the code.

@chienandalu @sergio-teruel

@pedrobaeza
Copy link
Member

To be taken into account: #605

@FranzPoize
Copy link
Author

FranzPoize commented May 2, 2024 via email

@sergio-teruel
Copy link

To be taken into account: #604

@sergio-teruel
Copy link

@chienandalu I'm having a real trouble figuring how the code works.

When you use the barcode button on a picking type. It calls action_barcode_scan on the stock_picking_type models there is 3 methods that are called:

  • create
  • determine_todo_action
  • fill_pending_moves
  1. First called is create this call set_candidate_picking if there is a picking_id but there is no picking_id in the parameters (even when we click on the new button on a picking type). It then calls action_show_step which sets the correct step because most filled_default are still correctly set (by _prepare_barcode_wiz_vals)
  2. Second is determine_todo_action, if the barcode option is guided, this calls fill_todo_records if there is no todo_line_ids (and there isn't) which calls _get_stock_move_lines. Since there is no picking_id, _get_stock_move_lines has to return an empty list. In this method all the default are filled but since there is no todo_line_ids all those value are set to empty sets. This then calls action_show_step again which remove the properly set step because the default value are now all empty.
  3. Third a call to fill_pending_moves this call fill_todo_records again which still does nothing.

So during action_barcode_scan:

  • create sets the proper default values
  • action_show_step is called twice once it sets a step (during) create and the second time it undoes what it did because determine_todo_action unset all the default values
  • fill_todo_records is called twice and twice it does nothing

This means no step at the end in some case (which are real convoluted but not so much).

  • Set the barcode option as guided
  • Leave no step with a step number of 0 (if a step with a 0 selected is action_show_step it will trigger the lineself.step = options_required[:1].stepbecause not 0 is True).
  • And click on the barcode of the picking_type

Or simpler use the demo Picking internals barcode option on internal transfer and click on the barcode on the internal transfer picking type.

The next week in Spanish OCA days we will work about it...

@pedrobaeza
Copy link
Member

Superseded by #610, that was the result of the Spanish OCA days,

@pedrobaeza pedrobaeza closed this May 13, 2024
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