[FIX] *: markupify python content
Will require a lot more conversions for this to work..
This commit is contained in:
@@ -4,6 +4,8 @@ from datetime import datetime, time
|
||||
from dateutil.relativedelta import relativedelta
|
||||
from functools import partial
|
||||
from itertools import groupby
|
||||
|
||||
from markupsafe import escape, Markup
|
||||
from pytz import timezone, UTC
|
||||
from werkzeug.urls import url_encode
|
||||
|
||||
@@ -308,9 +310,6 @@ class PurchaseOrder(models.Model):
|
||||
def onchange_partner_id_warning(self):
|
||||
if not self.partner_id or not self.env.user.has_group('purchase.group_warning_purchase'):
|
||||
return
|
||||
warning = {}
|
||||
title = False
|
||||
message = False
|
||||
|
||||
partner = self.partner_id
|
||||
|
||||
@@ -705,7 +704,7 @@ class PurchaseOrder(models.Model):
|
||||
raise_exception=False,
|
||||
email_values={'email_to': self.env.user.email, 'recipient_ids': []},
|
||||
notif_layout="mail.mail_notification_paynow")
|
||||
return {'toast_message': _("A sample email has been sent to %s.") % self.env.user.email}
|
||||
return {'toast_message': escape(_("A sample email has been sent to %s.", self.env.user.email))}
|
||||
|
||||
def _send_reminder_open_composer(self,template_id):
|
||||
self.ensure_one()
|
||||
@@ -776,7 +775,7 @@ class PurchaseOrder(models.Model):
|
||||
if order.state in ['purchase', 'done'] and not order.mail_reminder_confirmed:
|
||||
order.mail_reminder_confirmed = True
|
||||
date = confirmed_date or self.date_planned.date()
|
||||
order.message_post(body="%s confirmed the receipt will take place on %s." % (order.partner_id.name, date))
|
||||
order.message_post(body=_("%s confirmed the receipt will take place on %s.", order.partner_id.name, date))
|
||||
|
||||
def _approval_allowed(self):
|
||||
"""Returns whether the order qualifies to be approved by the current user"""
|
||||
@@ -793,7 +792,7 @@ class PurchaseOrder(models.Model):
|
||||
for order in self:
|
||||
if order.state in ['purchase', 'done'] and not order.mail_reception_confirmed:
|
||||
order.mail_reception_confirmed = True
|
||||
order.message_post(body="The order receipt has been acknowledged by %s." % order.partner_id.name)
|
||||
order.message_post(body=_("The order receipt has been acknowledged by %s.", order.partner_id.name))
|
||||
|
||||
def _update_date_planned_for_lines(self, updated_dates):
|
||||
# create or update the activity
|
||||
@@ -812,9 +811,14 @@ class PurchaseOrder(models.Model):
|
||||
line._update_date_planned(date)
|
||||
|
||||
def _create_update_date_activity(self, updated_dates):
|
||||
note = _('<p> %s modified receipt dates for the following products:</p>') % self.partner_id.name
|
||||
note = Markup('<p>%s</p>\n') % _('%s modified receipt dates for the following products:', self.partner_id.name)
|
||||
for line, date in updated_dates:
|
||||
note += _('<p> - %s from %s to %s </p>') % (line.product_id.display_name, line.date_planned.date(), date.date())
|
||||
note += Markup('<p> - %s</p>\n') % _(
|
||||
'%(product)s from %(original_receipt_date)s to %(new_receipt_date)s',
|
||||
product=line.product_id.display_name,
|
||||
original_receipt_date=line.date_planned.date(),
|
||||
new_receipt_date=date.date()
|
||||
)
|
||||
activity = self.activity_schedule(
|
||||
'mail.mail_activity_data_warning',
|
||||
summary=_("Date Updated"),
|
||||
@@ -828,7 +832,12 @@ class PurchaseOrder(models.Model):
|
||||
|
||||
def _update_update_date_activity(self, updated_dates, activity):
|
||||
for line, date in updated_dates:
|
||||
activity.note += _('<p> - %s from %s to %s </p>') % (line.product_id.display_name, line.date_planned.date(), date.date())
|
||||
activity.note += Markup('<p> - %s</p>\n') % _(
|
||||
'%(product)s from %(original_receipt_date)s to %(new_receipt_date)s',
|
||||
product=line.product_id.display_name,
|
||||
original_receipt_date=line.date_planned.date(),
|
||||
new_receipt_date=date.date()
|
||||
)
|
||||
|
||||
|
||||
class PurchaseOrderLine(models.Model):
|
||||
|
||||
@@ -159,7 +159,8 @@ class TestPurchase(AccountTestInvoicingCommon):
|
||||
])
|
||||
self.assertTrue(activity)
|
||||
self.assertIn(
|
||||
'<p> partner_a modified receipt dates for the following products:</p><p> \xa0 - product_a from 2020-06-06 to %s </p>' % fields.Date.today(),
|
||||
'<p>partner_a modified receipt dates for the following products:</p>\n'
|
||||
'<p> - product_a from 2020-06-06 to %s</p>' % fields.Date.today(),
|
||||
activity.note,
|
||||
)
|
||||
|
||||
@@ -167,6 +168,8 @@ class TestPurchase(AccountTestInvoicingCommon):
|
||||
po._update_date_planned_for_lines([(po.order_line[1], fields.Datetime.today())])
|
||||
self.assertEqual(po.order_line[1].date_planned, fields.Datetime.today())
|
||||
self.assertIn(
|
||||
'<p> partner_a modified receipt dates for the following products:</p><p> \xa0 - product_a from 2020-06-06 to %s </p><p> \xa0 - product_b from 2020-06-06 to %s </p>' % (fields.Date.today(), fields.Date.today()),
|
||||
'<p>partner_a modified receipt dates for the following products:</p>\n'
|
||||
'<p> - product_a from 2020-06-06 to %(today)s</p>\n'
|
||||
'<p> - product_b from 2020-06-06 to %(today)s</p>' % {'today': fields.Date.today()},
|
||||
activity.note,
|
||||
)
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
from markupsafe import Markup
|
||||
from dateutil.relativedelta import relativedelta
|
||||
|
||||
from odoo import api, fields, models, SUPERUSER_ID, _
|
||||
from odoo.tools.float_utils import float_compare
|
||||
from datetime import datetime
|
||||
from dateutil.relativedelta import relativedelta
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
from odoo.addons.purchase.models.purchase import PurchaseOrder as Purchase
|
||||
@@ -241,11 +242,12 @@ class PurchaseOrder(models.Model):
|
||||
"""
|
||||
validated_picking = self.picking_ids.filtered(lambda p: p.state == 'done')
|
||||
if validated_picking:
|
||||
activity.note += _("<p>Those dates couldn’t be modified accordingly on the receipt %s which had already been validated.</p>") % validated_picking[0].name
|
||||
message = _("Those dates couldn’t be modified accordingly on the receipt %s which had already been validated.", validated_picking[0].name)
|
||||
elif not self.picking_ids:
|
||||
activity.note += _("<p>Corresponding receipt not found.</p>")
|
||||
message = _("Corresponding receipt not found.")
|
||||
else:
|
||||
activity.note += _("<p>Those dates have been updated accordingly on the receipt %s.</p>") % self.picking_ids[0].name
|
||||
message = _("Those dates have been updated accordingly on the receipt %s.", self.picking_ids[0].name)
|
||||
activity.note += Markup('<p>{}</p>').format(message)
|
||||
|
||||
def _create_update_date_activity(self, updated_dates):
|
||||
activity = super()._create_update_date_activity(updated_dates)
|
||||
@@ -255,7 +257,7 @@ class PurchaseOrder(models.Model):
|
||||
# remove old picking info to update it
|
||||
note_lines = activity.note.split('<p>')
|
||||
note_lines.pop()
|
||||
activity.note = '<p>'.join(note_lines)
|
||||
activity.note = Markup('<p>').join(note_lines)
|
||||
super()._update_update_date_activity(updated_dates, activity)
|
||||
self._add_picking_info(activity)
|
||||
|
||||
|
||||
@@ -229,8 +229,10 @@ class TestPurchaseOrder(ValuationReconciliationTestCommon):
|
||||
('res_id', '=', po.id),
|
||||
])
|
||||
self.assertTrue(activity)
|
||||
self.assertIn(
|
||||
'<p> partner_a modified receipt dates for the following products:</p><p> \xa0 - Large Desk from %s to %s </p><p>Those dates have been updated accordingly on the receipt %s.</p>' % (today.date(), tomorrow.date(), po.picking_ids.name),
|
||||
self.assertEqual(
|
||||
'<p>partner_a modified receipt dates for the following products:</p>\n'
|
||||
'<p> - Large Desk from %s to %s</p>\n'
|
||||
'<p>Those dates have been updated accordingly on the receipt %s.</p>' % (today.date(), tomorrow.date(), po.picking_ids.name),
|
||||
activity.note,
|
||||
)
|
||||
|
||||
@@ -243,8 +245,12 @@ class TestPurchaseOrder(ValuationReconciliationTestCommon):
|
||||
old_date = po.order_line[1].date_planned
|
||||
po._update_date_planned_for_lines([(po.order_line[1], tomorrow)])
|
||||
self.assertEqual(po.order_line[1].date_planned, old_date)
|
||||
self.assertIn(
|
||||
'<p> partner_a modified receipt dates for the following products:</p><p> \xa0 - Large Desk from %s to %s </p><p> \xa0 - Conference Chair from %s to %s </p><p>Those dates couldn’t be modified accordingly on the receipt %s which had already been validated.</p>' % (today.date(), tomorrow.date(), today.date(), tomorrow.date(), po.picking_ids.name),
|
||||
self.assertEqual(
|
||||
'<p>partner_a modified receipt dates for the following products:</p>\n'
|
||||
'<p> - Large Desk from %s to %s</p>\n'
|
||||
'<p> - Conference Chair from %s to %s</p>\n'
|
||||
'<p>Those dates couldn’t be modified accordingly on the receipt %s which had already been validated.</p>' % (
|
||||
today.date(), tomorrow.date(), today.date(), tomorrow.date(), po.picking_ids.name),
|
||||
activity.note,
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user