Skip to content

Commit a896798

Browse files
committed
[MIG] stock_voucher_ux: Migration to 18.0
closes #588 Signed-off-by: ced-adhoc <[email protected]>
1 parent 2daf324 commit a896798

File tree

12 files changed

+431
-0
lines changed

12 files changed

+431
-0
lines changed

stock_voucher_ux/README.rst

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
.. |company| replace:: ADHOC SA
2+
3+
.. |company_logo| image:: https://raw.githubusercontent.com/ingadhoc/maintainer-tools/master/resources/adhoc-logo.png
4+
:alt: ADHOC SA
5+
:target: https://www.adhoc.com.ar
6+
7+
.. |icon| image:: https://raw.githubusercontent.com/ingadhoc/maintainer-tools/master/resources/adhoc-icon.png
8+
9+
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png
10+
:target: https://www.gnu.org/licenses/agpl
11+
:alt: License: AGPL-3
12+
13+
=============
14+
Stock Voucher
15+
=============
16+
17+
#. This module makes the assignation of the vouchers depending on the quantity of pages the report has.
18+
#. Replaces the field "Lines per voucher" for the boolean "Autoprinted" maintaining the same functionality.
19+
#. Eliminates the wizard for "Vouchers" and replace it with the action "Print Vouchers", which automatically prints and assigns the voucher/s.
20+
21+
Installation
22+
============
23+
24+
To install this module, you need to:
25+
26+
#. Only need to install the module
27+
28+
Configuration
29+
=============
30+
31+
To configure this module, you need to:
32+
33+
#. To configure Books: Go to Stock / Configurations / Books.
34+
#. To configure the Declared Value , Book Required: Go to Stock Pincking Type.
35+
36+
Usage
37+
=====
38+
39+
To use this module, you need to:
40+
41+
#. Just create a sale order, confirm and transfer the products.
42+
43+
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
44+
:alt: Try me on Runbot
45+
:target: http://runbot.adhoc.com.ar/
46+
47+
Bug Tracker
48+
===========
49+
50+
Bugs are tracked on `GitHub Issues
51+
<https://github.com/ingadhoc/stock/issues>`_. In case of trouble, please
52+
check there if your issue has already been reported. If you spotted it first,
53+
help us smashing it by providing a detailed and welcomed feedback.
54+
55+
Credits
56+
=======
57+
58+
Images
59+
------
60+
61+
* |company| |icon|
62+
63+
Contributors
64+
------------
65+
66+
Maintainer
67+
----------
68+
69+
|company_logo|
70+
71+
This module is maintained by the |company|.
72+
73+
To contribute to this module, please visit https://www.adhoc.com.ar.

stock_voucher_ux/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
##############################################################################
2+
# For copyright and license notices, see __manifest__.py file in module root
3+
# directory
4+
##############################################################################
5+
from . import models
6+
from . import controllers

stock_voucher_ux/__manifest__.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
##############################################################################
2+
#
3+
# Copyright (C) 2015 ADHOC SA (http://www.adhoc.com.ar)
4+
# All Rights Reserved.
5+
#
6+
# This program is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU Affero General Public License as
8+
# published by the Free Software Foundation, either version 3 of the
9+
# License, or (at your option) any later version.
10+
#
11+
# This program is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU Affero General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU Affero General Public License
17+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
#
19+
##############################################################################
20+
{
21+
'name': 'Stock Voucher UX',
22+
'version': "18.0.1.0.0",
23+
'category': 'Warehouse Management',
24+
'sequence': 14,
25+
'summary': '',
26+
'author': 'ADHOC SA',
27+
'website': 'www.adhoc.com.ar',
28+
'license': 'AGPL-3',
29+
'images': [
30+
],
31+
'depends': [
32+
'stock_voucher',
33+
'report_aeroo',
34+
'l10n_ar_stock',
35+
],
36+
'data': [
37+
'views/stock_book_views.xml',
38+
'views/stock_picking_views.xml',
39+
'views/report_deliveryslip.xml',
40+
],
41+
'demo': [
42+
],
43+
'installable': True,
44+
'auto_install': False,
45+
'application': False,
46+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
################################################################################
2+
#
3+
# This file is part of Aeroo Reports software - for license refer LICENSE file
4+
#
5+
################################################################################
6+
7+
from . import main

stock_voucher_ux/controllers/main.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Copyright 2017 ACSONE SA/NV
2+
# Copyright 2018 - Brain-tec AG - Carlos Jesus Cebrian
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
4+
import io
5+
import json
6+
import urllib.parse
7+
import re
8+
9+
from odoo.http import route, request
10+
from odoo.addons.web.controllers import report
11+
from PyPDF2 import PdfFileReader
12+
13+
14+
class ReportController(report.ReportController):
15+
16+
@route()
17+
def report_download(self, data, context=None):
18+
"""This function is used by 'qwebactionmanager.js' in order to trigger
19+
the download of a py3o/controller report.
20+
:param data: a javascript array JSON.stringified containg report
21+
internal url ([0]) and type [1]
22+
:returns: Response with a filetoken cookie and an attachment header
23+
"""
24+
response = super().report_download(data, context)
25+
#NTH detect if the binary is a PDF, no matter ifn it was generated by a QWeb or Aeroo
26+
requestcontent = json.loads(data)
27+
url, type = requestcontent[0], requestcontent[1]
28+
if type == 'aeroo' and 'remito' in url:
29+
context_part = json.loads(data)[0].split('context=')[1]
30+
context_dict = json.loads(urllib.parse.unquote(context_part))
31+
picking_id = context_dict.get('active_ids')
32+
assign = context_dict.get('assign')
33+
book_id = request.env['stock.picking'].browse(picking_id).book_id
34+
if assign and book_id and picking_id:
35+
pdf_response = response.response[0]
36+
reader = PdfFileReader(io.BytesIO(pdf_response))
37+
# The number of pages will assign the number of vouchers
38+
number_pages = len(reader.pages)
39+
40+
# See if there are vouchers already assigned. If not, then it assigns the vouchers
41+
if not request.env['stock.picking'].browse(picking_id).voucher_ids and book_id:
42+
request.env['stock.picking'].browse(picking_id).assign_numbers(number_pages, book_id)
43+
44+
elif 'report_deliveryslip' in url:
45+
# If the report is not an aeroo, the assign method should only assign one voucher
46+
match = re.search(r'(\d+)$', json.loads(data)[0])
47+
if match:
48+
picking_id = int(match.group(1))
49+
book_id = request.env['stock.picking'].browse(picking_id).book_id
50+
if book_id and book_id.autoprinted == False and picking_id:
51+
pdf_response = response.response[0]
52+
reader = PdfFileReader(io.BytesIO(pdf_response))
53+
# The number of pages will assign the number of vouchers
54+
number_pages = len(reader.pages)
55+
56+
if not request.env['stock.picking'].browse(picking_id).voucher_ids and book_id:
57+
request.env['stock.picking'].browse(picking_id).assign_numbers(number_pages, book_id)
58+
59+
elif book_id and picking_id:
60+
if not request.env['stock.picking'].browse(picking_id).voucher_ids and book_id:
61+
request.env['stock.picking'].browse(picking_id).assign_numbers(1, book_id)
62+
63+
return response

stock_voucher_ux/i18n/es.po

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Translation of Odoo Server.
2+
# This file contains the translation of the following modules:
3+
# * stock_voucher
4+
#
5+
# Translators:
6+
# Juan José Scarafía <[email protected]>, 2023
7+
#
8+
msgid ""
9+
msgstr ""
10+
"Project-Id-Version: Odoo Server 16.0+e\n"
11+
"Report-Msgid-Bugs-To: \n"
12+
"POT-Creation-Date: 2023-08-01 16:21+0000\n"
13+
"PO-Revision-Date: 2023-01-13 13:59+0000\n"
14+
"Last-Translator: Juan José Scarafía <[email protected]>, 2023\n"
15+
"Language-Team: Spanish (https://app.transifex.com/adhoc/teams/46451/es/)\n"
16+
"MIME-Version: 1.0\n"
17+
"Content-Type: text/plain; charset=UTF-8\n"
18+
"Content-Transfer-Encoding: \n"
19+
"Language: es\n"
20+
"Plural-Forms: nplurals=3; plural=n == 1 ? 0 : n != 0 && n % 1000000 == 0 ? 1 : 2;\n"
21+
22+
#. module: stock_voucher_ux
23+
#: model_terms:ir.ui.view,arch_db:stock_voucher_ux.view_print_stock_voucher_form_ux
24+
msgid "<strong>THE VOUCHER IT'S PRINTED.</strong>"
25+
msgstr "EL COMPROBANTE ESTÁ IMPRESO."
26+
27+
#. module: stock_voucher_ux
28+
#: model_terms:ir.ui.view,arch_db:stock_voucher_ux.view_print_stock_voucher_form_ux
29+
msgid "Print"
30+
msgstr "Imprimir"
31+
32+
#. module: stock_voucher_ux
33+
#: model_terms:ir.ui.view,arch_db:stock_voucher_ux.view_print_stock_voucher_form_ux
34+
msgid "Number estimated of pages"
35+
msgstr "Número estimado de paginas"
36+
37+
#. module: stock_voucher_ux
38+
#: model_terms:ir.ui.view,arch_db:stock_voucher_ux.view_print_stock_voucher_form_ux
39+
msgid "Estimate calculated to have an idea of the approximate number of pages. The real value will be known after printing"
40+
msgstr "Estimación calculada para tener una idea del número aproximado de páginas. El valor real se conocerá después de la impresión"
41+
42+
#. module: stock_voucher_ux
43+
#: model:ir.model.fields,help:stock_voucher_ux.field_stock_book__autoprinted
44+
msgid ""
45+
"If voucher is not an autoprinted, it will assign as many vouchers as pages the report has. "
46+
"Otherwise, it will assign only one voucher"
47+
msgstr ""
48+
"Si el remito no es un autoimpreso, se asignará cantidad de remitos como número de paginas haya. "
49+
"De otra manera, asignará un único remito"
50+
51+
#. module: stock_voucher_ux
52+
#: model:ir.model.fields,field_description:stock_voucher_ux.field_stock_book__autoprinted
53+
msgid "autoprinted"
54+
msgstr "Autoimpreso"
55+
56+
#. module: stock_voucher_ux
57+
#: model_terms:ir.ui.view,arch_db:stock_voucher_ux.view_print_stock_voucher_form_ux
58+
msgid "Print"
59+
msgstr "Imprimir"
60+
61+
#. module: stock_voucher_ux
62+
#: model_terms:ir.ui.view,arch_db:stock_voucher_ux.view_picking_form
63+
msgid "Print"
64+
msgstr "Imprimir"
65+
66+
#. module: stock_voucher_ux
67+
#: model:ir.model.fields,field_description:stock_voucher_ux.field_stock_picking__book_id
68+
msgid "Book"
69+
msgstr "Talonario"
70+
71+
#. module: stock_voucher_ux
72+
#: model_terms:ir.ui.view,arch_db:stock_voucher_ux.view_picking_form
73+
msgid "Print Vouchers"
74+
msgstr "Imprimir Remitos"
75+
76+
#. module: stock_voucher_ux
77+
#: model_terms:ir.ui.view,arch_db:stock_voucher_ux.view_picking_form
78+
msgid "Clean Voucher Data"
79+
msgstr "Limpiar Remitos"
80+
81+
#. module: stock_voucher_ux
82+
#. odoo-python
83+
#: code:addons/stock_voucher_ux/models/stock_picking.py:0
84+
#, python-format
85+
msgid ""
86+
"First you have to set a book"
87+
msgstr ""
88+
"Primero debe seleccionar un talonario"

stock_voucher_ux/models/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
##############################################################################
2+
# For copyright and license notices, see __manifest__.py file in module root
3+
# directory
4+
##############################################################################
5+
from . import stock_book
6+
from . import stock_picking

stock_voucher_ux/models/stock_book.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
##############################################################################
2+
# For copyright and license notices, see __manifest__.py file in module root
3+
# directory
4+
##############################################################################
5+
from odoo import fields, models
6+
7+
8+
class StockBook(models.Model):
9+
_inherit = 'stock.book'
10+
11+
12+
autoprinted = fields.Boolean(
13+
help="If voucher is not an autoprinted, it will assign as many vouchers as pages the report has. "
14+
"Otherwise, it will assign only one voucher",
15+
)
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
##############################################################################
2+
# For copyright and license notices, see __manifest__.py file in module root
3+
# directory
4+
##############################################################################
5+
from odoo import fields, models, api
6+
from odoo.exceptions import UserError
7+
8+
9+
class StockPicking(models.Model):
10+
_inherit = 'stock.picking'
11+
12+
13+
printed = fields.Boolean(
14+
)
15+
16+
with_vouchers = fields.Boolean(
17+
compute='_compute_with_vouchers',
18+
)
19+
20+
book_id = fields.Many2one(
21+
'stock.book',
22+
'Book',
23+
default=lambda self: self._get_book(),
24+
)
25+
26+
next_voucher_number = fields.Integer(
27+
'Next Voucher Number',
28+
related='book_id.sequence_id.number_next_actual',
29+
)
30+
31+
autoprinted = fields.Boolean(
32+
related='book_id.autoprinted',
33+
)
34+
35+
@api.model
36+
def _get_book(self):
37+
return self.book_id or self.env['stock.book'].search([('company_id', '=', self.company_id.id)], limit=1)
38+
39+
@api.depends('voucher_ids')
40+
def _compute_with_vouchers(self):
41+
for rec in self:
42+
rec.with_vouchers = bool(self.voucher_ids)
43+
44+
def do_print_voucher(self):
45+
self.printed = True
46+
if self.book_id:
47+
self.book_id = self.book_id.id
48+
return super(StockPicking, self).do_print_voucher()
49+
50+
def do_print_and_assign(self):
51+
if not self.book_id:
52+
raise UserError("Primero debe seleccionar un talonario")
53+
if self.autoprinted == False:
54+
self.printed = True
55+
return self.with_context(assign=True).do_print_voucher()
56+
else:
57+
self.assign_numbers(1,self.book_id)
58+
return self.do_print_voucher()
59+
60+
def clean_voucher_data(self):
61+
return super(StockPicking, self).clean_voucher_data()
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<odoo>
3+
<template id="report_delivery_document" inherit_id="l10n_ar_stock.report_delivery_document">
4+
<xpath expr="//t[@t-set='pre_printed_report']" position="replace">
5+
<t t-set="pre_printed_report" t-value="not o.autoprinted"/>
6+
</xpath>
7+
<xpath expr="//div[@name='footer_right_column']" position="replace">
8+
<div name="footer_right_column" class="col-4 text-right">
9+
<div t-if="o.book_id.autoprinted and o.book_id.l10n_ar_cai">
10+
CAI: <span t-field="o.book_id.l10n_ar_cai"/>
11+
</div>
12+
<div t-if="o.book_id.autoprinted and o.book_id.l10n_ar_cai_due">
13+
CAI Due Date: <span t-field="o.book_id.l10n_ar_cai_due"/>
14+
</div>
15+
<div name="pager" t-if="report_type == 'pdf'">
16+
Page: <span class="page"/>
17+
/ <span class="topage"/>
18+
</div>
19+
</div>
20+
</xpath>
21+
</template>
22+
</odoo>

0 commit comments

Comments
 (0)