Add location and date to inventory name

Closes #12188
This commit is contained in:
Maxime Richez
2023-06-09 09:15:31 +02:00
parent b4ab5413ac
commit df3aca4022
3 changed files with 35 additions and 1 deletions
+1
View File
@@ -1,3 +1,4 @@
* Add location and date to inventory name
Version 6.8.0 - 2023-05-01
--------------------------
+23 -1
View File
@@ -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() + [
@@ -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'