Skip to content

Commit

Permalink
Merge pull request #64 from kmee/feature/15.0-sale_order_pos_report
Browse files Browse the repository at this point in the history
[IMP] sale_order_pos_report: add button to show pdf in another tab.
  • Loading branch information
mileo authored Oct 29, 2024
2 parents ad41a83 + c727f36 commit 6d7e6c3
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions sale_order_pos_report/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import models
from . import controllers
1 change: 1 addition & 0 deletions sale_order_pos_report/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"sale",
],
"data": [
"views/sale_order.xml",
"views/res_config_settings.xml",
"report/report_saleorder_compact.xml",
"report/sale_report.xml",
Expand Down
1 change: 1 addition & 0 deletions sale_order_pos_report/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import sale_order_pos_report
20 changes: 20 additions & 0 deletions sale_order_pos_report/controllers/sale_order_pos_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from odoo import http
from odoo.http import request


class SaleOrderPosController(http.Controller):
@http.route("/sale_order_pos_report/<int:sale_order_id>", type="http", auth="user")
def store_ticket_report(self, sale_order_id, **post):
sale_order = request.env["sale.order"].browse(sale_order_id)
if not sale_order.exists():
return request.not_found()

pdf = request.env.ref(
"sale_order_pos_report.action_report_saleorder_compact"
)._render_qweb_pdf(sale_order.ids)[0]
response = request.make_response(pdf)
response.headers["Content-Type"] = "application/pdf"
response.headers[
"Content-Disposition"
] = f'inline; filename="sale_order_{sale_order_id}.pdf"'
return response
1 change: 1 addition & 0 deletions sale_order_pos_report/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from . import res_config_settings
from . import res_company
from . import sale_order
17 changes: 17 additions & 0 deletions sale_order_pos_report/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2024 KMEE
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import models


class SaleOrder(models.Model):

_inherit = "sale.order"

def action_pos_report(self):
self.ensure_one()
return {
"type": "ir.actions.act_url",
"url": f"/sale_order_pos_report/{self.id}",
"target": "new",
}
21 changes: 21 additions & 0 deletions sale_order_pos_report/views/sale_order.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2024 KMEE
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>
<record id="view_order_form" model="ir.ui.view">
<field name="name">sale.order.form (sale_order_pos_report)</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form" />
<field name="arch" type="xml">
<xpath expr="//header" position="inside">
<button
name="action_pos_report"
string="POS Print"
type="object"
class="oe_highlight"
attrs="{'invisible': [('state', 'not in', ('sale', 'done'))]}"
/>
</xpath>
</field>
</record>
</odoo>

0 comments on commit 6d7e6c3

Please sign in to comment.