Issue 9603

Title
Can't strftime lang that value is None
Priority
bug
Status
invalid
Nosy list
ced, pokoli, resteve, reviewbot
Assigned to
resteve
Keywords
review

Created on 2020-09-16.15:10:51 by resteve, last changed yesterday by ced.

Messages

Author: [hidden] (ced) Tryton committer Tryton translator
Date: 2020-10-24.23:56:18

We are still missing a complete full traceback. It is not possible to understand nor reproduce the problem without it.
It's been 1 month since this was requested. I mark the issue as invalid, re-open it with a traceback.

Author: [hidden] (ced) Tryton committer Tryton translator
Date: 2020-09-17.10:36:04
On 2020-09-17 10:21, Sergi Almacellas Abellana wrote:
> Could you please share some steps to reproduce the issue on a fresh database?

The best is a minimal scenario that can be included as test.
Author: [hidden] (pokoli) Tryton committer Tryton translator
Date: 2020-09-17.10:21:59
Move effective_date is set before calling move._do:

https://hg.tryton.org/modules/stock/file/tip/move.py#l632

So reading the code the date should be always set. 

Could you please share some steps to reproduce the issue on a fresh database?
Author: [hidden] (resteve)
Date: 2020-09-17.10:12:02
Versions: 5.0, 5.2, 5.4, 5.6 and master.

Receibe a supplier shipment when the currency is not equal that the company currency.

Traceback:

 File "/trytond/modules/stock/move.py", line 588, in do
    cost_price = move._do()
  File "/trytond/modules/product_cost_fifo/move.py", line 134, in _do
    cost_price = self._compute_product_cost_price('in')
  File "/trytond/modules/product_cost_fifo/move.py", line 81, in _compute_product_cost_price
    product_cost_price)
  File "/trytond/modules/stock/move.py", line 507, in _compute_product_cost_price
    unit_price = self.get_cost_price(product_cost_price=product_cost_price)
  File "/trytond/modules/sale/stock.py", line 186, in get_cost_price
    return super().get_cost_price(product_cost_price=product_cost_price)
  File "/trytond/modules/stock/move.py", line 629, in get_cost_price
    self.company.currency, round=False)
  File "/trytond/modules/currency/currency.py", line 175, in compute
    date=lang.strftime(date)))
  File "/trytond/ir/lang.py", line 506, in strftime
    return value.strftime(format)
AttributeError: 'NoneType' object has no attribute 'strftime'

1. effective_date in stock.shipment.in is not required [1]

2. effective_date is write when done a shipment [2]

3. _compute_product_cost_price() method set "date" in the context [3] when do a stock.move (receive a supplier shipment)

IMHO the control that has date in the context is in currency module because we alert an user error that show the "date":

"""
No rate found for currency "%(currency)s" on "%(date)s".
"""

[1] https://github.com/tryton/stock/blob/develop/shipment.py#L72
[2] https://github.com/tryton/stock/blob/develop/shipment.py#L487
[3] https://github.com/tryton/stock/blob/5.2/move.py#L483



    with Transaction().set_context(date=self.effective_date):
Author: [hidden] (ced) Tryton committer Tryton translator
Date: 2020-09-16.23:28:20
I agree with @pokoli. A empty date in context is wrong and this is what should be fixed.
Author: [hidden] (pokoli) Tryton committer Tryton translator
Date: 2020-09-16.17:16:56
El 16/9/20 a les 17:11, Raimon Esteve ha escrit:
>> Could you post the full traceback? I will like to understand why the date is None.
> Because "context", the "date" is None.


Yes, I understood that. What I want to understand is why the code calling the currency convert has an empty date in the context. Could you please provide more details?
Author: [hidden] (resteve)
Date: 2020-09-16.17:11:53
> Could you post the full traceback? I will like to understand why the date is None.

Because "context", the "date" is None.
Author: [hidden] (pokoli) Tryton committer Tryton translator
Date: 2020-09-16.16:12:30
Could you post the full traceback? I will like to understand why the date is None.

I think it's better to set them instead of setting a wrong default value.
Author: [hidden] (resteve)
Date: 2020-09-16.15:18:07
review290971002
Author: [hidden] (resteve)
Date: 2020-09-16.15:10:51
1. Traceback:

  File "/home/xxxx/trytond/trytond/modules/stock/move.py", line 629, in get_cost_price
    self.company.currency, round=False)
  File "/home/xxxx/trytond/trytond/modules/currency/currency.py", line 172, in compute
    lang = Lang.get()
  File "/home/xxxx/trytond/trytond/ir/lang.py", line 506, in strftime
    return value.strftime(format)
AttributeError: 'NoneType' object has no attribute 'strftime'

2. Context

{'client': '61d2cf34-76b0-416b-b8fd-b6f8566a41ab', 'user_conform_groups': [], 'employee': None, 'company': 3, 'company.rec_name': 'xxxxx', 'language': 'es', 'language_direction': 'ltr', 'groups': [12, 64, 1, 11, 24, 31, 32, 44, 2, 27, 8, 35, 16, 78, 20, 17, 5, 22, 6, 51, 7, 49, 34, 83, 29, 9, 50, 85, 4, 13, 76, 59, 71, 73, 60, 74, 77, 80, 62, 72, 3, 57, 36, 52, 15, 79, 14, 86, 21, 75, 19, 84, 38, 18, 25, 30, 23, 28, 26, 37, 10, 33, 41], 'roles': [], 'locale': {'date': '%d/%m/%Y', 'grouping': [3, 3, 0], 'decimal_point': ',', 'thousands_sep': '.'}, '_check_access': False, '_request': {'remote_addr': '10.254.0.18', 'http_host': 'localhost:38400', 'scheme': 'http', 'is_secure': False}, 'with_childs': False, 'locations': [], 'stock_date_end': datetime.date(2020, 9, 16), 'date': None}

See that "date" is None

3. Reason:

date = Transaction().context.get('date', Date.today()) [1]

"date" is None and not set Date.today()

[1] https://github.com/tryton/currency/blob/develop/currency.py#L177
History
Date User Action Args
2020-10-24 23:56:18cedsetcomponent: - currency
messages: + msg61383
status: need-eg -> invalid
2020-09-17 10:51:51reviewbotsetmessages: + msg60184
2020-09-17 10:36:04cedsetmessages: + msg60181
2020-09-17 10:21:59pokolisetmessages: + msg60180
2020-09-17 10:12:02restevesetmessages: + msg60176
2020-09-16 23:28:20cedsetnosy: + ced
messages: + msg60168
2020-09-16 17:16:56pokolisetstatus: chatting -> need-eg
messages: + msg60153
2020-09-16 17:11:53restevesetmessages: + msg60152
2020-09-16 16:12:30pokolisetnosy: + pokoli
messages: + msg60151
2020-09-16 15:25:59reviewbotsetnosy: + reviewbot
messages: + msg60150

Showing 10 items. Show all history (warning: this could be VERY long)