Update > 6.4: picklist with 2nd unit does no longer work

Hello,
since my update from 6.0 > 6.2 > 6.4, creating picklists does no longer work. It seems “unit_digits” are still in use although abandoned… My .fodt and error message can be found here:

Traceback (most recent call last):
  File "/trytond/model/modelstorage.py", line 1583, in __getattr__
    field = self._fields[name]
KeyError: 'unit_digits'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/genshi/template/eval.py", line 301, in lookup_attr
    val = getattr(obj, key)
  File "/trytond/model/modelstorage.py", line 1585, in __getattr__
    raise AttributeError('"%s" has no attribute "%s"' % (self, name))
AttributeError: "stock.move,851" has no attribute "unit_digits"

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/genshi/template/eval.py", line 307, in lookup_attr
    val = obj[key]
TypeError: 'stock.move' object is not subscriptable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/trytond/wsgi.py", line 119, in dispatch_request
    return endpoint(request, **request.view_args)
  File "/trytond/protocols/dispatcher.py", line 46, in rpc
    return methods.get(request.rpc_method, _dispatch)(
  File "/trytond/wsgi.py", line 86, in auth_required
    return wrapped(*args, **kwargs)
  File "/trytond/protocols/wrappers.py", line 161, in wrapper
    return func(request, pool, *args, **kwargs)
  File "/trytond/protocols/dispatcher.py", line 181, in _dispatch
    result = rpc.result(meth(*c_args, **c_kwargs))
  File "/trytond/modules/stock/shipment.py", line 2737, in execute
    return super(ShipmentReport, cls).execute(ids, data)
  File "/trytond/report/report.py", line 227, in execute
    oext, content = cls._execute(
  File "/trytond/report/report.py", line 248, in _execute
    return cls.convert(action, cls.render(action, report_context))
  File "/trytond/report/report.py", line 345, in render
    data = template.generate(**report_context).render()
  File "/relatorio/templates/base.py", line 34, in render
    return self.serializer(
  File "/relatorio/templates/opendocument.py", line 1181, in __call__
    output_encode(
  File "/genshi/output.py", line 60, in encode
    for chunk in iterator:
  File "/genshi/output.py", line 243, in __call__
    for kind, data, pos in stream:
  File "/genshi/output.py", line 674, in __call__
    for kind, data, pos in stream:
  File "/genshi/output.py", line 779, in __call__
    for kind, data, pos in chain(stream, [(None, None, None)]):
  File "/genshi/output.py", line 598, in __call__
    for ev in stream:
  File "/relatorio/templates/opendocument.py", line 1074, in __call__
    for kind, data, pos in stream:
  File "/genshi/filters/i18n.py", line 688, in __call__
    for kind, data, pos in stream:
  File "/genshi/template/base.py", line 641, in _include
    for event in stream:
  File "/genshi/template/markup.py", line 326, in _match
    for event in stream:
  File "/genshi/template/base.py", line 601, in _flatten
    result = _eval_expr(data, ctxt, vars)
  File "/genshi/template/base.py", line 291, in _eval_expr
    retval = expr.evaluate(ctxt)
  File "/genshi/template/eval.py", line 160, in evaluate
    return eval(self.code, _globals, {'__data__': data})
  File "<string>", line 260, in <Expression '__relatorio_escape_invalid_chars(format_number(move.quantity, user.language, digits=move.unit_digits))'>
  File "/genshi/template/eval.py", line 309, in lookup_attr
    val = cls.undefined(key, owner=obj)
  File "/genshi/template/eval.py", line 397, in undefined
    raise UndefinedError(key, owner=owner)
genshi.template.eval.UndefinedError: Pool().get('stock.move')(851) has no member named "unit_digits"

Fault: Pool().get('stock.move')(851) has no member named "unit_digits"

Cheers,
Wolf

On your report you have the following:

format_number(move.quantity, user.language, digits=move.unit_digits)

But as you mention unit_digits is abandoned since issue10730 so you need to update your reports like in core reports:

format_number_symbol(move.quantity, user.language, move.uom, digits=move.uom.digits)

https://hg.tryton.org/modules/stock/file/6bd0f5c3f901/picking_list.fodt#l471

It’s still in use only on your custom modules, core modules are updated.

1 Like

Thank you very much for your so quick answer. I tried as written, but still get an error. My guess is that the 2nd unit column has to be changed as well. I tried change:

format_number(move.secondary_quantity, user.language, digits=move.secondary_unit_digits)

to

format_number_symbol(move.secondary_quantity, user.language, digits=move.secondary_unit.digits)

but that does not work as well. What’s my mistake?

Cheers,
Wolf

Yes, all unit_digits has to be replaced.
If you post your errors they are helpful to guide you better.
I think the error you are facing now it’s not about unit_digits, its about the format:

def format_number(
        cls, value, lang, digits=None, grouping=True, monetary=None):
def format_number_symbol(
        cls, value, lang, symbol, digits=None, grouping=True):

Source: trytond: 9e882eb7fbff trytond/report/report.py

As you can see format_number it’s not the same as format_number_symbol. format_number_symbol expects symbol parameter which in your change you did not provide. I would recommend to still use the same format_number as you originally have.

1 Like

Thank you again. I did as you said and changed:

format_number(move.secondary_quantity, user.language, digits=move.secondary_unit_digits)

to

format_number(move.secondary_quantity, user.language, digits=move.secondary_unit.digits)

Now I can picklist again. ((-:

Dummy users as I am would really be grateful it these hints would be in updating advice. And we would need it in a level of detail dummy users can understand. I know, that’s hard for you profs - but we’re very well willing to assist. (-;

Cheers,
Wolf

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.