From df3aca402259e623d665e0480c9dfa2053b6b947 Mon Sep 17 00:00:00 2001 From: Maxime Richez Date: Fri, 9 Jun 2023 09:15:31 +0200 Subject: [PATCH] Add location and date to inventory name Closes #12188 --- modules/stock/CHANGELOG | 1 + modules/stock/inventory.py | 24 ++++++++++++++++++- .../stock/tests/scenario_stock_inventory.rst | 11 +++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/modules/stock/CHANGELOG b/modules/stock/CHANGELOG index 31b7e6f6ff..328f96bdeb 100644 --- a/modules/stock/CHANGELOG +++ b/modules/stock/CHANGELOG @@ -1,3 +1,4 @@ +* Add location and date to inventory name Version 6.8.0 - 2023-05-01 -------------------------- diff --git a/modules/stock/inventory.py b/modules/stock/inventory.py index bf58f320dc..21ec8aa531 100644 --- a/modules/stock/inventory.py +++ b/modules/stock/inventory.py @@ -8,7 +8,7 @@ from trytond.model import ( from trytond.model.exceptions import AccessError from trytond.pool import Pool from trytond.pyson import Bool, Eval, If -from trytond.tools import grouped_slice +from trytond.tools import grouped_slice, is_full_text, lstrip_wildcard from trytond.transaction import Transaction from trytond.wizard import Button, StateTransition, StateView, Wizard @@ -123,6 +123,28 @@ class Inventory(Workflow, ModelSQL, ModelView): def default_company(): return Transaction().context.get('company') + def get_rec_name(self, name): + pool = Pool() + Lang = pool.get('ir.lang') + lang = Lang.get() + date = lang.strftime(self.date) + return f"[{self.number}] {self.location.rec_name} @ {date}" + + @classmethod + def search_rec_name(cls, name, clause): + _, operator, operand, *extra = clause + if operator.startswith('!') or operator.startswith('not '): + bool_op = 'AND' + else: + bool_op = 'OR' + number_value = operand + if operator.endswith('like') and is_full_text(operand): + number_value = lstrip_wildcard(operand) + return [bool_op, + ('number', operator, number_value, *extra), + ('location.rec_name', operator, operand, *extra), + ] + @classmethod def view_attributes(cls): return super().view_attributes() + [ diff --git a/modules/stock/tests/scenario_stock_inventory.rst b/modules/stock/tests/scenario_stock_inventory.rst index 43621cb5e4..e5d1275449 100644 --- a/modules/stock/tests/scenario_stock_inventory.rst +++ b/modules/stock/tests/scenario_stock_inventory.rst @@ -245,3 +245,14 @@ Create an inventory that should be empty after completion:: >>> inventory.click('complete_lines') >>> len(inventory.lines) 0 + +Create an inventory and check rec_name:: + + >>> Inventory = Model.get('stock.inventory') + >>> inventory = Inventory() + >>> inventory.date = dt.date(2023, 1, 31) + >>> inventory.location = storage_loc + >>> inventory.empty_quantity = 'keep' + >>> inventory.save() + >>> inventory.rec_name + '[6] Storage Zone @ 01/31/2023'