Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
304 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,4 @@ | |
|
||
from . import models | ||
from . import wizard | ||
from . import report |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# -*- coding: utf-8 -*- | ||
############################################################################## | ||
# | ||
# Copyright (c) 2016 Kmee - www.kmee.com.br | ||
# @authors Daniel Sadamo <daniel.sadamo@kmee.com.br> | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
############################################################################## | ||
|
||
from . import stock_valuation_history_xls |
162 changes: 162 additions & 0 deletions
162
l10n_br_stock_account/report/stock_valuation_history_xls.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
# -*- coding: utf-8 -*- | ||
############################################################################## | ||
# | ||
# Copyright (c) 2016 Kmee - www.kmee.com.br | ||
# @authors Daniel Sadamo <daniel.sadamo@kmee.com.br> | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
############################################################################## | ||
|
||
import xlwt | ||
from openerp.report import report_sxw | ||
from openerp.addons.report_xls.report_xls import report_xls | ||
from openerp.addons.report_xls.utils import _render | ||
import logging | ||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
class StockHistoryXlsParser(report_sxw.rml_parse): | ||
|
||
def __init__(self, cr, uid, name, context): | ||
super(StockHistoryXlsParser, self).__init__( | ||
cr, uid, name, context=context) | ||
self.context = context | ||
|
||
|
||
class StockHistoryXls(report_xls): | ||
|
||
def __init__(self, name, table, rml=False, parser=False, header=True, | ||
store=False): | ||
super(StockHistoryXls, self).__init__( | ||
name, table, rml, parser, header, store) | ||
|
||
# Cell Styles | ||
_xs = self.xls_styles | ||
# header | ||
rh_cell_format = _xs['bold'] + _xs['fill'] + \ | ||
_xs['borders_all'] + _xs['right'] | ||
self.rh_cell_style = xlwt.easyxf(rh_cell_format) | ||
self.rh_cell_style_center = xlwt.easyxf(rh_cell_format + _xs['center']) | ||
self.rh_cell_style_right = xlwt.easyxf(rh_cell_format + _xs['right']) | ||
self.rh_cell_style_date = xlwt.easyxf( | ||
rh_cell_format, num_format_str=report_xls.date_format) | ||
# lines | ||
line_cell_format = _xs['borders_all'] | ||
self.line_cell_style_decimal = xlwt.easyxf( | ||
line_cell_format + _xs['right'], | ||
num_format_str=report_xls.decimal_format) | ||
self.line_cell_style = xlwt.easyxf(line_cell_format) | ||
|
||
self.col_specs_template = { | ||
'fiscal_classification_id': { | ||
'header': [1, 10, 'text', _render("('NCM')")], | ||
'lines': [1, 0, 'text', | ||
_render("line.get('fiscal_classification_id', '')")], | ||
'totals': [1, 0, 'text', None]}, | ||
'product_id': { | ||
'header': [1, 50, 'text', _render("('Produto')")], | ||
'lines': [1, 0, 'text', | ||
_render("line.get('product_id', False) and " | ||
"line.get('product_id')[1] or ''")], | ||
'totals': [1, 0, 'text', None]}, | ||
# 'product_id_count': { | ||
# 'header': [1, 20, 'text', _render("('Contagem')")], | ||
# 'lines': [1, 0, 'text', | ||
# _render("str(line.get('product_id_count', "") or '')")], | ||
# 'totals': [1, 0, 'text', None]}, | ||
'price_unit_on_quant': { | ||
'header': [1, 25, 'text', | ||
_render("('Preço de custo no periodo')")], | ||
'lines': [1, 0, 'number', | ||
_render("line.get('price_unit_on_quant')"), | ||
None, self.line_cell_style_decimal], | ||
'totals': [1, 0, 'text', None]}, | ||
'quantity': { | ||
'header': [1, 15, 'text', _render("('Quantidade')")], | ||
'lines': [1, 0, 'number', _render("line.get('quantity', 0)")], | ||
'totals': [1, 0, 'text', None]}, | ||
'inventory_value': { | ||
'header': [1, 15, 'text', _render("('Valor Total')")], | ||
'lines': [1, 0, 'number', | ||
_render("line.get('inventory_value', 0)"), | ||
None, self.line_cell_style_decimal], | ||
'totals': [1, 0, 'text', None]}, | ||
} | ||
|
||
def generate_xls_report(self, _p, _xs, data, objects, wb): | ||
|
||
report_name = 'Relatório de Valorização de Estoque' | ||
ws = wb.add_sheet(report_name[:31]) | ||
ws.panes_frozen = True | ||
ws.remove_splits = True | ||
ws.portrait = 0 # Landscape | ||
ws.fit_width_to_pages = 1 | ||
row_pos = 0 | ||
|
||
# set print header/footer | ||
ws.header_str = self.xls_headers['standard'] | ||
ws.footer_str = self.xls_footers['standard'] | ||
|
||
# Title | ||
c_specs = [ | ||
('report_name', 1, 0, 'text', report_name), | ||
] | ||
row_data = self.xls_row_template(c_specs, ['report_name']) | ||
row_pos = self.xls_write_row( | ||
ws, row_pos, row_data, row_style=xlwt.easyxf(_xs['xls_title'])) | ||
row_pos += 1 | ||
|
||
# Column headers | ||
c_specs = map(lambda x: self.render( | ||
x, self.col_specs_template, 'header'), | ||
[ | ||
'product_id', | ||
'fiscal_classification_id', | ||
# 'product_id_count', | ||
'quantity', | ||
'price_unit_on_quant', | ||
'inventory_value' | ||
]) | ||
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) | ||
row_pos = self.xls_write_row( | ||
ws, row_pos, row_data, row_style=self.rh_cell_style_center, | ||
set_column_size=True) | ||
ws.set_horz_split_pos(row_pos) | ||
|
||
# Lines | ||
active_ids = self.context.get('active_ids') | ||
wizard_obj = self.pool.get('wizard.valuation.history').browse( | ||
self.cr, self.uid, active_ids) | ||
data = wizard_obj.compute( | ||
self.cr, self.uid, objects[0].id, date=wizard_obj.date) | ||
for line in data: | ||
c_specs = map( | ||
lambda x: self.render( | ||
x, self.col_specs_template, 'lines'), [ | ||
'product_id', | ||
'fiscal_classification_id', | ||
# 'product_id_count', | ||
'quantity', | ||
'price_unit_on_quant', | ||
'inventory_value' | ||
]) | ||
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs]) | ||
row_pos = self.xls_write_row( | ||
ws, row_pos, row_data, row_style=self.line_cell_style) | ||
pass | ||
|
||
|
||
StockHistoryXls('report.wizard.valuation.history', | ||
'wizard.valuation.history', parser=StockHistoryXlsParser) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,4 @@ | |
|
||
from . import stock_invoice_onshipping | ||
from . import stock_return_picking | ||
from . import stock_valuation_history |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# -*- coding: utf-8 -*- | ||
############################################################################## | ||
# | ||
# Copyright (c) 2016 Kmee - www.kmee.com.br | ||
# @authors Daniel Sadamo <daniel.sadamo@kmee.com.br> | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
############################################################################## | ||
|
||
from openerp import models, fields, api | ||
from openerp.osv import osv | ||
|
||
|
||
class WizardValuationHistory(models.TransientModel): | ||
_inherit = 'wizard.valuation.history' | ||
|
||
@api.multi | ||
def compute(self, cr, uid, ids, date): | ||
ctx = dict(self._context) | ||
ctx['history_date'] = date | ||
fields = [ | ||
'fiscal_classification_id', | ||
'product_id', | ||
'location_id', | ||
'move_id', | ||
'company_id', | ||
'date', | ||
'source', | ||
'quantity', | ||
'inventory_value', | ||
'price_unit_on_quant' | ||
] | ||
group_by = [ | ||
'product_id', | ||
'location_id', | ||
'fiscal_classification_id' | ||
] | ||
result = self.env['stock.history'].read_group(domain=[], fields=fields, | ||
groupby=group_by, | ||
context=ctx) | ||
return result | ||
|
||
|
||
class stock_history(osv.osv): | ||
_inherit = 'stock.history' | ||
|
||
def read_group(self, cr, uid, domain, fields, groupby, offset=0, | ||
limit=None, context=None, orderby=False, lazy=True): | ||
res = super(stock_history, self).read_group( | ||
cr, uid, domain, fields, groupby, offset=offset, limit=limit, | ||
context=context, orderby=orderby, lazy=lazy) | ||
|
||
if 'fiscal_classification_id' in fields: | ||
product_obj = self.pool.get('product.product') | ||
for line in res: | ||
product = product_obj.browse(cr, uid, line['product_id'][0]) | ||
fiscal_class = product.fiscal_classification_id.code | ||
line.update({'fiscal_classification_id': fiscal_class}) | ||
return res | ||
|
||
|
||
class StockHistory(models.Model): | ||
_inherit = 'stock.history' | ||
|
||
fiscal_classification_id = fields.Many2one( | ||
comodel_name='account.product.fiscal.classification', | ||
string='NCM', | ||
related='product_id.fiscal_classification_id' | ||
) |
30 changes: 30 additions & 0 deletions
30
l10n_br_stock_account/wizard/stock_valuation_history_view.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<openerp> | ||
<data> | ||
|
||
<record id="stock_history_xls_export" model="ir.actions.report.xml"> | ||
<field name="name">Valorização em XLS</field> | ||
<field name="model">wizard.valuation.history</field> | ||
<field name="type">ir.actions.report.xml</field> | ||
<field name="report_name">wizard.valuation.history</field> | ||
<field name="report_type">xls</field> | ||
<field name="auto" eval="False"/> | ||
</record> | ||
|
||
<record id="view_wizard_valuation_history" model="ir.ui.view"> | ||
<field name="name">Stock Valuation</field> | ||
<field name="model">wizard.valuation.history</field> | ||
<field name="inherit_id" ref="stock_account.view_wizard_valuation_history"/> | ||
<field name="arch" type="xml"> | ||
<button name="open_table" position="after"> | ||
<button icon="gtk-execute" | ||
name="%(stock_history_xls_export)d" | ||
string="Export XLS" | ||
type="action" | ||
colspan="2"/> | ||
</button> | ||
</field> | ||
</record> | ||
|
||
</data> | ||
</openerp> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
# add a github url if you need a forked version | ||
server-tools | ||
account-fiscal-rule | ||
reporting-engine |