mirror of
https://github.com/OCA/stock-logistics-reporting.git
synced 2025-02-16 17:13:21 +02:00
[12.0][ADD] stock_card_report
This commit is contained in:
82
stock_card_report/README.rst
Normal file
82
stock_card_report/README.rst
Normal file
@@ -0,0 +1,82 @@
|
||||
=================
|
||||
Stock Card Report
|
||||
=================
|
||||
|
||||
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
!! This file is generated by oca-gen-addon-readme !!
|
||||
!! changes will be overwritten. !!
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
|
||||
:target: https://odoo-community.org/page/development-status
|
||||
:alt: Beta
|
||||
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
|
||||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
|
||||
:alt: License: AGPL-3
|
||||
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstock--logistics--reporting-lightgray.png?logo=github
|
||||
:target: https://github.com/OCA/stock-logistics-reporting/tree/12.0/stock_card_report
|
||||
:alt: OCA/stock-logistics-reporting
|
||||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
|
||||
:target: https://translation.odoo-community.org/projects/stock-logistics-reporting-12-0/stock-logistics-reporting-12-0-stock_card_report
|
||||
:alt: Translate me on Weblate
|
||||
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
|
||||
:target: https://runbot.odoo-community.org/runbot/151/12.0
|
||||
:alt: Try me on Runbot
|
||||
|
||||
|badge1| |badge2| |badge3| |badge4| |badge5|
|
||||
|
||||
Stock Card Report is the report that display movement (in/out) of a product in a specified location and date range.
|
||||
|
||||
**Table of contents**
|
||||
|
||||
.. contents::
|
||||
:local:
|
||||
|
||||
Usage
|
||||
=====
|
||||
|
||||
To use this module, you need to:
|
||||
|
||||
#. Go to Inventory > Reporting > Stock Card.
|
||||
#. Select Start date, End date, Products, Location.
|
||||
#. Choose View or Export PDF or Export XLSX or Cancel.
|
||||
|
||||
Bug Tracker
|
||||
===========
|
||||
|
||||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/stock-logistics-reporting/issues>`_.
|
||||
In case of trouble, please check there if your issue has already been reported.
|
||||
If you spotted it first, help us smashing it by providing a detailed and welcomed
|
||||
`feedback <https://github.com/OCA/stock-logistics-reporting/issues/new?body=module:%20stock_card_report%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
|
||||
|
||||
Do not contact contributors directly about support or help with technical issues.
|
||||
|
||||
Credits
|
||||
=======
|
||||
|
||||
Authors
|
||||
~~~~~~~
|
||||
|
||||
* Ecosoft
|
||||
|
||||
Contributors
|
||||
~~~~~~~~~~~~
|
||||
|
||||
* Pimolnat Suntian <pimolnats@ecosoft.co.th>
|
||||
|
||||
Maintainers
|
||||
~~~~~~~~~~~
|
||||
|
||||
This module is maintained by the OCA.
|
||||
|
||||
.. image:: https://odoo-community.org/logo.png
|
||||
:alt: Odoo Community Association
|
||||
:target: https://odoo-community.org
|
||||
|
||||
OCA, or the Odoo Community Association, is a nonprofit organization whose
|
||||
mission is to support the collaborative development of Odoo features and
|
||||
promote its widespread use.
|
||||
|
||||
This module is part of the `OCA/stock-logistics-reporting <https://github.com/OCA/stock-logistics-reporting/tree/12.0/stock_card_report>`_ project on GitHub.
|
||||
|
||||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
|
||||
5
stock_card_report/__init__.py
Normal file
5
stock_card_report/__init__.py
Normal file
@@ -0,0 +1,5 @@
|
||||
# Copyright 2019 Ecosoft Co., Ltd. (http://ecosoft.co.th)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from . import wizard
|
||||
from . import reports
|
||||
24
stock_card_report/__manifest__.py
Normal file
24
stock_card_report/__manifest__.py
Normal file
@@ -0,0 +1,24 @@
|
||||
# Copyright 2019 Ecosoft Co., Ltd. (http://ecosoft.co.th)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
{
|
||||
'name': 'Stock Card Report',
|
||||
'summary': 'Add stock card report on Inventory Reporting.',
|
||||
'version': '12.0.1.0.0',
|
||||
'category': 'Warehouse',
|
||||
'website': 'https://github.com/OCA/stock-logistics-reporting',
|
||||
'author': 'Ecosoft,Odoo Community Association (OCA)',
|
||||
'license': 'AGPL-3',
|
||||
'depends': [
|
||||
'stock',
|
||||
'date_range',
|
||||
'report_xlsx_helper',
|
||||
],
|
||||
'data': [
|
||||
'data/paper_format.xml',
|
||||
'data/report_data.xml',
|
||||
'reports/stock_card_report.xml',
|
||||
'wizard/stock_card_report_wizard_view.xml',
|
||||
],
|
||||
'installable': True,
|
||||
}
|
||||
19
stock_card_report/data/paper_format.xml
Normal file
19
stock_card_report/data/paper_format.xml
Normal file
@@ -0,0 +1,19 @@
|
||||
<odoo>
|
||||
|
||||
<record id="paperformat_stock_card" model="report.paperformat">
|
||||
<field name="name">Stock Card A4</field>
|
||||
<field name="default" eval="True"/>
|
||||
<field name="format">A4</field>
|
||||
<field name="page_height">0</field>
|
||||
<field name="page_width">0</field>
|
||||
<field name="orientation">Portrait</field>
|
||||
<field name="margin_top">28</field>
|
||||
<field name="margin_bottom">28</field>
|
||||
<field name="margin_left">7</field>
|
||||
<field name="margin_right">7</field>
|
||||
<field name="header_line" eval="False"/>
|
||||
<field name="header_spacing">24</field>
|
||||
<field name="dpi">90</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
26
stock_card_report/data/report_data.xml
Normal file
26
stock_card_report/data/report_data.xml
Normal file
@@ -0,0 +1,26 @@
|
||||
<odoo>
|
||||
|
||||
<record id="action_report_stock_card_report_html" model="ir.actions.client">
|
||||
<field name="name">Stock Card Report</field>
|
||||
<field name="tag">stock_card_report_backend</field>
|
||||
<field name="context" eval="{'active_model': 'report.stock.card.report'}" />
|
||||
</record>
|
||||
|
||||
<report string="Stock Card PDF"
|
||||
id="action_stock_card_report_pdf"
|
||||
model="report.stock.card.report"
|
||||
name="stock_card_report.report_stock_card_report_pdf"
|
||||
file="stock_card_report.report_stock_card_report_pdf"
|
||||
report_type="qweb-pdf"
|
||||
print_report_name="'Stock Card Report - [%s]' % object.location_id.name"
|
||||
paperformat="stock_card_report.paperformat_stock_card"/>
|
||||
|
||||
<report string="Stock Card XLSX"
|
||||
id="action_stock_card_report_xlsx"
|
||||
model="report.stock.card.report"
|
||||
name="stock_card_report.report_stock_card_report_xlsx"
|
||||
file="Stock_Card_Report"
|
||||
report_type="xlsx"
|
||||
attachment_use="False"/>
|
||||
|
||||
</odoo>
|
||||
1
stock_card_report/readme/CONTRIBUTORS.rst
Normal file
1
stock_card_report/readme/CONTRIBUTORS.rst
Normal file
@@ -0,0 +1 @@
|
||||
* Pimolnat Suntian <pimolnats@ecosoft.co.th>
|
||||
1
stock_card_report/readme/DESCRIPTION.rst
Normal file
1
stock_card_report/readme/DESCRIPTION.rst
Normal file
@@ -0,0 +1 @@
|
||||
Stock Card Report is the report that display movement (in/out) of a product in a specified location and date range.
|
||||
5
stock_card_report/readme/USAGE.rst
Normal file
5
stock_card_report/readme/USAGE.rst
Normal file
@@ -0,0 +1,5 @@
|
||||
To use this module, you need to:
|
||||
|
||||
#. Go to Inventory > Reporting > Stock Card.
|
||||
#. Select Start date, End date, Products, Location.
|
||||
#. Choose View or Export PDF or Export XLSX or Cancel.
|
||||
5
stock_card_report/reports/__init__.py
Normal file
5
stock_card_report/reports/__init__.py
Normal file
@@ -0,0 +1,5 @@
|
||||
# Copyright 2019 Ecosoft Co., Ltd. (http://ecosoft.co.th)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from . import stock_card_report
|
||||
from . import stock_card_report_xlsx
|
||||
109
stock_card_report/reports/stock_card_report.py
Normal file
109
stock_card_report/reports/stock_card_report.py
Normal file
@@ -0,0 +1,109 @@
|
||||
# Copyright 2019 Ecosoft Co., Ltd. (http://ecosoft.co.th)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class StockCardView(models.TransientModel):
|
||||
_name = 'stock.card.view'
|
||||
_description = 'Stock Card View'
|
||||
_order = 'date'
|
||||
|
||||
date = fields.Datetime()
|
||||
product_id = fields.Many2one(comodel_name='product.product')
|
||||
product_qty = fields.Float()
|
||||
product_uom_qty = fields.Float()
|
||||
product_uom = fields.Many2one(comodel_name='uom.uom')
|
||||
reference = fields.Char()
|
||||
location_id = fields.Many2one(comodel_name='stock.location')
|
||||
location_dest_id = fields.Many2one(comodel_name='stock.location')
|
||||
is_initial = fields.Boolean()
|
||||
product_in = fields.Float()
|
||||
product_out = fields.Float()
|
||||
|
||||
|
||||
class StockCardReport(models.TransientModel):
|
||||
_name = 'report.stock.card.report'
|
||||
_description = 'Stock Card Report'
|
||||
|
||||
# Filters fields, used for data computation
|
||||
date_from = fields.Date()
|
||||
date_to = fields.Date()
|
||||
product_ids = fields.Many2many(
|
||||
comodel_name='product.product',
|
||||
)
|
||||
location_id = fields.Many2one(
|
||||
comodel_name='stock.location',
|
||||
)
|
||||
|
||||
# Data fields, used to browse report data
|
||||
results = fields.Many2many(
|
||||
comodel_name='stock.card.view',
|
||||
compute='_compute_results',
|
||||
help='Use compute fields, so there is nothing store in database',
|
||||
)
|
||||
|
||||
@api.multi
|
||||
def _compute_results(self):
|
||||
self.ensure_one()
|
||||
change = False
|
||||
if not self.date_from:
|
||||
change = True
|
||||
self.date_from = '0001-01-01'
|
||||
if not self.date_to:
|
||||
self.date_to = fields.Date.context_today(self)
|
||||
locations = self.env['stock.location'].search(
|
||||
[('id', 'child_of', [self.location_id.id])])
|
||||
self._cr.execute("""
|
||||
SELECT move.date, move.product_id, move.product_qty,
|
||||
move.product_uom_qty, move.product_uom, move.reference,
|
||||
move.location_id, move.location_dest_id,
|
||||
case when move.location_dest_id in %s
|
||||
then move.product_qty end as product_in,
|
||||
case when move.location_id in %s
|
||||
then move.product_qty end as product_out,
|
||||
case when move.date < %s then True else False end as is_initial
|
||||
FROM stock_move move
|
||||
WHERE (move.location_id in %s or move.location_dest_id in %s)
|
||||
and move.state = 'done' and move.product_id in %s
|
||||
and CAST(move.date AS date) <= %s
|
||||
ORDER BY move.date, move.reference
|
||||
""", (
|
||||
tuple(locations.ids), tuple(locations.ids), self.date_from,
|
||||
tuple(locations.ids), tuple(locations.ids),
|
||||
tuple(self.product_ids.ids+[0]), self.date_to))
|
||||
stock_card_results = self._cr.dictfetchall()
|
||||
ReportLine = self.env['stock.card.view']
|
||||
for line in stock_card_results:
|
||||
self.results += ReportLine.new(line)
|
||||
if change:
|
||||
self.date_from = not change
|
||||
|
||||
@api.multi
|
||||
def _get_initial(self, product_line):
|
||||
product_input_qty = sum(product_line.mapped('product_in'))
|
||||
product_output_qty = sum(product_line.mapped('product_out'))
|
||||
return product_input_qty - product_output_qty
|
||||
|
||||
@api.multi
|
||||
def print_report(self, report_type='qweb'):
|
||||
self.ensure_one()
|
||||
action = report_type == 'xlsx' and self.env.ref(
|
||||
'stock_card_report.action_stock_card_report_xlsx') or \
|
||||
self.env.ref('stock_card_report.action_stock_card_report_pdf')
|
||||
return action.report_action(self, config=False)
|
||||
|
||||
def _get_html(self):
|
||||
result = {}
|
||||
rcontext = {}
|
||||
report = self.browse(self._context.get('active_id'))
|
||||
if report:
|
||||
rcontext['o'] = report
|
||||
result['html'] = self.env.ref(
|
||||
'stock_card_report.report_stock_card_report_html').render(
|
||||
rcontext)
|
||||
return result
|
||||
|
||||
@api.model
|
||||
def get_html(self, given_context=None):
|
||||
return self.with_context(given_context)._get_html()
|
||||
144
stock_card_report/reports/stock_card_report.xml
Normal file
144
stock_card_report/reports/stock_card_report.xml
Normal file
@@ -0,0 +1,144 @@
|
||||
<odoo>
|
||||
|
||||
<template id="assets_backend"
|
||||
name="stock_card_report assets" inherit_id="web.assets_backend">
|
||||
<xpath expr="." position="inside">
|
||||
<link href="/stock_card_report/static/src/css/report.css" rel="stylesheet"/>
|
||||
<script type="text/javascript"
|
||||
src="/stock_card_report/static/src/js/stock_card_report_backend.js"/>
|
||||
</xpath>
|
||||
</template>
|
||||
|
||||
<template id="stock_card_report.internal_layout">
|
||||
<div class="article">
|
||||
<link href="/stock_card_report/static/src/css/report.css" rel="stylesheet"/>
|
||||
<t t-raw="0"/>
|
||||
</div>
|
||||
<div class="footer">
|
||||
<div class="row">
|
||||
<div class="col-6 custom_footer">
|
||||
<span t-esc="context_timestamp(datetime.datetime.now()).strftime('%Y-%m-%d')"/>
|
||||
</div>
|
||||
<div class="col-6 text-right custom_footer">
|
||||
<span class="page"/>/<span class="topage"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template id="report_buttons">
|
||||
<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_export btn btn-sm oe_button"><span class="fa fa-download"/>Export</button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template id="report_stock_card_report_html">
|
||||
<div class="o_stock_card_reports_page">
|
||||
<t t-call="stock_card_report.report_buttons"/>
|
||||
<t t-call="stock_card_report.report_stock_card_report_base"/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template id="stock_card_report.report_stock_card_report_pdf">
|
||||
<t t-call="web.html_container">
|
||||
<t t-foreach="docs" t-as="o">
|
||||
<t t-call="stock_card_report.internal_layout">
|
||||
<t t-call="stock_card_report.report_stock_card_report_base"/>
|
||||
</t>
|
||||
</t>
|
||||
</t>
|
||||
</template>
|
||||
|
||||
<template id="stock_card_report.report_stock_card_report_base">
|
||||
<t t-foreach="o.results.mapped('product_id')" t-as="product">
|
||||
<div class="page">
|
||||
<div class="row">
|
||||
<t t-set="title">Stock Card - <t t-raw="product.name"/></t>
|
||||
<h4 class="mt0" t-esc="title" style="text-align: center;"/>
|
||||
</div>
|
||||
<!-- Display filters -->
|
||||
<t t-call="stock_card_report.report_stock_card_report_filters"/>
|
||||
<!-- Display stock card table -->
|
||||
<div class="act_as_table data_table mt4" style="width: 100%;">
|
||||
<!-- Display header line-->
|
||||
<t t-call="stock_card_report.report_stock_card_lines_header"/>
|
||||
<!-- 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))"/>
|
||||
<div class="act_as_row lines">
|
||||
<div class="act_as_cell"/>
|
||||
<div class="act_as_cell">
|
||||
Initial
|
||||
</div>
|
||||
<div class="act_as_cell"/>
|
||||
<div class="act_as_cell"/>
|
||||
<div class="act_as_cell right">
|
||||
<t t-esc="'{0:,.3f}'.format(initial)"/>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Display each lines -->
|
||||
<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-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>
|
||||
</div>
|
||||
<p style="page-break-before:always;"></p>
|
||||
</div>
|
||||
</t>
|
||||
</template>
|
||||
|
||||
<template id="stock_card_report.report_stock_card_report_filters">
|
||||
<div class="act_as_table data_table" style="width: 100%;">
|
||||
<div class="act_as_row labels">
|
||||
<div class="act_as_cell">Date From</div>
|
||||
<div class="act_as_cell">Date To</div>
|
||||
<div class="act_as_cell">Location</div>
|
||||
</div>
|
||||
<div class="act_as_row">
|
||||
<div class="act_as_cell">
|
||||
<span t-field="o.date_from"/>
|
||||
</div>
|
||||
<div class="act_as_cell">
|
||||
<span t-field="o.date_to"/>
|
||||
</div>
|
||||
<div class="act_as_cell">
|
||||
<span t-field="o.location_id"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template id="stock_card_report.report_stock_card_lines_header">
|
||||
<div class="act_as_thead">
|
||||
<div class="act_as_row labels">
|
||||
<div class="act_as_cell">Date</div>
|
||||
<div class="act_as_cell">Reference</div>
|
||||
<div class="act_as_cell">Input</div>
|
||||
<div class="act_as_cell">Output</div>
|
||||
<div class="act_as_cell">Balance</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template id="stock_card_report.report_stock_card_lines">
|
||||
<div class="act_as_row lines">
|
||||
<div class="act_as_cell left">
|
||||
<t t-esc="product_line.date.strftime('%Y-%m-%d')"/>
|
||||
</div>
|
||||
<div class="act_as_cell left">
|
||||
<t t-esc="product_line.reference"/>
|
||||
</div>
|
||||
<div class="act_as_cell right">
|
||||
<t t-esc="'{0:,.3f}'.format(product_line.product_in)"/>
|
||||
</div>
|
||||
<div class="act_as_cell right">
|
||||
<t t-esc="'{0:,.3f}'.format(product_line.product_out)"/>
|
||||
</div>
|
||||
<div class="act_as_cell right">
|
||||
<t t-esc="'{0:,.3f}'.format(product_balance)"/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
</odoo>
|
||||
137
stock_card_report/reports/stock_card_report_xlsx.py
Normal file
137
stock_card_report/reports/stock_card_report_xlsx.py
Normal file
@@ -0,0 +1,137 @@
|
||||
# Copyright 2019 Ecosoft Co., Ltd. (http://ecosoft.co.th)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
import logging
|
||||
from odoo import models
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ReportStockCardReportXlsx(models.TransientModel):
|
||||
_name = 'report.stock_card_report.report_stock_card_report_xlsx'
|
||||
_inherit = 'report.report_xlsx.abstract'
|
||||
|
||||
def generate_xlsx_report(self, workbook, data, objects):
|
||||
self._define_formats(workbook)
|
||||
products = objects.results.mapped('product_id')
|
||||
for product in products:
|
||||
for ws_params in self._get_ws_params(workbook, data, product):
|
||||
ws_name = ws_params.get('ws_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, objects, product)
|
||||
|
||||
def _get_ws_params(self, wb, data, product):
|
||||
|
||||
stock_card_template = {
|
||||
'1_date': {
|
||||
'header': {
|
||||
'value': 'Date',
|
||||
},
|
||||
'data': {
|
||||
'value': self._render('date'),
|
||||
'type': 'datetime',
|
||||
'format': self.format_tcell_date_left,
|
||||
},
|
||||
'width': 25,
|
||||
},
|
||||
'2_reference': {
|
||||
'header': {
|
||||
'value': 'Reference',
|
||||
},
|
||||
'data': {
|
||||
'value': self._render('reference'),
|
||||
},
|
||||
'width': 25,
|
||||
},
|
||||
'3_input': {
|
||||
'header': {
|
||||
'value': 'Input',
|
||||
},
|
||||
'data': {
|
||||
'value': self._render('input'),
|
||||
'format': self.format_tcell_amount_right,
|
||||
},
|
||||
'width': 20,
|
||||
},
|
||||
'4_output': {
|
||||
'header': {
|
||||
'value': 'Output',
|
||||
},
|
||||
'data': {
|
||||
'value': self._render('output'),
|
||||
'format': self.format_tcell_amount_right,
|
||||
},
|
||||
'width': 20,
|
||||
},
|
||||
'5_balance': {
|
||||
'header': {
|
||||
'value': 'Balance',
|
||||
},
|
||||
'data': {
|
||||
'value': self._render('balance'),
|
||||
'format': self.format_tcell_amount_right,
|
||||
},
|
||||
'width': 20,
|
||||
},
|
||||
}
|
||||
|
||||
ws_params = {
|
||||
'ws_name': product.name,
|
||||
'generate_ws_method': '_stock_card_report',
|
||||
'title': 'Stock Card Report - '+product.name,
|
||||
'wanted_list': [k for k in sorted(stock_card_template.keys())],
|
||||
'col_specs': stock_card_template,
|
||||
}
|
||||
return [ws_params]
|
||||
|
||||
def _stock_card_report(self, wb, ws, ws_params, data, objects, product):
|
||||
|
||||
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, True)
|
||||
|
||||
for o in objects:
|
||||
ws.write_row(
|
||||
row_pos, 0, ['Date from', 'Date to', 'Location'],
|
||||
self.format_theader_blue_center)
|
||||
ws.write_row(row_pos+1, 0, [o.date_from or '', o.date_to or ''],
|
||||
self.format_tcell_date_center)
|
||||
ws.write_row(row_pos+1, 2, [o.location_id.name or ''],
|
||||
self.format_tcell_center)
|
||||
|
||||
row_pos += 3
|
||||
row_pos = self._write_line(
|
||||
ws, row_pos, ws_params, col_specs_section='header',
|
||||
default_format=self.format_theader_blue_center)
|
||||
ws.freeze_panes(row_pos, 0)
|
||||
|
||||
balance = o._get_initial(o.results.filtered(
|
||||
lambda l: l.product_id == product and l.is_initial))
|
||||
ws.write_row(row_pos, 0, ['', 'Initial', '', ''],
|
||||
self.format_tcell_center,)
|
||||
ws.write(row_pos, 4, balance, self.format_tcell_amount_right,)
|
||||
row_pos += 1
|
||||
product_lines = o.results.filtered(
|
||||
lambda l: l.product_id == product and not l.is_initial)
|
||||
for line in product_lines:
|
||||
balance += line.product_in - line.product_out
|
||||
row_pos = self._write_line(
|
||||
ws, row_pos, ws_params, col_specs_section='data',
|
||||
render_space={
|
||||
'date': line.date or '',
|
||||
'reference': line.reference or '',
|
||||
'input': line.product_in or 0.000,
|
||||
'output': line.product_out or 0.000,
|
||||
'balance': balance,
|
||||
},
|
||||
default_format=self.format_tcell_left)
|
||||
BIN
stock_card_report/static/description/icon.png
Normal file
BIN
stock_card_report/static/description/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.2 KiB |
429
stock_card_report/static/description/index.html
Normal file
429
stock_card_report/static/description/index.html
Normal file
@@ -0,0 +1,429 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.14: http://docutils.sourceforge.net/" />
|
||||
<title>Stock Card Report</title>
|
||||
<style type="text/css">
|
||||
|
||||
/*
|
||||
:Author: David Goodger (goodger@python.org)
|
||||
:Id: $Id: html4css1.css 7952 2016-07-26 18:15:59Z milde $
|
||||
:Copyright: This stylesheet has been placed in the public domain.
|
||||
|
||||
Default cascading style sheet for the HTML output of Docutils.
|
||||
|
||||
See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
|
||||
customize this style sheet.
|
||||
*/
|
||||
|
||||
/* used to remove borders from tables and images */
|
||||
.borderless, table.borderless td, table.borderless th {
|
||||
border: 0 }
|
||||
|
||||
table.borderless td, table.borderless th {
|
||||
/* Override padding for "table.docutils td" with "! important".
|
||||
The right padding separates the table cells. */
|
||||
padding: 0 0.5em 0 0 ! important }
|
||||
|
||||
.first {
|
||||
/* Override more specific margin styles with "! important". */
|
||||
margin-top: 0 ! important }
|
||||
|
||||
.last, .with-subtitle {
|
||||
margin-bottom: 0 ! important }
|
||||
|
||||
.hidden {
|
||||
display: none }
|
||||
|
||||
.subscript {
|
||||
vertical-align: sub;
|
||||
font-size: smaller }
|
||||
|
||||
.superscript {
|
||||
vertical-align: super;
|
||||
font-size: smaller }
|
||||
|
||||
a.toc-backref {
|
||||
text-decoration: none ;
|
||||
color: black }
|
||||
|
||||
blockquote.epigraph {
|
||||
margin: 2em 5em ; }
|
||||
|
||||
dl.docutils dd {
|
||||
margin-bottom: 0.5em }
|
||||
|
||||
object[type="image/svg+xml"], object[type="application/x-shockwave-flash"] {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* Uncomment (and remove this text!) to get bold-faced definition list terms
|
||||
dl.docutils dt {
|
||||
font-weight: bold }
|
||||
*/
|
||||
|
||||
div.abstract {
|
||||
margin: 2em 5em }
|
||||
|
||||
div.abstract p.topic-title {
|
||||
font-weight: bold ;
|
||||
text-align: center }
|
||||
|
||||
div.admonition, div.attention, div.caution, div.danger, div.error,
|
||||
div.hint, div.important, div.note, div.tip, div.warning {
|
||||
margin: 2em ;
|
||||
border: medium outset ;
|
||||
padding: 1em }
|
||||
|
||||
div.admonition p.admonition-title, div.hint p.admonition-title,
|
||||
div.important p.admonition-title, div.note p.admonition-title,
|
||||
div.tip p.admonition-title {
|
||||
font-weight: bold ;
|
||||
font-family: sans-serif }
|
||||
|
||||
div.attention p.admonition-title, div.caution p.admonition-title,
|
||||
div.danger p.admonition-title, div.error p.admonition-title,
|
||||
div.warning p.admonition-title, .code .error {
|
||||
color: red ;
|
||||
font-weight: bold ;
|
||||
font-family: sans-serif }
|
||||
|
||||
/* Uncomment (and remove this text!) to get reduced vertical space in
|
||||
compound paragraphs.
|
||||
div.compound .compound-first, div.compound .compound-middle {
|
||||
margin-bottom: 0.5em }
|
||||
|
||||
div.compound .compound-last, div.compound .compound-middle {
|
||||
margin-top: 0.5em }
|
||||
*/
|
||||
|
||||
div.dedication {
|
||||
margin: 2em 5em ;
|
||||
text-align: center ;
|
||||
font-style: italic }
|
||||
|
||||
div.dedication p.topic-title {
|
||||
font-weight: bold ;
|
||||
font-style: normal }
|
||||
|
||||
div.figure {
|
||||
margin-left: 2em ;
|
||||
margin-right: 2em }
|
||||
|
||||
div.footer, div.header {
|
||||
clear: both;
|
||||
font-size: smaller }
|
||||
|
||||
div.line-block {
|
||||
display: block ;
|
||||
margin-top: 1em ;
|
||||
margin-bottom: 1em }
|
||||
|
||||
div.line-block div.line-block {
|
||||
margin-top: 0 ;
|
||||
margin-bottom: 0 ;
|
||||
margin-left: 1.5em }
|
||||
|
||||
div.sidebar {
|
||||
margin: 0 0 0.5em 1em ;
|
||||
border: medium outset ;
|
||||
padding: 1em ;
|
||||
background-color: #ffffee ;
|
||||
width: 40% ;
|
||||
float: right ;
|
||||
clear: right }
|
||||
|
||||
div.sidebar p.rubric {
|
||||
font-family: sans-serif ;
|
||||
font-size: medium }
|
||||
|
||||
div.system-messages {
|
||||
margin: 5em }
|
||||
|
||||
div.system-messages h1 {
|
||||
color: red }
|
||||
|
||||
div.system-message {
|
||||
border: medium outset ;
|
||||
padding: 1em }
|
||||
|
||||
div.system-message p.system-message-title {
|
||||
color: red ;
|
||||
font-weight: bold }
|
||||
|
||||
div.topic {
|
||||
margin: 2em }
|
||||
|
||||
h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
|
||||
h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
|
||||
margin-top: 0.4em }
|
||||
|
||||
h1.title {
|
||||
text-align: center }
|
||||
|
||||
h2.subtitle {
|
||||
text-align: center }
|
||||
|
||||
hr.docutils {
|
||||
width: 75% }
|
||||
|
||||
img.align-left, .figure.align-left, object.align-left, table.align-left {
|
||||
clear: left ;
|
||||
float: left ;
|
||||
margin-right: 1em }
|
||||
|
||||
img.align-right, .figure.align-right, object.align-right, table.align-right {
|
||||
clear: right ;
|
||||
float: right ;
|
||||
margin-left: 1em }
|
||||
|
||||
img.align-center, .figure.align-center, object.align-center {
|
||||
display: block;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
table.align-center {
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
.align-left {
|
||||
text-align: left }
|
||||
|
||||
.align-center {
|
||||
clear: both ;
|
||||
text-align: center }
|
||||
|
||||
.align-right {
|
||||
text-align: right }
|
||||
|
||||
/* reset inner alignment in figures */
|
||||
div.align-right {
|
||||
text-align: inherit }
|
||||
|
||||
/* div.align-center * { */
|
||||
/* text-align: left } */
|
||||
|
||||
.align-top {
|
||||
vertical-align: top }
|
||||
|
||||
.align-middle {
|
||||
vertical-align: middle }
|
||||
|
||||
.align-bottom {
|
||||
vertical-align: bottom }
|
||||
|
||||
ol.simple, ul.simple {
|
||||
margin-bottom: 1em }
|
||||
|
||||
ol.arabic {
|
||||
list-style: decimal }
|
||||
|
||||
ol.loweralpha {
|
||||
list-style: lower-alpha }
|
||||
|
||||
ol.upperalpha {
|
||||
list-style: upper-alpha }
|
||||
|
||||
ol.lowerroman {
|
||||
list-style: lower-roman }
|
||||
|
||||
ol.upperroman {
|
||||
list-style: upper-roman }
|
||||
|
||||
p.attribution {
|
||||
text-align: right ;
|
||||
margin-left: 50% }
|
||||
|
||||
p.caption {
|
||||
font-style: italic }
|
||||
|
||||
p.credits {
|
||||
font-style: italic ;
|
||||
font-size: smaller }
|
||||
|
||||
p.label {
|
||||
white-space: nowrap }
|
||||
|
||||
p.rubric {
|
||||
font-weight: bold ;
|
||||
font-size: larger ;
|
||||
color: maroon ;
|
||||
text-align: center }
|
||||
|
||||
p.sidebar-title {
|
||||
font-family: sans-serif ;
|
||||
font-weight: bold ;
|
||||
font-size: larger }
|
||||
|
||||
p.sidebar-subtitle {
|
||||
font-family: sans-serif ;
|
||||
font-weight: bold }
|
||||
|
||||
p.topic-title {
|
||||
font-weight: bold }
|
||||
|
||||
pre.address {
|
||||
margin-bottom: 0 ;
|
||||
margin-top: 0 ;
|
||||
font: inherit }
|
||||
|
||||
pre.literal-block, pre.doctest-block, pre.math, pre.code {
|
||||
margin-left: 2em ;
|
||||
margin-right: 2em }
|
||||
|
||||
pre.code .ln { color: grey; } /* line numbers */
|
||||
pre.code, code { background-color: #eeeeee }
|
||||
pre.code .comment, code .comment { color: #5C6576 }
|
||||
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
|
||||
pre.code .literal.string, code .literal.string { color: #0C5404 }
|
||||
pre.code .name.builtin, code .name.builtin { color: #352B84 }
|
||||
pre.code .deleted, code .deleted { background-color: #DEB0A1}
|
||||
pre.code .inserted, code .inserted { background-color: #A3D289}
|
||||
|
||||
span.classifier {
|
||||
font-family: sans-serif ;
|
||||
font-style: oblique }
|
||||
|
||||
span.classifier-delimiter {
|
||||
font-family: sans-serif ;
|
||||
font-weight: bold }
|
||||
|
||||
span.interpreted {
|
||||
font-family: sans-serif }
|
||||
|
||||
span.option {
|
||||
white-space: nowrap }
|
||||
|
||||
span.pre {
|
||||
white-space: pre }
|
||||
|
||||
span.problematic {
|
||||
color: red }
|
||||
|
||||
span.section-subtitle {
|
||||
/* font-size relative to parent (h1..h6 element) */
|
||||
font-size: 80% }
|
||||
|
||||
table.citation {
|
||||
border-left: solid 1px gray;
|
||||
margin-left: 1px }
|
||||
|
||||
table.docinfo {
|
||||
margin: 2em 4em }
|
||||
|
||||
table.docutils {
|
||||
margin-top: 0.5em ;
|
||||
margin-bottom: 0.5em }
|
||||
|
||||
table.footnote {
|
||||
border-left: solid 1px black;
|
||||
margin-left: 1px }
|
||||
|
||||
table.docutils td, table.docutils th,
|
||||
table.docinfo td, table.docinfo th {
|
||||
padding-left: 0.5em ;
|
||||
padding-right: 0.5em ;
|
||||
vertical-align: top }
|
||||
|
||||
table.docutils th.field-name, table.docinfo th.docinfo-name {
|
||||
font-weight: bold ;
|
||||
text-align: left ;
|
||||
white-space: nowrap ;
|
||||
padding-left: 0 }
|
||||
|
||||
/* "booktabs" style (no vertical lines) */
|
||||
table.docutils.booktabs {
|
||||
border: 0px;
|
||||
border-top: 2px solid;
|
||||
border-bottom: 2px solid;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
table.docutils.booktabs * {
|
||||
border: 0px;
|
||||
}
|
||||
table.docutils.booktabs th {
|
||||
border-bottom: thin solid;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
|
||||
h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
|
||||
font-size: 100% }
|
||||
|
||||
ul.auto-toc {
|
||||
list-style-type: none }
|
||||
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="document" id="stock-card-report">
|
||||
<h1 class="title">Stock Card Report</h1>
|
||||
|
||||
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
!! This file is generated by oca-gen-addon-readme !!
|
||||
!! changes will be overwritten. !!
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
|
||||
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/stock-logistics-reporting/tree/12.0/stock_card_report"><img alt="OCA/stock-logistics-reporting" src="https://img.shields.io/badge/github-OCA%2Fstock--logistics--reporting-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/stock-logistics-reporting-12-0/stock-logistics-reporting-12-0-stock_card_report"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/151/12.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
|
||||
<p>Stock Card Report is the report that display movement (in/out) of a product in a specified location and date range.</p>
|
||||
<p><strong>Table of contents</strong></p>
|
||||
<div class="contents local topic" id="contents">
|
||||
<ul class="simple">
|
||||
<li><a class="reference internal" href="#usage" id="id1">Usage</a></li>
|
||||
<li><a class="reference internal" href="#bug-tracker" id="id2">Bug Tracker</a></li>
|
||||
<li><a class="reference internal" href="#credits" id="id3">Credits</a><ul>
|
||||
<li><a class="reference internal" href="#authors" id="id4">Authors</a></li>
|
||||
<li><a class="reference internal" href="#contributors" id="id5">Contributors</a></li>
|
||||
<li><a class="reference internal" href="#maintainers" id="id6">Maintainers</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="usage">
|
||||
<h1><a class="toc-backref" href="#id1">Usage</a></h1>
|
||||
<p>To use this module, you need to:</p>
|
||||
<ol class="arabic simple">
|
||||
<li>Go to Inventory > Reporting > Stock Card.</li>
|
||||
<li>Select Start date, End date, Products, Location.</li>
|
||||
<li>Choose View or Export PDF or Export XLSX or Cancel.</li>
|
||||
</ol>
|
||||
</div>
|
||||
<div class="section" id="bug-tracker">
|
||||
<h1><a class="toc-backref" href="#id2">Bug Tracker</a></h1>
|
||||
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/stock-logistics-reporting/issues">GitHub Issues</a>.
|
||||
In case of trouble, please check there if your issue has already been reported.
|
||||
If you spotted it first, help us smashing it by providing a detailed and welcomed
|
||||
<a class="reference external" href="https://github.com/OCA/stock-logistics-reporting/issues/new?body=module:%20stock_card_report%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
|
||||
<p>Do not contact contributors directly about support or help with technical issues.</p>
|
||||
</div>
|
||||
<div class="section" id="credits">
|
||||
<h1><a class="toc-backref" href="#id3">Credits</a></h1>
|
||||
<div class="section" id="authors">
|
||||
<h2><a class="toc-backref" href="#id4">Authors</a></h2>
|
||||
<ul class="simple">
|
||||
<li>Ecosoft</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="contributors">
|
||||
<h2><a class="toc-backref" href="#id5">Contributors</a></h2>
|
||||
<ul class="simple">
|
||||
<li>Pimolnat Suntian <<a class="reference external" href="mailto:pimolnats@ecosoft.co.th">pimolnats@ecosoft.co.th</a>></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="maintainers">
|
||||
<h2><a class="toc-backref" href="#id6">Maintainers</a></h2>
|
||||
<p>This module is maintained by the OCA.</p>
|
||||
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
|
||||
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
|
||||
mission is to support the collaborative development of Odoo features and
|
||||
promote its widespread use.</p>
|
||||
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/stock-logistics-reporting/tree/12.0/stock_card_report">OCA/stock-logistics-reporting</a> project on GitHub.</p>
|
||||
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
59
stock_card_report/static/src/css/report.css
Normal file
59
stock_card_report/static/src/css/report.css
Normal file
@@ -0,0 +1,59 @@
|
||||
.act_as_table {
|
||||
display: table !important;
|
||||
background-color: white;
|
||||
}
|
||||
.act_as_row {
|
||||
display: table-row !important;
|
||||
page-break-inside: avoid;
|
||||
}
|
||||
.act_as_cell {
|
||||
display: table-cell !important;
|
||||
page-break-inside: avoid;
|
||||
}
|
||||
.act_as_thead {
|
||||
display: table-header-group !important;
|
||||
}
|
||||
.act_as_row.labels {
|
||||
background-color:#F0F0F0 !important;
|
||||
}
|
||||
.data_table {
|
||||
width: 100% !important;
|
||||
border-left:0px;
|
||||
border-right:0px;
|
||||
text-align:center;
|
||||
font-size:10px;
|
||||
padding-right:3px;
|
||||
padding-left:3px;
|
||||
padding-top:2px;
|
||||
padding-bottom:2px;
|
||||
border-collapse:collapse;
|
||||
}
|
||||
.data_table .act_as_cell{
|
||||
border: 1px solid lightGrey;
|
||||
text-align: center;
|
||||
}
|
||||
.data_table .act_as_cell {
|
||||
word-wrap: break-word;
|
||||
}
|
||||
.data_table .act_as_row.labels {
|
||||
font-weight: bold;
|
||||
}
|
||||
.act_as_cell.left {
|
||||
text-align:left;
|
||||
}
|
||||
.act_as_cell.right {
|
||||
text-align:right;
|
||||
}
|
||||
.custom_footer {
|
||||
font-size:7px !important;
|
||||
}
|
||||
.button_row {
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
.o_stock_card_reports_page {
|
||||
padding-top: 10px;
|
||||
width: 90%;
|
||||
margin-right: auto;
|
||||
margin-left: auto;
|
||||
font-family: Helvetica, Arial;
|
||||
}
|
||||
112
stock_card_report/static/src/js/stock_card_report_backend.js
Normal file
112
stock_card_report/static/src/js/stock_card_report_backend.js
Normal file
@@ -0,0 +1,112 @@
|
||||
odoo.define('stock_card_report.stock_card_report_backend', function (require) {
|
||||
'use strict';
|
||||
|
||||
var core = require('web.core');
|
||||
var Widget = require('web.Widget');
|
||||
var ControlPanelMixin = require('web.ControlPanelMixin');
|
||||
var ReportWidget = require('web.Widget');
|
||||
|
||||
|
||||
var report_backend = Widget.extend(ControlPanelMixin, {
|
||||
// Stores all the parameters of the action.
|
||||
events: {
|
||||
'click .o_stock_card_reports_print': 'print',
|
||||
'click .o_stock_card_reports_export': 'export',
|
||||
},
|
||||
init: function (parent, action) {
|
||||
this.actionManager = parent;
|
||||
this.given_context = {};
|
||||
this.odoo_context = action.context;
|
||||
this.controller_url = action.context.url;
|
||||
if (action.context.context) {
|
||||
this.given_context = action.context.context;
|
||||
}
|
||||
this.given_context.active_id = action.context.active_id ||
|
||||
action.params.active_id;
|
||||
this.given_context.model = action.context.active_model || false;
|
||||
this.given_context.ttype = action.context.ttype || false;
|
||||
return this._super.apply(this, arguments);
|
||||
},
|
||||
willStart: function () {
|
||||
return $.when(this.get_html());
|
||||
},
|
||||
set_html: function () {
|
||||
var self = this;
|
||||
var def = $.when();
|
||||
if (!this.report_widget) {
|
||||
this.report_widget = new ReportWidget(this, this.given_context);
|
||||
def = this.report_widget.appendTo(this.$el);
|
||||
}
|
||||
def.then(function () {
|
||||
self.report_widget.$el.html(self.html);
|
||||
});
|
||||
},
|
||||
start: function () {
|
||||
this.set_html();
|
||||
return this._super();
|
||||
},
|
||||
// Fetches the html and is previous report.context if any,
|
||||
// else create it
|
||||
get_html: function () {
|
||||
var self = this;
|
||||
var defs = [];
|
||||
return this._rpc({
|
||||
model: this.given_context.model,
|
||||
method: 'get_html',
|
||||
args: [self.given_context],
|
||||
context: self.odoo_context,
|
||||
})
|
||||
.then(function (result) {
|
||||
self.html = result.html;
|
||||
defs.push(self.update_cp());
|
||||
return $.when.apply($, defs);
|
||||
});
|
||||
},
|
||||
// Updates the control panel and render the elements that have yet
|
||||
// to be rendered
|
||||
update_cp: function () {
|
||||
if (this.$buttons) {
|
||||
var status = {
|
||||
breadcrumbs: this.actionManager.get_breadcrumbs(),
|
||||
cp_content: {$buttons: this.$buttons},
|
||||
};
|
||||
return this.update_control_panel(status);
|
||||
}
|
||||
},
|
||||
do_show: function () {
|
||||
this._super();
|
||||
this.update_cp();
|
||||
},
|
||||
print: function () {
|
||||
var self = this;
|
||||
this._rpc({
|
||||
model: this.given_context.model,
|
||||
method: 'print_report',
|
||||
args: [this.given_context.active_id, 'qweb-pdf'],
|
||||
context: self.odoo_context,
|
||||
}).then(function (result) {
|
||||
self.do_action(result);
|
||||
});
|
||||
},
|
||||
export: function () {
|
||||
var self = this;
|
||||
this._rpc({
|
||||
model: this.given_context.model,
|
||||
method: 'print_report',
|
||||
args: [this.given_context.active_id, 'xlsx'],
|
||||
context: self.odoo_context,
|
||||
}).then(function (result) {
|
||||
self.do_action(result);
|
||||
});
|
||||
},
|
||||
canBeRemoved: function () {
|
||||
return $.when();
|
||||
},
|
||||
});
|
||||
|
||||
core.action_registry.add(
|
||||
"stock_card_report_backend",
|
||||
report_backend
|
||||
);
|
||||
return report_backend;
|
||||
});
|
||||
4
stock_card_report/tests/__init__.py
Normal file
4
stock_card_report/tests/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
||||
# Copyright 2019 Ecosoft Co., Ltd. (http://ecosoft.co.th)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from . import test_stock_card_report
|
||||
223
stock_card_report/tests/test_stock_card_report.py
Normal file
223
stock_card_report/tests/test_stock_card_report.py
Normal file
@@ -0,0 +1,223 @@
|
||||
# Copyright 2019 Ecosoft Co., Ltd. (http://ecosoft.co.th)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
import time
|
||||
import logging
|
||||
from datetime import date
|
||||
from odoo.tests import common
|
||||
from odoo.tools import test_reports
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class TestStockCard(common.TransactionCase):
|
||||
|
||||
def setUp(cls):
|
||||
super(TestStockCard, cls).setUp()
|
||||
|
||||
# Create uom:
|
||||
uom_id = cls.ref('uom.product_uom_unit')
|
||||
|
||||
# Create products:
|
||||
cls.product_A = cls.env['product.product'].create({
|
||||
'name': 'Product A',
|
||||
'type': 'product',
|
||||
'uom_id': uom_id,
|
||||
'uom_po_id': uom_id,
|
||||
})
|
||||
|
||||
# Create location:
|
||||
cls.location_1 = cls.env.ref('stock.stock_location_stock')
|
||||
cls.location_2 = cls.env.ref('stock.stock_location_customers')
|
||||
|
||||
# Create operation type:
|
||||
operation_type = cls.env.ref('stock.picking_type_in')
|
||||
|
||||
# Create stock picking:
|
||||
picking = cls.env['stock.picking'].create({
|
||||
'location_id': cls.location_2.id,
|
||||
'location_dest_id': cls.location_1.id,
|
||||
'picking_type_id': operation_type.id,
|
||||
})
|
||||
cls.env['stock.move'].create({
|
||||
'name': cls.product_A.name,
|
||||
'product_id': cls.product_A.id,
|
||||
'product_uom_qty': 50.000,
|
||||
'product_uom': cls.product_A.uom_id.id,
|
||||
'picking_id': picking.id,
|
||||
'location_id': cls.location_2.id,
|
||||
'location_dest_id': cls.location_1.id,
|
||||
})
|
||||
picking.action_confirm()
|
||||
picking.move_ids_without_package.quantity_done = 50.000
|
||||
picking.button_validate()
|
||||
|
||||
cls.model = cls._getReportModel()
|
||||
|
||||
cls.qweb_report_name = cls._getQwebReportName()
|
||||
cls.xlsx_report_name = cls._getXlsxReportName()
|
||||
cls.xlsx_action_name = cls._getXlsxReportActionName()
|
||||
|
||||
cls.report_title = cls._getReportTitle()
|
||||
|
||||
cls.base_filters = cls._getBaseFilters()
|
||||
|
||||
cls.report = cls.model.create(cls.base_filters)
|
||||
cls.report._compute_results()
|
||||
|
||||
def test_html(self):
|
||||
test_reports.try_report(self.env.cr, self.env.uid,
|
||||
self.qweb_report_name,
|
||||
[self.report.id],
|
||||
report_type='qweb-html')
|
||||
|
||||
def test_qweb(self):
|
||||
test_reports.try_report(self.env.cr, self.env.uid,
|
||||
self.qweb_report_name,
|
||||
[self.report.id],
|
||||
report_type='qweb-pdf')
|
||||
|
||||
def test_xlsx(self):
|
||||
test_reports.try_report(self.env.cr, self.env.uid,
|
||||
self.xlsx_report_name,
|
||||
[self.report.id],
|
||||
report_type='xlsx')
|
||||
|
||||
def test_print(self):
|
||||
self.report.print_report('qweb')
|
||||
self.report.print_report('xlsx')
|
||||
|
||||
def _getReportModel(self):
|
||||
return self.env['report.stock.card.report']
|
||||
|
||||
def _getQwebReportName(self):
|
||||
return 'stock_card_report.report_stock_card_report_pdf'
|
||||
|
||||
def _getXlsxReportName(self):
|
||||
return 'stock_card_report.report_stock_card_report_xlsx'
|
||||
|
||||
def _getXlsxReportActionName(self):
|
||||
return 'stock_card_report.action_report_stock_card_report_xlsx'
|
||||
|
||||
def _getReportTitle(self):
|
||||
return 'Stock Card Report'
|
||||
|
||||
def _getBaseFilters(self):
|
||||
return {
|
||||
'product_ids': [(6, 0, [self.product_A.id])],
|
||||
'location_id': self.location_1.id,
|
||||
}
|
||||
|
||||
|
||||
class TestStockCardReport(common.TransactionCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestStockCardReport, self).setUp()
|
||||
|
||||
# Create uom:
|
||||
uom_id = self.ref('uom.product_uom_unit')
|
||||
|
||||
# Create products:
|
||||
self.product_A = self.env['product.product'].create({
|
||||
'name': 'Product A',
|
||||
'type': 'product',
|
||||
'uom_id': uom_id,
|
||||
'uom_po_id': uom_id,
|
||||
})
|
||||
self.product_B = self.env['product.product'].create({
|
||||
'name': 'Product B',
|
||||
'type': 'product',
|
||||
'uom_id': uom_id,
|
||||
'uom_po_id': uom_id,
|
||||
})
|
||||
|
||||
# Create location:
|
||||
self.location_1 = self.env.ref('stock.stock_location_stock')
|
||||
self.location_2 = self.env.ref('stock.stock_location_customers')
|
||||
|
||||
# Create operation type:
|
||||
operation_type = self.env.ref('stock.picking_type_in')
|
||||
|
||||
# Create stock picking:
|
||||
picking_1 = self.env['stock.picking'].create({
|
||||
'location_id': self.location_2.id,
|
||||
'location_dest_id': self.location_1.id,
|
||||
'picking_type_id': operation_type.id,
|
||||
})
|
||||
self.env['stock.move'].create({
|
||||
'name': self.product_A.name,
|
||||
'product_id': self.product_A.id,
|
||||
'product_uom_qty': 50.000,
|
||||
'product_uom': self.product_A.uom_id.id,
|
||||
'picking_id': picking_1.id,
|
||||
'location_id': self.location_2.id,
|
||||
'location_dest_id': self.location_1.id,
|
||||
})
|
||||
picking_1.action_confirm()
|
||||
picking_1.move_ids_without_package.quantity_done = 50.000
|
||||
picking_1.button_validate()
|
||||
|
||||
picking_2 = self.env['stock.picking'].create({
|
||||
'location_id': self.location_2.id,
|
||||
'location_dest_id': self.location_1.id,
|
||||
'picking_type_id': operation_type.id,
|
||||
})
|
||||
self.env['stock.move'].create({
|
||||
'name': self.product_B.name,
|
||||
'product_id': self.product_B.id,
|
||||
'product_uom_qty': 100.000,
|
||||
'product_uom': self.product_B.uom_id.id,
|
||||
'picking_id': picking_2.id,
|
||||
'location_id': self.location_2.id,
|
||||
'location_dest_id': self.location_1.id,
|
||||
})
|
||||
picking_2.action_confirm()
|
||||
picking_2.move_ids_without_package.quantity_done = 100.000
|
||||
picking_2.button_validate()
|
||||
|
||||
def test_reports(self):
|
||||
report = self.env['report.stock.card.report'].create({
|
||||
'product_ids': [(6, 0, [self.product_A.id, self.product_B.id])],
|
||||
'location_id': self.location_1.id,
|
||||
})
|
||||
report._compute_results()
|
||||
report.print_report('qweb')
|
||||
report.print_report('xlsx')
|
||||
|
||||
def test_get_report_html(self):
|
||||
report = self.env['report.stock.card.report'].create({
|
||||
'product_ids': [(6, 0, [self.product_A.id, self.product_B.id])],
|
||||
'location_id': self.location_1.id,
|
||||
})
|
||||
report._compute_results()
|
||||
report.get_html(given_context={
|
||||
'active_id': report.id
|
||||
})
|
||||
|
||||
def test_wizard_date_range(self):
|
||||
date_range = self.env['date.range']
|
||||
self.type = self.env['date.range.type'].create(
|
||||
{'name': 'Month',
|
||||
'company_id': False,
|
||||
'allow_overlap': False})
|
||||
dt = date_range.create({
|
||||
'name': 'FiscalYear',
|
||||
'date_start': time.strftime('%Y-%m-01'),
|
||||
'date_end': time.strftime('%Y-%m-28'),
|
||||
'type_id': self.type.id,
|
||||
})
|
||||
wizard = self.env['stock.card.report.wizard'].create(
|
||||
{'date_range_id': dt.id,
|
||||
'date_from': time.strftime('%Y-%m-28'),
|
||||
'date_to': time.strftime('%Y-%m-01'),
|
||||
'product_ids': [(6, 0, [self.product_A.id, self.product_B.id])],
|
||||
'location_id': self.location_1.id})
|
||||
wizard._onchange_date_range_id()
|
||||
self.assertEqual(wizard.date_from, date(
|
||||
date.today().year, date.today().month, 1))
|
||||
self.assertEqual(wizard.date_to, date(
|
||||
date.today().year, date.today().month, 28))
|
||||
wizard._export('qweb-pdf')
|
||||
wizard.button_export_html()
|
||||
wizard.button_export_pdf()
|
||||
wizard.button_export_xlsx()
|
||||
4
stock_card_report/wizard/__init__.py
Normal file
4
stock_card_report/wizard/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
||||
# Copyright 2019 Ecosoft Co., Ltd. (http://ecosoft.co.th)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from . import stock_card_report_wizard
|
||||
79
stock_card_report/wizard/stock_card_report_wizard.py
Normal file
79
stock_card_report/wizard/stock_card_report_wizard.py
Normal file
@@ -0,0 +1,79 @@
|
||||
# Copyright 2019 Ecosoft Co., Ltd. (http://ecosoft.co.th)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import api, fields, models
|
||||
from odoo.tools.safe_eval import safe_eval
|
||||
from odoo.tools import pycompat
|
||||
|
||||
|
||||
class StockCardReportWizard(models.TransientModel):
|
||||
_name = 'stock.card.report.wizard'
|
||||
_description = 'Stock Card Report Wizard'
|
||||
|
||||
date_range_id = fields.Many2one(
|
||||
comodel_name='date.range',
|
||||
string='Period',
|
||||
)
|
||||
date_from = fields.Date(
|
||||
string='Start Date',
|
||||
)
|
||||
date_to = fields.Date(
|
||||
string='End Date',
|
||||
)
|
||||
location_id = fields.Many2one(
|
||||
comodel_name='stock.location',
|
||||
string='Location',
|
||||
required=True,
|
||||
)
|
||||
product_ids = fields.Many2many(
|
||||
comodel_name='product.product',
|
||||
string='Products',
|
||||
required=True,
|
||||
)
|
||||
|
||||
@api.onchange('date_range_id')
|
||||
def _onchange_date_range_id(self):
|
||||
self.date_from = self.date_range_id.date_start
|
||||
self.date_to = self.date_range_id.date_end
|
||||
|
||||
@api.multi
|
||||
def button_export_html(self):
|
||||
self.ensure_one()
|
||||
action = self.env.ref(
|
||||
'stock_card_report.action_report_stock_card_report_html')
|
||||
vals = action.read()[0]
|
||||
context1 = vals.get('context', {})
|
||||
if isinstance(context1, pycompat.string_types):
|
||||
context1 = safe_eval(context1)
|
||||
model = self.env['report.stock.card.report']
|
||||
report = model.create(self._prepare_stock_card_report())
|
||||
context1['active_id'] = report.id
|
||||
context1['active_ids'] = report.ids
|
||||
vals['context'] = context1
|
||||
return vals
|
||||
|
||||
@api.multi
|
||||
def button_export_pdf(self):
|
||||
self.ensure_one()
|
||||
report_type = 'qweb-pdf'
|
||||
return self._export(report_type)
|
||||
|
||||
@api.multi
|
||||
def button_export_xlsx(self):
|
||||
self.ensure_one()
|
||||
report_type = 'xlsx'
|
||||
return self._export(report_type)
|
||||
|
||||
def _prepare_stock_card_report(self):
|
||||
self.ensure_one()
|
||||
return {
|
||||
'date_from': self.date_from,
|
||||
'date_to': self.date_to,
|
||||
'product_ids': [(6, 0, self.product_ids.ids)],
|
||||
'location_id': self.location_id.id,
|
||||
}
|
||||
|
||||
def _export(self, report_type):
|
||||
model = self.env['report.stock.card.report']
|
||||
report = model.create(self._prepare_stock_card_report())
|
||||
return report.print_report(report_type)
|
||||
46
stock_card_report/wizard/stock_card_report_wizard_view.xml
Normal file
46
stock_card_report/wizard/stock_card_report_wizard_view.xml
Normal file
@@ -0,0 +1,46 @@
|
||||
<odoo>
|
||||
|
||||
<record id="stock_card_report_wizard_form" model="ir.ui.view">
|
||||
<field name="name">stock.card.report.wizard.form</field>
|
||||
<field name="model">stock.card.report.wizard</field>
|
||||
<field name="arch" type="xml">
|
||||
<form>
|
||||
<group name="criteria">
|
||||
<group>
|
||||
<field name="date_range_id"/>
|
||||
<field name="date_from"/>
|
||||
<field name="date_to"/>
|
||||
</group>
|
||||
<group>
|
||||
<field name="product_ids" widget="many2many_tags"/>
|
||||
<field name="location_id"/>
|
||||
</group>
|
||||
</group>
|
||||
<footer>
|
||||
<button name="button_export_html" string="View"
|
||||
type="object" default_focus="1" class="oe_highlight"/>
|
||||
or
|
||||
<button name="button_export_pdf" string="Export PDF" type="object"/>
|
||||
or
|
||||
<button name="button_export_xlsx" string="Export XLSX" type="object"/>
|
||||
or
|
||||
<button string="Cancel" class="oe_link" special="cancel" />
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="stock_card_report_action" model="ir.actions.act_window">
|
||||
<field name="name">Stock Card</field>
|
||||
<field name="res_model">stock.card.report.wizard</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
|
||||
<menuitem id="stock_card_report_menu"
|
||||
action="stock_card_report_action"
|
||||
parent="stock.menu_warehouse_report"
|
||||
sequence="30"/>
|
||||
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user