From ac148ced217169dba599e72da3b41e5a52af3476 Mon Sep 17 00:00:00 2001 From: adria Date: Wed, 24 Jul 2024 12:52:41 +0200 Subject: [PATCH 1/4] ADD template company banner --- poweremail_generic_template/__terp__.py | 1 + .../banner_generic_email_template_company.xml | 16 ++++++++++++++++ .../emails/generic/components/company/en.mako | 1 + .../emails/generic/components/footer/en.mako | 2 +- .../emails/generic/index.mako | 16 +++++++++++----- ...-0001_load_generic_template_company_banner.py | 14 ++++++++++++++ 6 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 poweremail_generic_template/data/banners/banner_generic_email_template_company.xml create mode 100644 poweremail_generic_template/emails/generic/components/company/en.mako create mode 100644 poweremail_generic_template/migrations/5.0.24.9.0/post-0001_load_generic_template_company_banner.py diff --git a/poweremail_generic_template/__terp__.py b/poweremail_generic_template/__terp__.py index c2ec593..482db27 100644 --- a/poweremail_generic_template/__terp__.py +++ b/poweremail_generic_template/__terp__.py @@ -18,6 +18,7 @@ "data/banners/banner_generic_email_template_body.xml", "data/banners/banner_generic_email_template_footer.xml", "data/banners/banner_generic_email_template_css.xml", + "data/banners/banner_generic_email_template_company.xml", ], "active": False, "installable": True diff --git a/poweremail_generic_template/data/banners/banner_generic_email_template_company.xml b/poweremail_generic_template/data/banners/banner_generic_email_template_company.xml new file mode 100644 index 0000000..8b1755b --- /dev/null +++ b/poweremail_generic_template/data/banners/banner_generic_email_template_company.xml @@ -0,0 +1,16 @@ + + + + + + diff --git a/poweremail_generic_template/emails/generic/components/company/en.mako b/poweremail_generic_template/emails/generic/components/company/en.mako new file mode 100644 index 0000000..f4d8c1b --- /dev/null +++ b/poweremail_generic_template/emails/generic/components/company/en.mako @@ -0,0 +1 @@ +object.company_id \ No newline at end of file diff --git a/poweremail_generic_template/emails/generic/components/footer/en.mako b/poweremail_generic_template/emails/generic/components/footer/en.mako index 4e9a37c..4502826 100644 --- a/poweremail_generic_template/emails/generic/components/footer/en.mako +++ b/poweremail_generic_template/emails/generic/components/footer/en.mako @@ -1,4 +1,4 @@ -<% company = object.company_id %> +<% company = env['company'] %>
diff --git a/poweremail_generic_template/emails/generic/index.mako b/poweremail_generic_template/emails/generic/index.mako index 3202411..bc7d6fd 100644 --- a/poweremail_generic_template/emails/generic/index.mako +++ b/poweremail_generic_template/emails/generic/index.mako @@ -3,9 +3,6 @@ from datetime import datetime from poweremail.poweremail_template import get_value -pool = object.pool -cursor = object._cr -uid = object._uid today = datetime.today().date().strftime('%Y-%m-%d') banner_o = pool.get('report.banner') @@ -15,8 +12,17 @@ banners = banner_o.get_report_banners( today, object.id, context={'lang': lang} ) -body_html = get_value(cursor, uid, object.id, message=banners['generic_email_template_body'], template=template, context={'lang': lang}) -footer_html = get_value(cursor, uid, object.id, message=banners['generic_email_template_footer'], template=template, context={'lang': lang}) +company = eval(banners['generic_email_template_company']) + +env['company'] = company +ctx = { + 'lang': lang, + 'raise_exception': True, +} +ctx.update(env) + +body_html = get_value(cursor, uid, object.id, message=banners['generic_email_template_body'], template=template, context=ctx) +footer_html = get_value(cursor, uid, object.id, message=banners['generic_email_template_footer'], template=template, context=ctx) %> diff --git a/poweremail_generic_template/migrations/5.0.24.9.0/post-0001_load_generic_template_company_banner.py b/poweremail_generic_template/migrations/5.0.24.9.0/post-0001_load_generic_template_company_banner.py new file mode 100644 index 0000000..227daa3 --- /dev/null +++ b/poweremail_generic_template/migrations/5.0.24.9.0/post-0001_load_generic_template_company_banner.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- +from oopgrade.oopgrade import load_data + + +def up(cursor, installed_version): + if not installed_version: + return + load_data(cursor, 'poweremail_generic_template', 'data/banners/banner_generic_email_template_company.xml') + + +def down(cursor, installed_version): + pass + +migrate = up \ No newline at end of file From b42d330b5edd78751873ff0d754bffee607ebb1f Mon Sep 17 00:00:00 2001 From: adria Date: Wed, 24 Jul 2024 14:20:20 +0200 Subject: [PATCH 2/4] FIX migration script --- .../data/banners/banner_generic_email_template_company.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/poweremail_generic_template/data/banners/banner_generic_email_template_company.xml b/poweremail_generic_template/data/banners/banner_generic_email_template_company.xml index 8b1755b..24fe265 100644 --- a/poweremail_generic_template/data/banners/banner_generic_email_template_company.xml +++ b/poweremail_generic_template/data/banners/banner_generic_email_template_company.xml @@ -9,8 +9,8 @@ no.required La compañia a la que hace referencia la plantilla - - + + From 5ed4eb2ef04b12723505e00d9e227ebe31fe1169 Mon Sep 17 00:00:00 2001 From: jperez Date: Mon, 29 Jul 2024 09:30:26 +0200 Subject: [PATCH 3/4] Add try except when get company and if company is false get company with id 1 --- poweremail_generic_template/emails/generic/index.mako | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/poweremail_generic_template/emails/generic/index.mako b/poweremail_generic_template/emails/generic/index.mako index bc7d6fd..00a3493 100644 --- a/poweremail_generic_template/emails/generic/index.mako +++ b/poweremail_generic_template/emails/generic/index.mako @@ -12,7 +12,13 @@ banners = banner_o.get_report_banners( today, object.id, context={'lang': lang} ) -company = eval(banners['generic_email_template_company']) +try: + company = eval(banners['generic_email_template_company']) +except: + company = False + +if not company: + company = pool.get('res.company').browse(cursor, uid, 1, context={}) env['company'] = company ctx = { From a21903005bd7345d04b232468ef3b6999a3d238f Mon Sep 17 00:00:00 2001 From: Luis Ka Date: Fri, 2 Aug 2024 13:29:06 +0200 Subject: [PATCH 4/4] imp: avoid redundant update --- .../post-0001_load_generic_template_company_banner.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/poweremail_generic_template/migrations/5.0.24.9.0/post-0001_load_generic_template_company_banner.py b/poweremail_generic_template/migrations/5.0.24.9.0/post-0001_load_generic_template_company_banner.py index 227daa3..10ec59b 100644 --- a/poweremail_generic_template/migrations/5.0.24.9.0/post-0001_load_generic_template_company_banner.py +++ b/poweremail_generic_template/migrations/5.0.24.9.0/post-0001_load_generic_template_company_banner.py @@ -1,9 +1,10 @@ # -*- coding: utf-8 -*- from oopgrade.oopgrade import load_data +from tools import config def up(cursor, installed_version): - if not installed_version: + if not installed_version or config.updating_all: return load_data(cursor, 'poweremail_generic_template', 'data/banners/banner_generic_email_template_company.xml')