Sale_secondary_unit module: picklist

Hello friends,
I managed to make the “sale_secondary_unit” work. Now I’d like to have a 2nd column in my picklist: weight. The first column contains
format_number(move.quantity, user.language, digits=move.unit_digits)
in the placeholder, to replace “move.quantity” by “move.weight” does not work. What would be the correct line?

Cheers,
Wolf

I guess the weight is the secondary unit, so you will need to format the move.secondary_quantity if there is a secondary unit.

True. Thank you for instant reply.

I created a new column for weight, copied the entry from the old column and changed quantity to secondary_quantity. Now when creating a picklist, I get this error:

Traceback (most recent call last):
  File "/trytond/wsgi.py", line 117, in dispatch_request
    return endpoint(request, **request.view_args)
  File "/trytond/protocols/dispatcher.py", line 47, in rpc
    return methods.get(request.rpc_method, _dispatch)(
  File "/trytond/wsgi.py", line 84, in auth_required
    return wrapped(*args, **kwargs)
  File "/trytond/protocols/wrappers.py", line 156, 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 2738, in execute
    return super(ShipmentReport, cls).execute(ids, data)
  File "/trytond/report/report.py", line 193, in execute
    oext, content = cls._execute(
  File "/trytond/report/report.py", line 207, in _execute
    return cls.convert(action, cls.render(action, report_context))
  File "/trytond/report/report.py", line 303, 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 240, in <Expression '__relatorio_escape_invalid_chars(format_number(move.secondary_quantity, user.language, digits=move.unit_digits))'>
  File "/trytond/report/report.py", line 435, in format_number
    return lang.format('%.' + str(digits) + 'f', value,
  File "/trytond/ir/lang.py", line 445, in format
    formatted = percent % value
TypeError: must be real number, not NoneType

Fault: must be real number, not NoneType

What’s wrong?

Cheers,
Wolf

You have some moves that does not have a secondary unit sot you must display the formatted value only if the value is not None.

Thank you, I understand. How would I do this?

You must add a statement like

<if test="move.secondary_quantity is not None">
<format_number(move.secondary_quantity, user.language, digits=move.secondary_unit_digits)> <move.secondary_unit.symbol>
</if>

Sorry having to bother you again. The entry in in the new .fodt file column now looks like this:

<if test="move.secondary_quantity is not None">
<format_number(move.secondary_quantity, user.language, digits=move.secondary_unit_digits)>
<move.secondary_unit.symbol>
</if>
  • so it’s four placeholders. Correct?

This is the error message produced:

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

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 1470, in __getattr__
    raise AttributeError('"%s" has no attribute "%s"' % (self, name))
AttributeError: "stock.move,418" has no attribute "secondary_quantity"

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 117, in dispatch_request
    return endpoint(request, **request.view_args)
  File "/trytond/protocols/dispatcher.py", line 47, in rpc
    return methods.get(request.rpc_method, _dispatch)(
  File "/trytond/wsgi.py", line 84, in auth_required
    return wrapped(*args, **kwargs)
  File "/trytond/protocols/wrappers.py", line 156, 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 2740, in execute
    return super(ShipmentReport, cls).execute(ids, data)
  File "/trytond/report/report.py", line 193, in execute
    oext, content = cls._execute(
  File "/trytond/report/report.py", line 207, in _execute
    return cls.convert(action, cls.render(action, report_context))
  File "/trytond/report/report.py", line 303, 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 621, in _flatten
    stream = _apply_directives(data[1], data[0], ctxt, vars)
  File "/genshi/template/base.py", line 276, in _apply_directives
    stream = directives[0](iter(stream), directives[1:], ctxt, **vars)
  File "/genshi/template/directives.py", line 411, in __call__
    value = _eval_expr(self.expr, 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 240, in <Expression 'move.secondary_quantity is not None'>
  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')(418) has no member named "secondary_quantity"

Fault: Pool().get('stock.move')(418) has no member named "secondary_quantity"

One day I’ll learn more about these to me absolutely cryptic characters…

Cheers,
Wolf

I think you have also to install modules/stock_secondary_unit: log

Right. After having installed stock_secondary_unit, the whole thing works.
Thank you very much to all of you for your time.

To sum it up:

  • you need installed the modules
    -stock_secondary_unit
    -purchase_secondary_unit
    -sale_secondary_unit (in case you want to deal with sales as well)
  • in “products”, you find the secondary unit under the “purchasers” (resp. “sellers”) tab
  • In your picklist template, you need to insert in a new column:
<if test="move.secondary_quantity is not None"> #checks if there is a secondary unit at all
<format_number(move.secondary_quantity, user.language, digits=move.secondary_unit_digits)> # inserts the number
<move.secondary_unit.symbol> # inserts the unit
</if>

(each line go into one placeholder box, without surrounding brackets <…>.

One question is remaining:
By now, I get two digits (xxx,00 g) as a result, but I do not need the digits following the comma. I found that I should be able to alter the digits by adding something like secondary_unit_digits = 0 to my trytond.conf. But it does not work for me. What’s going wrong?

Cheers,
Wolf

The number of digits for a quantity is defined on the unit used to measure it.

Thank you. Found these settings under
Product > Configuration > Units of Measure.
Works! ((:
Cheers,
Wolf

A post was split to a new topic: Select automatically a second unit

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