Purchase form

This commit is contained in:
2026-07-25 10:39:50 +02:00
parent 64390eaecb
commit 264ff534cf
3 changed files with 102 additions and 25 deletions

View File

@@ -1606,9 +1606,6 @@ class Log(ResourceAccessMixin, ModelSQL, ModelView):
return json.dumps(value, sort_keys=True, ensure_ascii=False)
if value in (None, ''):
return ''
if isinstance(value, str) and re.match(r'^-?\d+(\.\d+)?$', value):
value = value.rstrip('0').rstrip('.')
return value or '0'
return str(value)
@staticmethod
@@ -1619,14 +1616,27 @@ class Log(ResourceAccessMixin, ModelSQL, ModelView):
return label[:-1]
return label
def _nested_record_label(self, field, field_label, record_id):
record_label = self._singular_label(field_label)
if not self.resource:
return '%s %s' % (record_label, record_id)
records = list(getattr(self.resource, field.name, None) or [])
line_records = [
record for record in records
if getattr(record, 'type', 'line') == 'line']
ordered_records = line_records or records
for index, record in enumerate(ordered_records, 1):
if str(getattr(record, 'id', '')) == str(record_id):
return '%s %s' % (record_label, index)
return '%s %s' % (record_label, record_id)
def _format_nested_change_summary(
self, field_label, target_model, old_value, new_value):
self, field, field_label, target_model, old_value, new_value):
pool = Pool()
Field = pool.get('ir.model.field')
lines = []
if not isinstance(old_value, dict) or not isinstance(new_value, dict):
return lines
record_label = self._singular_label(field_label)
def record_sort_key(value):
try:
return int(value)
@@ -1645,14 +1655,63 @@ class Log(ResourceAccessMixin, ModelSQL, ModelView):
if child_old == child_new:
continue
child_label = Field.get_name(target_model, child_field)
lines.append('%s %s %s %s => %s' % (
record_label,
record_id,
lines.append('%s %s %s => %s' % (
self._nested_record_label(
field, field_label, record_id),
child_label,
self._format_change_value(child_old),
self._format_change_value(child_new)))
return lines
@staticmethod
def _iter_change_commands(value):
if not isinstance(value, list):
return
for item in value:
if isinstance(item, list) and item and isinstance(item[0], str):
command = item[0]
if len(item) >= 3:
yield command, item[1], item[2]
elif len(item) >= 2:
yield command, item[1], None
if value and all(isinstance(item, list) for item in value):
return
index = 0
while index < len(value):
command = value[index]
if not isinstance(command, str):
index += 1
continue
if command == 'write':
if index + 2 >= len(value):
break
yield command, value[index + 1], value[index + 2]
index += 3
continue
if index + 1 >= len(value):
break
yield command, value[index + 1], None
index += 2
def _format_command_change_summary(
self, field, field_label, target_model, new_value):
pool = Pool()
Field = pool.get('ir.model.field')
lines = []
for command, record_ids, values in self._iter_change_commands(
new_value) or []:
if command != 'write' or not isinstance(values, dict):
continue
for record_id in record_ids:
for child_field, child_value in sorted(values.items()):
child_label = Field.get_name(target_model, child_field)
lines.append('%s %s => %s' % (
self._nested_record_label(
field, field_label, record_id),
child_label,
self._format_change_value(child_value)))
return lines
def get_change_summary(self, name):
if self.event != 'write':
return ''
@@ -1673,14 +1732,21 @@ class Log(ResourceAccessMixin, ModelSQL, ModelView):
field_label = Field.get_name(model, field_name)
else:
field_label = field_name
field = getattr(self.resource.__class__, field_name, None)
field = (
getattr(self.resource.__class__, field_name, None)
if self.resource else None)
if field and hasattr(field, 'get_target'):
target_model = field.get_target().__name__
nested_lines = self._format_nested_change_summary(
field_label, target_model, old_value, new_value)
field, field_label, target_model, old_value, new_value)
if nested_lines:
lines.extend(nested_lines)
continue
command_lines = self._format_command_change_summary(
field, field_label, target_model, new_value)
if command_lines:
lines.extend(command_lines)
continue
lines.append('%s: %s -> %s' % (
field_label,
self._format_change_value(old_value),