Skip to content

Commit

Permalink
[IMP] grap_change_email + grap_qweb_report : add new xlsx report file…
Browse files Browse the repository at this point in the history
… as attachment in purchase order mail template
  • Loading branch information
legalsylvain committed Nov 28, 2023
1 parent c3e231d commit 73648e7
Show file tree
Hide file tree
Showing 9 changed files with 263 additions and 13 deletions.
3 changes: 3 additions & 0 deletions grap_change_email/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
"depends": [
"purchase",
"sale",
# OCA
"mail_template_multi_attachment",
# GRAP
"sale_recovery_moment",
"grap_qweb_report",
],
"data": [
"data/mail_data.xml",
Expand Down
7 changes: 7 additions & 0 deletions grap_change_email/data/mail_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
</field>
</record>

<record id="email_template_purchase_order_report_xlsx" model="mail.template.report">
<field name="mail_template_id" ref="grap_change_email.email_template_purchase_order"/>
<field name="report_template_id" ref="grap_qweb_report.purchase_order_xlsx"/>
<field name="report_name">Bon_de_commande_${(object.name or '').replace('/','_')}</field>
</record>


<!--*********************************************************************** -->
<!--model sale.order - Bon de commande -->
<!--*********************************************************************** -->
Expand Down
2 changes: 2 additions & 0 deletions grap_qweb_report/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
# OCA
"pos_ticket_extra_company_info",
"pos_ticket_extra_company_info_l10n_fr",
"purchase_triple_discount",
"report_xlsx_helper",
# GRAP
"base_company_legal_info",
"fiscal_company_base",
Expand Down
13 changes: 13 additions & 0 deletions grap_qweb_report/data/ir_actions_report_xml.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,17 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
print_report_name="'Self-Adhesive Barcode Sheet - %s' % (object.name)"
paperformat="paperformat_grap_no_margin"
/>

<report
id="purchase_order_xlsx"
model="purchase.order"
string="Purchase Order (XLSX)"
report_type="xlsx"
name="report_xlsx.purchase_order_xlsx"
print_report_name="'Bon_de_commande__%s__%s' % (
object.partner_id.name.replace('&quot;', '_').replace('\'', '_').replace('/', '_'),
object.name.replace('/', '_')
)"

/>
</odoo>
67 changes: 65 additions & 2 deletions grap_qweb_report/i18n/fr.po
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * grap_qweb_report
# * grap_qweb_report
#
msgid ""
msgstr ""
Expand Down Expand Up @@ -148,7 +148,7 @@ msgstr "Anonyme"

#. module: grap_qweb_report
#. openerp-web
#: code:addons/grap_qweb_report/static/src/xml/pos.xml:109
#: code:addons/grap_qweb_report/static/src/xml/pos.xml:90
#, python-format
msgid "Base"
msgstr ""
Expand Down Expand Up @@ -226,13 +226,22 @@ msgid "Date de facture"
msgstr ""

#. module: grap_qweb_report
#: code:addons/grap_qweb_report/report/report_purchase_order_xlsx.py:53
#: model_terms:ir.ui.view,arch_db:grap_qweb_report.template_account_invoice
#, python-format
msgid "Description"
msgstr ""

#. module: grap_qweb_report
#: code:addons/grap_qweb_report/report/report_purchase_order_xlsx.py:82
#, python-format
msgid "Discount %s %%"
msgstr "Remise %s %%"

#. module: grap_qweb_report
#: model:ir.model.fields,field_description:grap_qweb_report.field_report_custom_message__display_name
#: model:ir.model.fields,field_description:grap_qweb_report.field_report_custom_message_mixin__display_name
#: model:ir.model.fields,field_description:grap_qweb_report.field_report_report_xlsx_purchase_order_xlsx__display_name
msgid "Display Name"
msgstr "Nom affiché"

Expand Down Expand Up @@ -306,6 +315,7 @@ msgstr "Hauteur du message, exprimé en pixel"
#. module: grap_qweb_report
#: model:ir.model.fields,field_description:grap_qweb_report.field_report_custom_message__id
#: model:ir.model.fields,field_description:grap_qweb_report.field_report_custom_message_mixin__id
#: model:ir.model.fields,field_description:grap_qweb_report.field_report_report_xlsx_purchase_order_xlsx__id
msgid "ID"
msgstr ""

Expand Down Expand Up @@ -341,6 +351,7 @@ msgstr "Facture__{number}__{partner}__{date}"
#. module: grap_qweb_report
#: model:ir.model.fields,field_description:grap_qweb_report.field_report_custom_message____last_update
#: model:ir.model.fields,field_description:grap_qweb_report.field_report_custom_message_mixin____last_update
#: model:ir.model.fields,field_description:grap_qweb_report.field_report_report_xlsx_purchase_order_xlsx____last_update
msgid "Last Modified on"
msgstr "Dernière modification le"

Expand Down Expand Up @@ -403,6 +414,12 @@ msgstr ""
msgid "Preview"
msgstr "Prévisualiser"

#. module: grap_qweb_report
#: code:addons/grap_qweb_report/report/report_purchase_order_xlsx.py:91
#, python-format
msgid "Price Subtotal VAT Excl."
msgstr "Sous Total HT"

#. module: grap_qweb_report
#. openerp-web
#: code:addons/grap_qweb_report/static/src/xml/pos.xml:52
Expand All @@ -416,6 +433,12 @@ msgstr "Liste de prix: "
msgid "Printed"
msgstr "Imprimée le"

#. module: grap_qweb_report
#: code:addons/grap_qweb_report/report/report_purchase_order_xlsx.py:47
#, python-format
msgid "Product Name"
msgstr "Nom Frs"

#. module: grap_qweb_report
#: model_terms:ir.ui.view,arch_db:grap_qweb_report.qweb_template_pricetag_normal_large
#: model_terms:ir.ui.view,arch_db:grap_qweb_report.qweb_template_pricetag_normal_small
Expand All @@ -428,6 +451,17 @@ msgstr ""
msgid "Purchase Order"
msgstr "Commande fournisseur"

#. module: grap_qweb_report
#: model:ir.actions.report,name:grap_qweb_report.purchase_order_xlsx
msgid "Purchase Order (XLSX)"
msgstr "Commande fournisseur (XLSX)"

#. module: grap_qweb_report
#: code:addons/grap_qweb_report/report/report_purchase_order_xlsx.py:59
#, python-format
msgid "Quantity"
msgstr "Quantité"

#. module: grap_qweb_report
#: model:ir.model.fields,field_description:grap_qweb_report.field_account_invoice__report_custom_message
#: model:ir.model.fields,field_description:grap_qweb_report.field_purchase_order__report_custom_message
Expand Down Expand Up @@ -493,6 +527,18 @@ msgstr ""
msgid "Transfer"
msgstr "Transfert"

#. module: grap_qweb_report
#: code:addons/grap_qweb_report/report/report_purchase_order_xlsx.py:65
#, python-format
msgid "Unit"
msgstr "Unité"

#. module: grap_qweb_report
#: code:addons/grap_qweb_report/report/report_purchase_order_xlsx.py:71
#, python-format
msgid "Unit Price"
msgstr "Prix Unitaire"

#. module: grap_qweb_report
#. openerp-web
#: code:addons/grap_qweb_report/static/src/xml/pos.xml:29
Expand Down Expand Up @@ -533,3 +579,20 @@ msgstr ""
#: model_terms:ir.ui.view,arch_db:grap_qweb_report.qweb_template_pricetag_square_small
msgid "le kilo"
msgstr ""

#. module: grap_qweb_report
#: code:addons/grap_qweb_report/report/report_purchase_order_xlsx.py:41
#, python-format
msgid "product Code"
msgstr ""

#. module: grap_qweb_report
#: model:ir.model,name:grap_qweb_report.model_report_report_xlsx_partner_xlsx
msgid "report.report_xlsx.partner_xlsx"
msgstr ""

#. module: grap_qweb_report
#: model:ir.model,name:grap_qweb_report.model_report_report_xlsx_purchase_order_xlsx
msgid "report.report_xlsx.purchase_order_xlsx"
msgstr ""

1 change: 1 addition & 0 deletions grap_qweb_report/report/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import report_purchase_order_xlsx
154 changes: 154 additions & 0 deletions grap_qweb_report/report/report_purchase_order_xlsx.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
from odoo import _, models


class PurchaseOrderXlsx(models.AbstractModel):
_name = "report.report_xlsx.purchase_order_xlsx"
_inherit = "report.report_xlsx.abstract"

def _define_custom_formats(self, workbook, orders):
currency = orders[0].currency_id
s_before = currency.symbol if currency.position == "before" else ""
s_after = " %s" % currency.symbol if currency.position == "after" else ""
currency_format = (
f"{f'{s_before}'}#,##0.{'0' * currency.decimal_places}{f'{s_after}'}"
)
self.format_currency_right = workbook.add_format(
{"align": "right", "num_format": currency_format}
)

def generate_xlsx_report(self, workbook, data, orders):
self._define_formats(workbook)
self._define_custom_formats(workbook, orders)
ws_params = self._get_ws_params(workbook, data, orders.mapped("order_line"))[0]

for order in orders:
ws_name = order.name
ws_name = self._check_ws_name(ws_name)
ws = workbook.add_worksheet(ws_name)
generate_ws_method = getattr(self, ws_params["generate_ws_method"])
generate_ws_method(workbook, ws, ws_params, data, order.order_line)

def _get_columns_spec(self, order_lines):
supplierinfo_render = (
"order_line.product_id.seller_ids.filtered("
"lambda x: x.name == order_line.order_id.partner_id "
" and (not x.product_id or x.product_id == order_line.product_id))"
".sorted(key=lambda x: x.min_qty)"
)
res = [
{
"name": "product_code",
"header_name": _("product Code"),
"data": self._render(f"{supplierinfo_render}.product_code or ''"),
"width": 20,
},
{
"name": "product_name",
"header_name": _("Product Name"),
"data": self._render(f"{supplierinfo_render}.product_name or ''"),
"width": 20,
},
{
"name": "name",
"header_name": _("Description"),
"data": self._render("order_line.name"),
"width": 20,
},
{
"name": "product_qty",
"header_name": _("Quantity"),
"data": self._render("order_line.product_qty"),
"width": 10,
},
{
"name": "product_uom",
"header_name": _("Unit"),
"data": self._render("order_line.product_uom.name"),
"width": 10,
},
{
"name": "price_unit",
"header_name": _("Unit Price"),
"data": self._render("order_line.price_unit"),
"format": self.format_currency_right,
"width": 10,
},
]
for i, field in enumerate(["discount", "discount2", "discount3"]):
if any(order_lines.mapped(field)):
res.append(

Check warning on line 79 in grap_qweb_report/report/report_purchase_order_xlsx.py

View check run for this annotation

Codecov / codecov/patch

grap_qweb_report/report/report_purchase_order_xlsx.py#L79

Added line #L79 was not covered by tests
{
"name": field,
"header_name": _("Discount %s %%" % (i + 1)),
"data": self._render(f"order_line.{field} / 100"),
"format": self.format_tcell_percent_right,
"width": 15,
}
)
res += [
{
"name": "price_subtotal",
"header_name": _("Price Subtotal VAT Excl."),
"data": self._render("order_line.price_subtotal"),
"format": self.format_currency_right,
"width": 20,
}
]

return res

def _get_ws_params(self, wb, data, order_lines):
columns_spec = self._get_columns_spec(order_lines)

order_line_template = {}
for spec in columns_spec:
order_line_template[spec["name"]] = {
"header": {
"value": spec["header_name"],
},
"data": {
"value": spec["data"],
"format": spec.get("format", False),
},
"width": spec["width"],
}

return [
{
"generate_ws_method": "_purchase_order_report",
"wanted_list": [x["name"] for x in columns_spec],
"col_specs": order_line_template,
}
]

def _purchase_order_report(self, workbook, ws, ws_params, data, order_lines):

ws.set_portrait()
ws.fit_to_pages(1, 0)
ws.set_header(self.xls_headers["standard"])
ws.set_footer(self.xls_footers["standard"])

self._set_column_width(ws, ws_params)

row_pos = 0
# row_pos = self._write_ws_title(ws, row_pos, ws_params)
row_pos = self._write_line(
ws,
row_pos,
ws_params,
col_specs_section="header",
default_format=self.format_theader_yellow_left,
)
ws.freeze_panes(row_pos, 0)

for order_line in order_lines:
row_pos = self._write_line(
ws,
row_pos,
ws_params,
col_specs_section="data",
render_space={
"order_line": order_line,
},
default_format=self.format_tcell_left,
)
Loading

0 comments on commit 73648e7

Please sign in to comment.