-
-
Notifications
You must be signed in to change notification settings - Fork 225
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
Changes from all commits
a9fb233
349fc7a
41561af
b6f8708
97090c5
40ec8c5
f384c09
aa8b382
7af84a6
6a02f87
dbbb057
d62452b
544c5c2
7e0b314
71aa343
af3802d
89531e4
bc3e996
a466a18
113b8d4
50e18bf
f5be9fb
8d16009
4caaa46
a5c9bdf
3c7808c
42c7926
3b13b60
d78a11f
32b0967
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
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 | ||
|
||
============================== | ||
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**>`_. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use your module name |
||
|
||
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. |
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 |
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": [ | ||
], | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# -*- encoding: utf-8 -*- | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
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', | ||
} |
There was a problem hiding this comment.
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