Skip to content

Commit e308c08

Browse files
committed
[FIX] stock_card_report: fix view action
1 parent e02b0a6 commit e308c08

File tree

9 files changed

+272
-256
lines changed

9 files changed

+272
-256
lines changed

stock_card_report/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33

44
from . import wizard
55
from . import reports
6+
from . import controllers
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import main

stock_card_report/controllers/main.py

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# -*- coding: utf-8 -*-
2+
import werkzeug
3+
from werkzeug.exceptions import InternalServerError
4+
from io import BytesIO
5+
from odoo import http
6+
from odoo.http import request
7+
from odoo.tools.misc import html_escape
8+
9+
import json
10+
11+
12+
class StockCardReportController(http.Controller):
13+
14+
@http.route('/stock/stock_card_report/<string:output_format>', type='http', auth='user')
15+
def report(self, output_format, report_name=False, **kw):
16+
if output_format == 'pdf':
17+
report_ref = request.env.ref('stock_card_report.action_stock_card_report_pdf')
18+
method_name = '_render_qweb_pdf'
19+
report = getattr(report_ref, method_name)(
20+
report_ref,
21+
res_ids=[int(kw['active_id'])],
22+
data={
23+
'report_type': 'pdf'
24+
},
25+
)[0]
26+
return request.make_response(
27+
report,
28+
headers=[
29+
('Content-Type', 'application/pdf'),
30+
('Content-Disposition', f'attachment; filename= Stock_Card_Report.pdf'),
31+
],
32+
)
33+
else:
34+
report_ref = request.env.ref('stock_card_report.action_stock_card_report_xlsx')
35+
method_name = '_render_xlsx'
36+
report = getattr(report_ref, method_name)(
37+
report_ref,
38+
docids=[int(kw['active_id'])],
39+
data={
40+
'report_type': 'xlsx'
41+
},
42+
)[0]
43+
return request.make_response(
44+
report,
45+
headers=[
46+
('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'),
47+
('Content-Disposition', 'attachment; filename= Stock_Card_Report.xlsx'),
48+
],
49+
)
+26-27
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,31 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<odoo>
3+
<record id="action_report_stock_card_report_html" model="ir.actions.client">
4+
<field name="name">Stock Card Report</field>
5+
<field name="tag">stock_card_report_backend</field>
6+
<field
7+
name="context"
8+
eval="{'url': 'stock/stock_card_report/output_format?active_id=:active_id', 'model': 'report.stock.card.report'}"
9+
/>
10+
</record>
311

4-
<record id="action_report_stock_card_report_html" model="ir.actions.client">
5-
<field name="name">Stock Card Report</field>
6-
<field name="tag">stock_card_report_backend</field>
7-
<field name="context" eval="{'active_model': 'report.stock.card.report'}" />
8-
</record>
9-
10-
<record id="action_stock_card_report_pdf" model="ir.actions.report">
11-
<field name="name">Stock Card PDF</field>
12-
<field name="model">report.stock.card.report</field>
13-
<field name="report_type">qweb-pdf</field>
14-
<field name="report_name">stock_card_report.report_stock_card_report_pdf</field>
15-
<field name="report_file">stock_card_report.report_stock_card_report_pdf</field>
16-
<field
17-
name="print_report_name"
18-
>'Stock Card Report - [%s]' % (object.location_id.complete_name)</field>
19-
<field name="paperformat_id" ref="stock_card_report.paperformat_stock_card" />
20-
</record>
21-
22-
<record id="action_stock_card_report_xlsx" model="ir.actions.report">
23-
<field name="name">Stock Card XLSX</field>
24-
<field name="model">report.stock.card.report</field>
25-
<field name="report_type">xlsx</field>
26-
<field
27-
name="report_name"
28-
>stock_card_report.report_stock_card_report_xlsx</field>
29-
<field name="report_file">Stock Card Report</field>
30-
</record>
12+
<record id="action_stock_card_report_pdf" model="ir.actions.report">
13+
<field name="name">Stock Card PDF</field>
14+
<field name="model">report.stock.card.report</field>
15+
<field name="report_type">qweb-pdf</field>
16+
<field name="report_name">stock_card_report.report_stock_card_report_pdf</field>
17+
<field name="report_file">stock_card_report.report_stock_card_report_pdf</field>
18+
<field name="print_report_name">
19+
'Stock Card Report - [%s]' % (object.location_id.complete_name)
20+
</field>
21+
<field name="paperformat_id" ref="stock_card_report.paperformat_stock_card" />
22+
</record>
3123

24+
<record id="action_stock_card_report_xlsx" model="ir.actions.report">
25+
<field name="name">Stock Card XLSX</field>
26+
<field name="model">report.stock.card.report</field>
27+
<field name="report_type">xlsx</field>
28+
<field name="report_name">stock_card_report.report_stock_card_report_xlsx</field>
29+
<field name="report_file">Stock Card Report</field>
30+
</record>
3231
</odoo>
+115-129
Original file line numberDiff line numberDiff line change
@@ -1,153 +1,139 @@
11
<odoo>
2-
3-
<template id="stock_card_report.internal_layout">
4-
<div class="article">
5-
<link
6-
href="/stock_card_report/static/src/css/report.css"
7-
rel="stylesheet"
8-
/>
9-
<t t-out="0" />
10-
</div>
11-
<div class="footer">
12-
<div class="row">
13-
<div class="col-6 custom_footer">
14-
<span
2+
<template id="stock_card_report.internal_layout">
3+
<div class="article">
4+
<link href="/stock_card_report/static/src/css/report.css" rel="stylesheet" />
5+
<t t-out="0" />
6+
</div>
7+
<div class="footer">
8+
<div class="row">
9+
<div class="col-6 custom_footer">
10+
<span
1511
t-out="context_timestamp(datetime.datetime.now()).strftime('%Y-%m-%d')"
1612
/>
17-
</div>
18-
<div class="col-6 text-right custom_footer">
19-
<span class="page" />/<span class="topage" />
20-
</div>
21-
</div>
2213
</div>
23-
</template>
24-
25-
<template id="report_buttons">
26-
<div class="button_row">
27-
<button class="o_stock_card_reports_print btn btn-sm oe_button"><span
28-
class="fa fa-print"
29-
/>Print</button>
30-
<button class="o_stock_card_reports_export btn btn-sm oe_button"><span
31-
class="fa fa-download"
32-
/>Export</button>
14+
<div class="col-6 text-right custom_footer">
15+
<span class="page" />
16+
/
17+
<span class="topage" />
3318
</div>
34-
</template>
19+
</div>
20+
</div>
21+
</template>
3522

36-
<template id="report_stock_card_report_html">
37-
<div class="o_stock_card_reports_page">
38-
<t t-call="stock_card_report.report_buttons" />
39-
<t t-call="stock_card_report.report_stock_card_report_base" />
40-
</div>
41-
</template>
23+
<template id="report_stock_card_report_html">
24+
<div class="o_stock_card_reports_page">
25+
<t t-call="stock_card_report.report_stock_card_report_base" />
26+
</div>
27+
</template>
4228

43-
<template id="stock_card_report.report_stock_card_report_pdf">
44-
<t t-call="web.html_container">
45-
<t t-foreach="docs" t-as="o">
46-
<t t-call="stock_card_report.internal_layout">
47-
<t t-call="stock_card_report.report_stock_card_report_base" />
48-
</t>
49-
</t>
29+
<template id="stock_card_report.report_stock_card_report_pdf">
30+
<t t-call="web.html_container">
31+
<t t-foreach="docs" t-as="o">
32+
<t t-call="stock_card_report.internal_layout">
33+
<t t-call="stock_card_report.report_stock_card_report_base" />
5034
</t>
51-
</template>
35+
</t>
36+
</t>
37+
</template>
5238

53-
<template id="stock_card_report.report_stock_card_report_base">
54-
<t t-foreach="o.product_ids" t-as="product">
55-
<div class="page">
56-
<div class="row">
57-
<t t-set="title">Stock Card - <t t-out="product.name" /></t>
58-
<h4 class="mt0" t-out="title" style="text-align: center;" />
59-
</div>
60-
<!-- Display filters -->
61-
<t t-call="stock_card_report.report_stock_card_report_filters" />
62-
<!-- Display stock card table -->
63-
<div class="act_as_table data_table mt4" style="width: 100%;">
64-
<!-- Display header line-->
65-
<t t-call="stock_card_report.report_stock_card_lines_header" />
66-
<!-- Display initial lines -->
67-
<t
39+
<template id="stock_card_report.report_stock_card_report_base">
40+
<t t-foreach="o.product_ids" t-as="product">
41+
<div class="page">
42+
<div class="row">
43+
<t t-set="title">
44+
Stock Card -
45+
<t t-out="product.name" />
46+
</t>
47+
<h4 class="mt0" t-out="title" style="text-align: center;" />
48+
</div>
49+
<!-- Display filters -->
50+
<t t-call="stock_card_report.report_stock_card_report_filters" />
51+
<!-- Display stock card table -->
52+
<div class="act_as_table data_table mt4" style="width: 100%;">
53+
<!-- Display header line-->
54+
<t t-call="stock_card_report.report_stock_card_lines_header" />
55+
<!-- Display initial lines -->
56+
<t
6857
t-set="initial"
6958
t-value="o._get_initial(o.results.filtered(lambda l: l.product_id == product and l.is_initial))"
7059
/>
71-
<div class="act_as_row lines">
72-
<div class="act_as_cell" />
73-
<div class="act_as_cell">
74-
Initial
75-
</div>
76-
<div class="act_as_cell" />
77-
<div class="act_as_cell" />
78-
<div class="act_as_cell right">
79-
<t t-out="'{0:,.3f}'.format(initial)" />
80-
</div>
81-
</div>
82-
<!-- Display each lines -->
83-
<t t-set="product_balance" t-value="initial" />
84-
<t
60+
<div class="act_as_row lines">
61+
<div class="act_as_cell" />
62+
<div class="act_as_cell">Initial</div>
63+
<div class="act_as_cell" />
64+
<div class="act_as_cell" />
65+
<div class="act_as_cell right">
66+
<t t-out="'{0:,.3f}'.format(initial)" />
67+
</div>
68+
</div>
69+
<!-- Display each lines -->
70+
<t t-set="product_balance" t-value="initial" />
71+
<t
8572
t-foreach="o.results.filtered(lambda l: l.product_id == product and not l.is_initial)"
8673
t-as="product_line"
8774
>
88-
<t
75+
<t
8976
t-set="product_balance"
9077
t-value="product_balance + product_line.product_in - product_line.product_out"
9178
/>
92-
<t t-call="stock_card_report.report_stock_card_lines" />
93-
</t>
94-
</div>
95-
<p style="page-break-before:always;" />
96-
</div>
97-
</t>
98-
</template>
99-
100-
<template id="stock_card_report.report_stock_card_report_filters">
101-
<div class="act_as_table data_table" style="width: 100%;">
102-
<div class="act_as_row labels">
103-
<div class="act_as_cell">Date From</div>
104-
<div class="act_as_cell">Date To</div>
105-
<div class="act_as_cell">Location</div>
106-
</div>
107-
<div class="act_as_row">
108-
<div class="act_as_cell">
109-
<span t-field="o.date_from" />
110-
</div>
111-
<div class="act_as_cell">
112-
<span t-field="o.date_to" />
113-
</div>
114-
<div class="act_as_cell">
115-
<span t-field="o.location_id" />
116-
</div>
117-
</div>
79+
<t t-call="stock_card_report.report_stock_card_lines" />
80+
</t>
11881
</div>
119-
</template>
82+
<p style="page-break-before:always;" />
83+
</div>
84+
</t>
85+
</template>
12086

121-
<template id="stock_card_report.report_stock_card_lines_header">
122-
<div class="act_as_thead">
123-
<div class="act_as_row labels">
124-
<div class="act_as_cell">Date</div>
125-
<div class="act_as_cell">Reference</div>
126-
<div class="act_as_cell">In</div>
127-
<div class="act_as_cell">Out</div>
128-
<div class="act_as_cell">Balance</div>
129-
</div>
87+
<template id="stock_card_report.report_stock_card_report_filters">
88+
<div class="act_as_table data_table" style="width: 100%;">
89+
<div class="act_as_row labels">
90+
<div class="act_as_cell">Date From</div>
91+
<div class="act_as_cell">Date To</div>
92+
<div class="act_as_cell">Location</div>
93+
</div>
94+
<div class="act_as_row">
95+
<div class="act_as_cell">
96+
<span t-field="o.date_from" />
13097
</div>
131-
</template>
132-
133-
<template id="stock_card_report.report_stock_card_lines">
134-
<div class="act_as_row lines">
135-
<div class="act_as_cell left">
136-
<t t-out="product_line.date.strftime('%Y-%m-%d')" />
137-
</div>
138-
<div class="act_as_cell left">
139-
<t t-out="product_line.display_name" />
140-
</div>
141-
<div class="act_as_cell right">
142-
<t t-out="'{0:,.3f}'.format(product_line.product_in)" />
143-
</div>
144-
<div class="act_as_cell right">
145-
<t t-out="'{0:,.3f}'.format(product_line.product_out)" />
146-
</div>
147-
<div class="act_as_cell right">
148-
<t t-out="'{0:,.3f}'.format(product_balance)" />
149-
</div>
98+
<div class="act_as_cell">
99+
<span t-field="o.date_to" />
100+
</div>
101+
<div class="act_as_cell">
102+
<span t-field="o.location_id" />
150103
</div>
151-
</template>
104+
</div>
105+
</div>
106+
</template>
107+
108+
<template id="stock_card_report.report_stock_card_lines_header">
109+
<div class="act_as_thead">
110+
<div class="act_as_row labels">
111+
<div class="act_as_cell">Date</div>
112+
<div class="act_as_cell">Reference</div>
113+
<div class="act_as_cell">In</div>
114+
<div class="act_as_cell">Out</div>
115+
<div class="act_as_cell">Balance</div>
116+
</div>
117+
</div>
118+
</template>
152119

120+
<template id="stock_card_report.report_stock_card_lines">
121+
<div class="act_as_row lines">
122+
<div class="act_as_cell left">
123+
<t t-out="product_line.date.strftime('%Y-%m-%d')" />
124+
</div>
125+
<div class="act_as_cell left">
126+
<t t-out="product_line.display_name" />
127+
</div>
128+
<div class="act_as_cell right">
129+
<t t-out="'{0:,.3f}'.format(product_line.product_in)" />
130+
</div>
131+
<div class="act_as_cell right">
132+
<t t-out="'{0:,.3f}'.format(product_line.product_out)" />
133+
</div>
134+
<div class="act_as_cell right">
135+
<t t-out="'{0:,.3f}'.format(product_balance)" />
136+
</div>
137+
</div>
138+
</template>
153139
</odoo>

stock_card_report/static/description/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
22
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
33
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
44
<head>

0 commit comments

Comments
 (0)