Add module stock_history_ods

This commit is contained in:
Alexis de Lattre
2018-03-13 00:27:05 +01:00
parent da92731607
commit 0c94dde977
7 changed files with 111 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import wizard

View File

@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
'name': 'Stock History ODS',
'version': '10.0.1.0.0',
'category': 'Tools',
'license': 'AGPL-3',
'summary': 'Adds a Py3o ODS report on Inventory at Date',
'description': """
Stock History ODS
=================
This module will add a Py3o ODS report on Inventory at Date.
This module has been written by Alexis de Lattre from Akretion <alexis.delattre@akretion.com>.
""",
'author': "Akretion",
'website': 'http://www.akretion.com',
'depends': ['stock_account', 'report_py3o'],
'data': [
'report.xml',
'wizard/wizard_valuation_history_view.xml',
],
'installable': True,
}

Binary file not shown.

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="stock_history_ods" model="ir.actions.report.xml">
<field name="name">Inventory at Date (ODS)</field>
<field name="model">wizard.valuation.history</field>
<field name="report_name">stock.history.ods</field>
<field name="report_type">py3o</field>
<field name="py3o_filetype">ods</field>
<field name="module">stock_history_ods</field>
<field name="py3o_template_fallback">inventory_history.ods</field>
<field name="py3o_multi_in_one" eval="True"/>
</record>
</odoo>

View File

@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import wizard_valuation_history

View File

@@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models
class StockValuationHistory(models.TransientModel):
_inherit = 'wizard.valuation.history'
def report_py3o(self):
ppo = self.env['product.product']
lines = self.env['stock.history'].with_context(
history_date=self.date).read_group(
[('date', '<=', self.date)],
['product_id', 'location_id', 'move_id', 'company_id',
'date', 'quantity', 'inventory_value'],
['product_id', 'location_id'])
categ_id2name = {}
for categ in self.env['product.category'].search([]):
categ_id2name[categ.id] = categ.display_name
res = []
for line in lines:
product_id = line['product_id'][0]
product = ppo.browse(product_id)
res.append({
'product_categ': categ_id2name[product.categ_id.id],
'product_name': product.name,
'product_code': product.default_code,
'product_display_name': line['product_id'][1],
'product_uom': product.uom_id.name,
'quantity': line['quantity'],
'inventory_value': line['inventory_value'],
})
return res
def print_table(self):
self.ensure_one()
action = self.env['report'].get_action(self, 'stock.history.ods')
return action

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2018 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<odoo>
<record id="view_wizard_valuation_history" model="ir.ui.view">
<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 name="print_table" string="Print (ODS)" type="object"/>
</button>
</field>
</record>
</odoo>