Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fist commit module report_stock_spreadsheet #20

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
a9fb233
fist commit module report_stock_spreadsheet
miguelchuga Oct 19, 2015
349fc7a
Module report_stock_spreadseet act
miguelchuga Oct 19, 2015
41561af
Module report_stock_spreadseet modifications
miguelchuga Oct 20, 2015
b6f8708
Module report_stock_spreadseet bug
miguelchuga Oct 20, 2015
97090c5
Relative import
miguelchuga Oct 20, 2015
40ec8c5
README.rst
miguelchuga Oct 20, 2015
f384c09
README.rst
miguelchuga Oct 20, 2015
aa8b382
README.rst
miguelchuga Oct 20, 2015
7af84a6
README.rst
miguelchuga Oct 20, 2015
6a02f87
README.rst
miguelchuga Oct 20, 2015
dbbb057
README.rst
miguelchuga Oct 20, 2015
d62452b
.travis.yml
miguelchuga Oct 20, 2015
544c5c2
.travis.yml and README.rst
miguelchuga Oct 20, 2015
7e0b314
README.srt and icon
miguelchuga Oct 21, 2015
71aa343
pep8 finish
miguelchuga Oct 21, 2015
af3802d
ready Testing test_flake8
miguelchuga Oct 21, 2015
89531e4
No UTF-8 coding comment found and other'
miguelchuga Oct 21, 2015
bc3e996
add config travis.yml
miguelchuga Oct 21, 2015
a466a18
add sudo travis.yml
miguelchuga Oct 21, 2015
113b8d4
add sudo travis.yml required
miguelchuga Oct 21, 2015
50e18bf
add sudo travis.yml install
miguelchuga Oct 21, 2015
f5be9fb
travis.yml pip install
miguelchuga Oct 21, 2015
8d16009
travis.yml with pip install
miguelchuga Oct 21, 2015
4caaa46
travis.yml two
miguelchuga Oct 21, 2015
a5c9bdf
8.0
miguelchuga Oct 21, 2015
3c7808c
apt-get install python-openpyxl
miguelchuga Oct 21, 2015
42c7926
new pip install openpyxl 9.0
miguelchuga Oct 21, 2015
3b13b60
last resolved changes
miguelchuga Oct 22, 2015
d78a11f
space...
miguelchuga Oct 22, 2015
32b0967
modif. __init__.py
miguelchuga Oct 22, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 33 additions & 0 deletions report_stock_spreadsheet/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
sudo: false

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file .travis.yml should be in root path of project.

cache: pip

addons:
apt:
packages:
- expect-dev # provides unbuffer utility
- python-lxml # because pip installation is slow

language: python

python:
- "2.7"

env:
- VERSION="9.0" LINT_CHECK="1"
- VERSION="9.0" ODOO_REPO="odoo/odoo" LINT_CHECK="0"
- VERSION="9.0" ODOO_REPO="OCA/OCB" LINT_CHECK="0"

virtualenv:
system_site_packages: true

install:
- pip install openpyxl
- git clone https://github.com/OCA/maintainer-quality-tools.git ${HOME}/maintainer-quality-tools
- export PATH=${HOME}/maintainer-quality-tools/travis:${PATH}
- travis_install_nightly ${VERSION}

script:
- travis_run_tests ${VERSION}

after_success:
coveralls
661 changes: 661 additions & 0 deletions report_stock_spreadsheet/LICENSE

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions report_stock_spreadsheet/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

Odoo Stock report for locations
==============================

Reports for the Odo.

- Create a spreadsheet with the stock of all locations and the total locations

- sudo pip install openpyxl
1 change: 1 addition & 0 deletions report_stock_spreadsheet/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import report
44 changes: 44 additions & 0 deletions report_stock_spreadsheet/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (C) 2015 Agile Business Group sagl
# (<http://www.agilebg.com>)
#
# 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/>.
#
##############################################################################

{
'name': 'Report Stock',
'version': '0.1',
'website' : 'https://mcsistemas.net',
'category': 'Report',
'summary': 'Generate stock to xls',
'description': """
This module generate stock in locations to xls

""",
'author': 'Miguel Chuga',
'depends': ['base','stock'],
'data': ['report/generate_stock_wizard.xml',
],
'demo': [

],
'test': [
],
'installable': True,
'auto_install': False,
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
1 change: 1 addition & 0 deletions report_stock_spreadsheet/report/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import generate_stock_wizard
242 changes: 242 additions & 0 deletions report_stock_spreadsheet/report/generate_stock_wizard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
#from openerp.osv import fields, osv, orm


from tempfile import NamedTemporaryFile
from openpyxl import Workbook
from openpyxl.cell import get_column_letter
from openpyxl.worksheet import ColumnDimension
from openpyxl.styles import Border, Side, Font, Style
import base64
from openerp.tools.translate import _
from openerp import models,fields,api,exceptions,tools


class generate_stock_wizard(models.Model):
_name = "report_stock.generate_stock"
data=fields.Binary('File', readonly=True)
name=fields.Char('File Name', readonly=True)
state=fields.Selection([('choose', 'choose'),
('get', 'get')],default='choose')

def generate_file(self, cr, uid, ids, context=None):

if context is None:
context = {}

product_obj = self.pool.get('product.product')
quant_obj = self.pool.get('stock.quant')
location_obj = self.pool.get('stock.location')

this = self.browse(cr, uid, ids)[0]
fileobj = NamedTemporaryFile('w+b')
xlsfile = fileobj.name
fileobj.close()

wb = Workbook()

ws = wb.active

ws.title = "Stock_Total"
ws['A1'].value = "Report Total Stock"

ws['A2'].value = "id"
ws['B2'].value = "default_code"
ws['C2'].value = "ean14"
ws['D2'].value = "category_name"
ws['E2'].value = "name"
ws['F2'].value = "cost"
ws['G2'].value = "price"
ws['H2'].value = "stock_total"
ws['I2'].value = "costo_total"
ws.merge_cells('A1:I1')
# ws.freeze_panes = 'A2' no funciona


border_bottom = Border(bottom=Side(style='thin'))
border_right = Border(right=Side(style='thin'))
border_corner = Border(right=Side(style='thin'),bottom=Side(style='thin'))
font_bold = Font(bold=True)

sql = """
Select product_id,sum(qty) qty
from stock_quant sq JOIN
stock_location sl ON sq.location_id = sl.id
where sl.usage = 'internal'
group by product_id
"""
# AND pp.default_code = 'RVR022C-NEK'

cr.execute(sql,)
row = 3
for product_line in cr.dictfetchall():

product_id = product_obj.browse(cr, uid,product_line['product_id'] )

ws.cell(row=row, column= 1).value = product_id.id
ws.cell(row=row, column= 2).value = product_id.default_code
ws.cell(row=row, column= 3).value = product_id.ean13
ws.cell(row=row, column= 4).value = product_id.categ_id.name
ws.cell(row=row, column= 5).value = product_id.name
ws.cell(row=row, column= 6).value = product_id.standard_price
ws.cell(row=row, column= 7).value = product_id.list_price
ws.cell(row=row, column= 8).value = product_line['qty']
ws.cell(row=row, column= 9).value = (product_line['qty']*product_id.standard_price)

ws.cell(row=row, column= 1).border = border_right
ws.cell(row=row, column= 2).border = border_right
ws.cell(row=row, column= 5).border = border_right
ws.cell(row=row, column= 6).border = border_right
ws.cell(row=row, column= 7).border = border_right
ws.cell(row=row, column= 8).border = border_right
ws.cell(row=row, column= 9).border = border_right
row += 1


for r in ws.iter_rows('A1:G1'):
for c in r:
c.font = font_bold
for r in ws.iter_rows('A2:G2'):
for c in r:
c.border = border_bottom
c.font = font_bold


ws['A1'].border = border_right
ws['A2'].border = border_corner
ws['B1'].border = border_right
ws['B2'].border = border_corner
ws['C1'].border = border_right
ws['C2'].border = border_corner
ws['D1'].border = border_right
ws['D2'].border = border_corner
ws['E1'].border = border_right
ws['E2'].border = border_corner
ws['F1'].border = border_right
ws['F2'].border = border_corner
ws['G1'].border = border_right
ws['G2'].border = border_corner
ws['H1'].border = border_right
ws['H2'].border = border_corner
ws['I1'].border = border_right
ws['I2'].border = border_corner

ws.column_dimensions['B'].width = 20
ws.column_dimensions['C'].width = 20
ws.column_dimensions['E'].width = 70


#
# Location = Iternal
#

location_ids = location_obj.search(cr, uid, [('usage', '=', 'internal')], context=context)
for location in location_ids:

location_id = location_obj.browse(cr, uid,location)
print location_id.display_name
ws = wb.create_sheet()
ws['A1'].value = location_id.display_name
ws.title = location_id.display_name.replace('/', '_')
ws['A2'].value = "id"
ws['B2'].value = "default_code"
ws['C2'].value = "ean14"
ws['D2'].value = "category_name"
ws['E2'].value = "name"
ws['F2'].value = "cost"
ws['G2'].value = "price"
ws['H2'].value = "stock_total"
ws['I2'].value = "costo_total"
ws.merge_cells('A1:I1')

sql_quant = """
Select product_id,location_id,sum(qty) qty
from stock_quant
"""
cr.execute(sql_quant + "Where location_id = %s group by product_id,location_id", (location,))

row = 3
for product_quant in cr.dictfetchall():
product_id = product_obj.browse(cr, uid,product_quant['product_id'] )

# se implemento un query a quant para que sea mas eficiente la extraccion de datos de la DB
#product_quant_ids = quant_obj.search(cr, uid, [('location_id', '=', location),('product_id', '=', product_id.id)], context=context)
#for quant in product_quant_ids:
# quant_id = quant_obj.browse(cr, uid,quant)
# product_stock+=quant_id.qty

ws.cell(row=row, column= 1).value = product_id.id
ws.cell(row=row, column= 2).value = product_id.default_code
ws.cell(row=row, column= 3).value = product_id.ean13
ws.cell(row=row, column= 4).value = product_id.categ_id.name
ws.cell(row=row, column= 5).value = product_id.name
ws.cell(row=row, column= 6).value = product_id.standard_price
ws.cell(row=row, column= 7).value = product_id.list_price
ws.cell(row=row, column= 8).value = product_quant['qty']
ws.cell(row=row, column= 9).value = (product_quant['qty']*product_id.standard_price)

ws.cell(row=row, column= 1).border = border_right
ws.cell(row=row, column= 2).border = border_right
ws.cell(row=row, column= 5).border = border_right
ws.cell(row=row, column= 6).border = border_right
ws.cell(row=row, column= 7).border = border_right
ws.cell(row=row, column= 8).border = border_right
ws.cell(row=row, column= 9).border = border_right
ws.cell(row=row, column= 10).border = border_right

row += 1

for r in ws.iter_rows('A1:J1'):
for c in r:
c.font = font_bold
for r in ws.iter_rows('A2:J2'):
for c in r:
c.border = border_bottom
c.font = font_bold


ws['A1'].border = border_right
ws['A2'].border = border_corner
ws['B1'].border = border_right
ws['B2'].border = border_corner
ws['C1'].border = border_right
ws['C2'].border = border_corner
ws['D1'].border = border_right
ws['D2'].border = border_corner
ws['E1'].border = border_right
ws['E2'].border = border_corner
ws['F1'].border = border_right
ws['F2'].border = border_corner
ws['G1'].border = border_right
ws['G2'].border = border_corner
ws['H1'].border = border_right
ws['H2'].border = border_corner
ws['I1'].border = border_right
ws['I2'].border = border_corner
ws.column_dimensions['B'].width = 20
ws.column_dimensions['C'].width = 20
ws.column_dimensions['E'].width = 70

wb.save(filename=xlsfile)

spreadsheet_file = open(xlsfile, "rb")
binary_data = spreadsheet_file.read()
spreadsheet_file.close()
out = base64.b64encode(binary_data)


self.write(cr, uid, ids, {
'state': 'get',
'name': "SBG_Product_stock.xlsx",
'data': out
}, context=context)

return {
'type': 'ir.actions.act_window',
'res_model': 'report_stock.generate_stock',
'view_mode': 'form',
'view_type': 'form',
'res_id': this.id,
'views': [(False, 'form')],
'target': 'new',
}

58 changes: 58 additions & 0 deletions report_stock_spreadsheet/report/generate_stock_wizard.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" ?>
<openerp>
<data>
<record id="sbg_generate_stock_wizard" model="ir.ui.view">
<field name="name">Generate stock product spreadsheet</field>
<field name="model">report_stock.generate_stock</field>
<field name="arch" type="xml">
<form string="Generate file">


<field invisible="1" name="state"/>
<field name="name" invisible="1"/>

<group states="choose" string="Press button">
<h2>to generate file</h2>
</group>

<div states="choose">
<p>Here is the generated file: <field name="data" readonly="1" filename="name"/></p>
</div>

<div states="get">
<h2>File generation complete</h2>
<p>Here is the generated file: <field name="data" readonly="1" filename="name"/></p>
</div>
<footer states="choose">
<button name="generate_file" string="Generate file" type="object" class="oe_highlight"/>
or
<button string="Cancel" class="oe_link" special="cancel" />
</footer>
<footer states="get">
<button special="cancel" string="Close" type="object"/>
</footer>

</form>
</field>
</record>

<record id="generate_stock_action" model="ir.actions.act_window">
<field name="name">Generate product catalog spreadsheet</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">report_stock.generate_stock</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>

<menuitem
name="Generate product stock spreadsheet"
action="generate_stock_action"
id="generate_stock_menu"
parent="stock.menu_traceability"
sequence="100"
/>


</data>
</openerp>