mirror of
https://github.com/OCA/stock-logistics-reporting.git
synced 2025-02-16 17:13:21 +02:00
[12.0][fix] stock_card_report
This commit is contained in:
@@ -12,14 +12,14 @@
|
||||
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"
|
||||
print_report_name="'Stock Card Report - [%s]' % object.location_id.display_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"
|
||||
file="Stock Card Report"
|
||||
report_type="xlsx"
|
||||
attachment_use="False"/>
|
||||
|
||||
|
||||
@@ -46,12 +46,8 @@ class StockCardReport(models.TransientModel):
|
||||
@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)
|
||||
date_from = self.date_from or '0001-01-01'
|
||||
self.date_to = self.date_to or fields.Date.context_today(self)
|
||||
locations = self.env['stock.location'].search(
|
||||
[('id', 'child_of', [self.location_id.id])])
|
||||
self._cr.execute("""
|
||||
@@ -69,15 +65,12 @@ class StockCardReport(models.TransientModel):
|
||||
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), date_from,
|
||||
tuple(locations.ids), tuple(locations.ids),
|
||||
tuple(self.product_ids.ids+[0]), self.date_to))
|
||||
tuple(self.product_ids.ids), 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
|
||||
self.results = [ReportLine.new(line).id for line in stock_card_results]
|
||||
|
||||
@api.multi
|
||||
def _get_initial(self, product_line):
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
</template>
|
||||
|
||||
<template id="stock_card_report.report_stock_card_report_base">
|
||||
<t t-foreach="o.results.mapped('product_id')" t-as="product">
|
||||
<t t-foreach="o.product_ids" t-as="product">
|
||||
<div class="page">
|
||||
<div class="row">
|
||||
<t t-set="title">Stock Card - <t t-raw="product.name"/></t>
|
||||
|
||||
@@ -7,14 +7,13 @@ from odoo import models
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ReportStockCardReportXlsx(models.TransientModel):
|
||||
class ReportStockCardReportXlsx(models.AbstractModel):
|
||||
_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 product in objects.product_ids:
|
||||
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)
|
||||
@@ -25,7 +24,50 @@ class ReportStockCardReportXlsx(models.TransientModel):
|
||||
workbook, ws, ws_params, data, objects, product)
|
||||
|
||||
def _get_ws_params(self, wb, data, product):
|
||||
|
||||
filter_template = {
|
||||
'1_date_from': {
|
||||
'header': {
|
||||
'value': 'Date from',
|
||||
},
|
||||
'data': {
|
||||
'value': self._render('date_from'),
|
||||
'format': self.format_tcell_date_center,
|
||||
},
|
||||
},
|
||||
'2_date_to': {
|
||||
'header': {
|
||||
'value': 'Date to',
|
||||
},
|
||||
'data': {
|
||||
'value': self._render('date_to'),
|
||||
'format': self.format_tcell_date_center,
|
||||
},
|
||||
},
|
||||
'3_location': {
|
||||
'header': {
|
||||
'value': 'Location',
|
||||
},
|
||||
'data': {
|
||||
'value': self._render('location'),
|
||||
'format': self.format_tcell_center,
|
||||
},
|
||||
},
|
||||
}
|
||||
initial_template = {
|
||||
'1_ref': {
|
||||
'data': {
|
||||
'value': 'Initial',
|
||||
'format': self.format_tcell_center,
|
||||
},
|
||||
'colspan': 4,
|
||||
},
|
||||
'2_balance': {
|
||||
'data': {
|
||||
'value': self._render('balance'),
|
||||
'format': self.format_tcell_amount_right,
|
||||
},
|
||||
},
|
||||
}
|
||||
stock_card_template = {
|
||||
'1_date': {
|
||||
'header': {
|
||||
@@ -33,7 +75,6 @@ class ReportStockCardReportXlsx(models.TransientModel):
|
||||
},
|
||||
'data': {
|
||||
'value': self._render('date'),
|
||||
'type': 'datetime',
|
||||
'format': self.format_tcell_date_left,
|
||||
},
|
||||
'width': 25,
|
||||
@@ -44,6 +85,7 @@ class ReportStockCardReportXlsx(models.TransientModel):
|
||||
},
|
||||
'data': {
|
||||
'value': self._render('reference'),
|
||||
'format': self.format_tcell_left,
|
||||
},
|
||||
'width': 25,
|
||||
},
|
||||
@@ -53,9 +95,8 @@ class ReportStockCardReportXlsx(models.TransientModel):
|
||||
},
|
||||
'data': {
|
||||
'value': self._render('input'),
|
||||
'format': self.format_tcell_amount_right,
|
||||
},
|
||||
'width': 20,
|
||||
'width': 25,
|
||||
},
|
||||
'4_output': {
|
||||
'header': {
|
||||
@@ -63,9 +104,8 @@ class ReportStockCardReportXlsx(models.TransientModel):
|
||||
},
|
||||
'data': {
|
||||
'value': self._render('output'),
|
||||
'format': self.format_tcell_amount_right,
|
||||
},
|
||||
'width': 20,
|
||||
'width': 25,
|
||||
},
|
||||
'5_balance': {
|
||||
'header': {
|
||||
@@ -73,65 +113,69 @@ class ReportStockCardReportXlsx(models.TransientModel):
|
||||
},
|
||||
'data': {
|
||||
'value': self._render('balance'),
|
||||
'format': self.format_tcell_amount_right,
|
||||
},
|
||||
'width': 20,
|
||||
'width': 25,
|
||||
},
|
||||
}
|
||||
|
||||
ws_params = {
|
||||
'ws_name': product.name,
|
||||
'generate_ws_method': '_stock_card_report',
|
||||
'title': 'Stock Card Report - '+product.name,
|
||||
'title': 'Stock Card - {}'.format(product.name),
|
||||
'wanted_list_filter': [k for k in sorted(filter_template.keys())],
|
||||
'col_specs_filter': filter_template,
|
||||
'wanted_list_initial': [k for k in sorted(initial_template.keys())],
|
||||
'col_specs_initial': initial_template,
|
||||
'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)
|
||||
|
||||
# Title
|
||||
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
|
||||
# Filter Table
|
||||
row_pos = self._write_line(
|
||||
ws, row_pos, ws_params, col_specs_section='header',
|
||||
default_format=self.format_theader_blue_center,
|
||||
col_specs='col_specs_filter', wanted_list='wanted_list_filter')
|
||||
row_pos = self._write_line(
|
||||
ws, row_pos, ws_params, col_specs_section='data',
|
||||
render_space={
|
||||
'date_from': objects.date_from or '',
|
||||
'date_to': objects.date_to or '',
|
||||
'location': objects.location_id.display_name or '',
|
||||
},
|
||||
col_specs='col_specs_filter', wanted_list='wanted_list_filter')
|
||||
row_pos += 1
|
||||
# Stock Card Table
|
||||
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 = objects._get_initial(objects.results.filtered(
|
||||
lambda l: l.product_id == product and l.is_initial))
|
||||
row_pos = self._write_line(
|
||||
ws, row_pos, ws_params, col_specs_section='data',
|
||||
render_space={'balance': balance}, col_specs='col_specs_initial',
|
||||
wanted_list='wanted_list_initial')
|
||||
product_lines = objects.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='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)
|
||||
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,
|
||||
'output': line.product_out or 0,
|
||||
'balance': balance,
|
||||
},
|
||||
default_format=self.format_tcell_amount_right)
|
||||
|
||||
@@ -42,14 +42,14 @@ class StockCardReportWizard(models.TransientModel):
|
||||
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)
|
||||
context = vals.get('context', {})
|
||||
if isinstance(context, pycompat.string_types):
|
||||
context = safe_eval(context)
|
||||
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
|
||||
context['active_id'] = report.id
|
||||
context['active_ids'] = report.ids
|
||||
vals['context'] = context
|
||||
return vals
|
||||
|
||||
@api.multi
|
||||
@@ -68,7 +68,7 @@ class StockCardReportWizard(models.TransientModel):
|
||||
self.ensure_one()
|
||||
return {
|
||||
'date_from': self.date_from,
|
||||
'date_to': self.date_to,
|
||||
'date_to': self.date_to or fields.Date.context_today(self),
|
||||
'product_ids': [(6, 0, self.product_ids.ids)],
|
||||
'location_id': self.location_id.id,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user