Skip to content

Instantly share code, notes, and snippets.

@simahawk
Created September 19, 2016 06:49
Show Gist options
  • Save simahawk/8825fc55da95624d73582703fdaa87e1 to your computer and use it in GitHub Desktop.
Save simahawk/8825fc55da95624d73582703fdaa87e1 to your computer and use it in GitHub Desktop.
Odoo - custom openchatter message on fields update
def _message_order_formatter(subj, line, changed, old):
"""Format mail msg for update order lines log.
@param subj: subject of the message
@param line: order line
@param changed: mapping of changed field values
@param old: mapping of old field values
"""
mess = subj + "<ul>"
for fname, value in changed.iteritems():
mess += """
<li>{label}: {old_value} -> {new_value}</li>
""".format(
# TODO: translate label
label=line._fields[fname].string,
old_value=old[fname],
new_value=value,
)
mess += "<ul>"
return mess
[...]
fnames = (
'name', 'product_id',
'product_uom', 'product_uom_qty',
)
changed = {}
current = self.order_line_id.read(
fnames, load='_classic_write')[0]
for fname in fnames:
if not current[fname] == line_values[fname]:
# build mapping of changed field
# values are ($old, $new)
changed[fname] = line_values[fname]
if changed:
self.order_line_id.write(changed)
subj = 'Line {} updated'.format(self.order_line_id.name)
self.order_id.message_post(
body=_message_order_formatter(
subj,
self.order_line_id,
changed,
current
),
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment