[IMP] stock_card_report: black, isort, prettier

This commit is contained in:
Prapassorn Sornkaew
2020-11-17 10:19:49 +00:00
committed by ps-tubtim
parent 6a9eef7840
commit f274130e65
8 changed files with 154 additions and 107 deletions

View File

@@ -0,0 +1 @@
../../../../stock_card_report

View File

@@ -0,0 +1,6 @@
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

View File

@@ -6,21 +6,25 @@
<field name="context" eval="{'active_model': 'report.stock.card.report'}" /> <field name="context" eval="{'active_model': 'report.stock.card.report'}" />
</record> </record>
<report string="Stock Card PDF" <report
string="Stock Card PDF"
id="action_stock_card_report_pdf" id="action_stock_card_report_pdf"
model="report.stock.card.report" model="report.stock.card.report"
name="stock_card_report.report_stock_card_report_pdf" name="stock_card_report.report_stock_card_report_pdf"
file="stock_card_report.report_stock_card_report_pdf" file="stock_card_report.report_stock_card_report_pdf"
report_type="qweb-pdf" report_type="qweb-pdf"
print_report_name="'Stock Card Report - [%s]' % object.location_id.display_name" print_report_name="'Stock Card Report - [%s]' % object.location_id.display_name"
paperformat="stock_card_report.paperformat_stock_card"/> paperformat="stock_card_report.paperformat_stock_card"
/>
<report string="Stock Card XLSX" <report
string="Stock Card XLSX"
id="action_stock_card_report_xlsx" id="action_stock_card_report_xlsx"
model="report.stock.card.report" model="report.stock.card.report"
name="stock_card_report.report_stock_card_report_xlsx" name="stock_card_report.report_stock_card_report_xlsx"
file="Stock Card Report" file="Stock Card Report"
report_type="xlsx" report_type="xlsx"
attachment_use="False"/> attachment_use="False"
/>
</odoo> </odoo>

View File

@@ -1,23 +1,36 @@
<odoo> <odoo>
<template id="assets_backend" <template
name="stock_card_report assets" inherit_id="web.assets_backend"> id="assets_backend"
name="stock_card_report assets"
inherit_id="web.assets_backend"
>
<xpath expr="." position="inside"> <xpath expr="." position="inside">
<link href="/stock_card_report/static/src/css/report.css" rel="stylesheet"/> <link
<script type="text/javascript" href="/stock_card_report/static/src/css/report.css"
src="/stock_card_report/static/src/js/stock_card_report_backend.js"/> rel="stylesheet"
/>
<script
type="text/javascript"
src="/stock_card_report/static/src/js/stock_card_report_backend.js"
/>
</xpath> </xpath>
</template> </template>
<template id="stock_card_report.internal_layout"> <template id="stock_card_report.internal_layout">
<div class="article"> <div class="article">
<link href="/stock_card_report/static/src/css/report.css" rel="stylesheet"/> <link
href="/stock_card_report/static/src/css/report.css"
rel="stylesheet"
/>
<t t-raw="0" /> <t t-raw="0" />
</div> </div>
<div class="footer"> <div class="footer">
<div class="row"> <div class="row">
<div class="col-6 custom_footer"> <div class="col-6 custom_footer">
<span t-esc="context_timestamp(datetime.datetime.now()).strftime('%Y-%m-%d')"/> <span
t-esc="context_timestamp(datetime.datetime.now()).strftime('%Y-%m-%d')"
/>
</div> </div>
<div class="col-6 text-right custom_footer"> <div class="col-6 text-right custom_footer">
<span class="page" />/<span class="topage" /> <span class="page" />/<span class="topage" />
@@ -28,8 +41,12 @@
<template id="report_buttons"> <template id="report_buttons">
<div class="button_row"> <div class="button_row">
<button class="o_stock_card_reports_print btn btn-sm oe_button"><span class="fa fa-print"/>Print</button> <button class="o_stock_card_reports_print btn btn-sm oe_button"><span
<button class="o_stock_card_reports_export btn btn-sm oe_button"><span class="fa fa-download"/>Export</button> class="fa fa-print"
/>Print</button>
<button class="o_stock_card_reports_export btn btn-sm oe_button"><span
class="fa fa-download"
/>Export</button>
</div> </div>
</template> </template>
@@ -64,7 +81,10 @@
<!-- Display header line--> <!-- Display header line-->
<t t-call="stock_card_report.report_stock_card_lines_header" /> <t t-call="stock_card_report.report_stock_card_lines_header" />
<!-- Display initial lines --> <!-- Display initial lines -->
<t t-set="initial" t-value="o._get_initial(o.results.filtered(lambda l: l.product_id == product and l.is_initial))"/> <t
t-set="initial"
t-value="o._get_initial(o.results.filtered(lambda l: l.product_id == product and l.is_initial))"
/>
<div class="act_as_row lines"> <div class="act_as_row lines">
<div class="act_as_cell" /> <div class="act_as_cell" />
<div class="act_as_cell"> <div class="act_as_cell">
@@ -78,12 +98,18 @@
</div> </div>
<!-- Display each lines --> <!-- Display each lines -->
<t t-set="product_balance" t-value="initial" /> <t t-set="product_balance" t-value="initial" />
<t t-foreach="o.results.filtered(lambda l: l.product_id == product and not l.is_initial)" t-as="product_line"> <t
<t t-set="product_balance" t-value="product_balance + product_line.product_in - product_line.product_out"/> t-foreach="o.results.filtered(lambda l: l.product_id == product and not l.is_initial)"
t-as="product_line"
>
<t
t-set="product_balance"
t-value="product_balance + product_line.product_in - product_line.product_out"
/>
<t t-call="stock_card_report.report_stock_card_lines" /> <t t-call="stock_card_report.report_stock_card_lines" />
</t> </t>
</div> </div>
<p style="page-break-before:always;"></p> <p style="page-break-before:always;" />
</div> </div>
</t> </t>
</template> </template>

View File

@@ -14,7 +14,7 @@
display: table-header-group !important; display: table-header-group !important;
} }
.act_as_row.labels { .act_as_row.labels {
background-color:#F0F0F0 !important; background-color: #f0f0f0 !important;
} }
.data_table { .data_table {
width: 100% !important; width: 100% !important;

View File

@@ -1,17 +1,16 @@
odoo.define('stock_card_report.stock_card_report_backend', function (require) { odoo.define("stock_card_report.stock_card_report_backend", function (require) {
'use strict'; "use strict";
var AbstractAction = require('web.AbstractAction');
var core = require('web.core');
var ReportWidget = require('web.Widget');
var AbstractAction = require("web.AbstractAction");
var core = require("web.core");
var ReportWidget = require("web.Widget");
var report_backend = AbstractAction.extend({ var report_backend = AbstractAction.extend({
hasControlPanel: true, hasControlPanel: true,
// Stores all the parameters of the action. // Stores all the parameters of the action.
events: { events: {
'click .o_stock_card_reports_print': 'print', "click .o_stock_card_reports_print": "print",
'click .o_stock_card_reports_export': 'export', "click .o_stock_card_reports_export": "export",
}, },
init: function (parent, action) { init: function (parent, action) {
this._super.apply(this, arguments); this._super.apply(this, arguments);
@@ -22,8 +21,8 @@ odoo.define('stock_card_report.stock_card_report_backend', function (require) {
if (action.context.context) { if (action.context.context) {
this.given_context = action.context.context; this.given_context = action.context.context;
} }
this.given_context.active_id = action.context.active_id || this.given_context.active_id =
action.params.active_id; action.context.active_id || action.params.active_id;
this.given_context.model = action.context.active_model || false; this.given_context.model = action.context.active_model || false;
this.given_context.ttype = action.context.ttype || false; this.given_context.ttype = action.context.ttype || false;
}, },
@@ -35,7 +34,7 @@ odoo.define('stock_card_report.stock_card_report_backend', function (require) {
var def = Promise.resolve(); var def = Promise.resolve();
if (!this.report_widget) { if (!this.report_widget) {
this.report_widget = new ReportWidget(this, this.given_context); this.report_widget = new ReportWidget(this, this.given_context);
def = this.report_widget.appendTo(this.$('.o_content')); def = this.report_widget.appendTo(this.$(".o_content"));
} }
def.then(function () { def.then(function () {
self.report_widget.$el.html(self.html); self.report_widget.$el.html(self.html);
@@ -52,11 +51,10 @@ odoo.define('stock_card_report.stock_card_report_backend', function (require) {
var defs = []; var defs = [];
return this._rpc({ return this._rpc({
model: this.given_context.model, model: this.given_context.model,
method: 'get_html', method: "get_html",
args: [self.given_context], args: [self.given_context],
context: self.odoo_context, context: self.odoo_context,
}) }).then(function (result) {
.then(function (result) {
self.html = result.html; self.html = result.html;
defs.push(self.update_cp()); defs.push(self.update_cp());
return $.when.apply($, defs); return $.when.apply($, defs);
@@ -81,8 +79,8 @@ odoo.define('stock_card_report.stock_card_report_backend', function (require) {
var self = this; var self = this;
this._rpc({ this._rpc({
model: this.given_context.model, model: this.given_context.model,
method: 'print_report', method: "print_report",
args: [this.given_context.active_id, 'qweb-pdf'], args: [this.given_context.active_id, "qweb-pdf"],
context: self.odoo_context, context: self.odoo_context,
}).then(function (result) { }).then(function (result) {
self.do_action(result); self.do_action(result);
@@ -92,8 +90,8 @@ odoo.define('stock_card_report.stock_card_report_backend', function (require) {
var self = this; var self = this;
this._rpc({ this._rpc({
model: this.given_context.model, model: this.given_context.model,
method: 'print_report', method: "print_report",
args: [this.given_context.active_id, 'xlsx'], args: [this.given_context.active_id, "xlsx"],
context: self.odoo_context, context: self.odoo_context,
}).then(function (result) { }).then(function (result) {
self.do_action(result); self.do_action(result);
@@ -104,9 +102,6 @@ odoo.define('stock_card_report.stock_card_report_backend', function (require) {
}, },
}); });
core.action_registry.add( core.action_registry.add("stock_card_report_backend", report_backend);
"stock_card_report_backend",
report_backend
);
return report_backend; return report_backend;
}); });

View File

@@ -17,12 +17,25 @@
</group> </group>
</group> </group>
<footer> <footer>
<button name="button_export_html" string="View" <button
type="object" default_focus="1" class="oe_highlight"/> name="button_export_html"
string="View"
type="object"
default_focus="1"
class="oe_highlight"
/>
or or
<button name="button_export_pdf" string="Export PDF" type="object"/> <button
name="button_export_pdf"
string="Export PDF"
type="object"
/>
or or
<button name="button_export_xlsx" string="Export XLSX" type="object"/> <button
name="button_export_xlsx"
string="Export XLSX"
type="object"
/>
or or
<button string="Cancel" class="oe_link" special="cancel" /> <button string="Cancel" class="oe_link" special="cancel" />
</footer> </footer>
@@ -37,9 +50,11 @@
<field name="target">new</field> <field name="target">new</field>
</record> </record>
<menuitem id="stock_card_report_menu" <menuitem
id="stock_card_report_menu"
action="stock_card_report_action" action="stock_card_report_action"
parent="stock.menu_warehouse_report" parent="stock.menu_warehouse_report"
sequence="30"/> sequence="30"
/>
</odoo> </odoo>