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 all 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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ install:
- 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
- pip install openpyxl

script:
- travis_run_tests
Expand Down
662 changes: 662 additions & 0 deletions report_stock_spreadsheet/LICENSE

Large diffs are not rendered by default.

40 changes: 40 additions & 0 deletions report_stock_spreadsheet/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3

Choose a reason for hiding this comment

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

Add try-on-runbot section like as original template

==============================
Stock Report Spreadsheet
==============================

This module allows to print pickings in partner language.

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
`here <https://github.com/OCA/stock-logistics-reporting/issues/new?body=module:%20stock_picking_partner_lang%0Aversion:%208.0.1.0.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Choose a reason for hiding this comment

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

Use your module name report_stock_spreadsheet instead of `stock_picking_partner_lang``


Credits
=======

Contributors
------------

* Miguel Chuga <mchuga@mcsistemas.net>

Maintainer
----------

.. image:: http://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: http://odoo-community.org

This module is maintained by the OCA.

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.

To contribute to this module, please visit http://odoo-community.org.
23 changes: 23 additions & 0 deletions report_stock_spreadsheet/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# report_stock_spreadsheet for Odoo
# Copyright (C) 2014-2015 MC-sistemas (http://mcsistemas.net)
# @author Miguel Chuga <mchuga@mcsistemas.net>
#
# 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 report
25 changes: 25 additions & 0 deletions report_stock_spreadsheet/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# © <2015> <Miguel Chuga>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Report Stock Spreadsheet",
"summary": "generates the stock of all locations",
"version": "8.0.1.0.0",
"category": "Report",
"website": "https://mcsistemas.net",
"author": "Miguel Chuga,"
# "MC-Sistemas,"
"Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": [
"base",
"stock",
],
"data": [
'report/generate_stock_wizard.xml',
],
"demo": [
],
}
23 changes: 23 additions & 0 deletions report_stock_spreadsheet/report/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- encoding: utf-8 -*-

Choose a reason for hiding this comment

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

s/enconding/coding/g

##############################################################################
#
# report_stock_spreadsheet for Odoo
# Copyright (C) 2014-2015 MC-sistemas (http://mcsistemas.net)
# @author Miguel Chuga <mchuga@mcsistemas.net>
#
# 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 generate_stock_wizard
227 changes: 227 additions & 0 deletions report_stock_spreadsheet/report/generate_stock_wizard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
# -*- coding: utf-8 -*-
from tempfile import NamedTemporaryFile
from openpyxl import Workbook
from openpyxl.styles import Border, Side, Font
import base64
from openerp import models, fields


class GenerateStockWizard(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')
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')

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
"""
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)
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'])

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': "report_stock_spreadsheet.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',
}