From e59e818e803d3fc3913c0fc48f09f33e2ac5612a Mon Sep 17 00:00:00 2001 From: mav-adhoc Date: Fri, 22 Nov 2024 09:56:53 -0300 Subject: [PATCH] [MIG] stock_voucher_ux: Migration to 18.0 --- stock_voucher_ux/README.rst | 73 +++++++++++++++ stock_voucher_ux/__init__.py | 6 ++ stock_voucher_ux/__manifest__.py | 46 ++++++++++ stock_voucher_ux/controllers/__init__.py | 7 ++ stock_voucher_ux/controllers/main.py | 72 +++++++++++++++ stock_voucher_ux/i18n/es.po | 88 +++++++++++++++++++ stock_voucher_ux/models/__init__.py | 6 ++ stock_voucher_ux/models/stock_book.py | 15 ++++ stock_voucher_ux/models/stock_picking.py | 61 +++++++++++++ .../views/report_deliveryslip.xml | 22 +++++ stock_voucher_ux/views/stock_book_views.xml | 21 +++++ .../views/stock_picking_views.xml | 22 +++++ 12 files changed, 439 insertions(+) create mode 100644 stock_voucher_ux/README.rst create mode 100644 stock_voucher_ux/__init__.py create mode 100644 stock_voucher_ux/__manifest__.py create mode 100644 stock_voucher_ux/controllers/__init__.py create mode 100644 stock_voucher_ux/controllers/main.py create mode 100644 stock_voucher_ux/i18n/es.po create mode 100644 stock_voucher_ux/models/__init__.py create mode 100644 stock_voucher_ux/models/stock_book.py create mode 100644 stock_voucher_ux/models/stock_picking.py create mode 100644 stock_voucher_ux/views/report_deliveryslip.xml create mode 100644 stock_voucher_ux/views/stock_book_views.xml create mode 100644 stock_voucher_ux/views/stock_picking_views.xml diff --git a/stock_voucher_ux/README.rst b/stock_voucher_ux/README.rst new file mode 100644 index 000000000..9be2b0acd --- /dev/null +++ b/stock_voucher_ux/README.rst @@ -0,0 +1,73 @@ +.. |company| replace:: ADHOC SA + +.. |company_logo| image:: https://raw.githubusercontent.com/ingadhoc/maintainer-tools/master/resources/adhoc-logo.png + :alt: ADHOC SA + :target: https://www.adhoc.com.ar + +.. |icon| image:: https://raw.githubusercontent.com/ingadhoc/maintainer-tools/master/resources/adhoc-icon.png + +.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png + :target: https://www.gnu.org/licenses/agpl + :alt: License: AGPL-3 + +============= +Stock Voucher +============= + +#. This module makes the assignation of the vouchers depending on the quantity of pages the report has. +#. Replaces the field "Lines per voucher" for the boolean "Autoprinted" maintaining the same functionality. +#. Eliminates the wizard for "Vouchers" and replace it with the action "Print Vouchers", which automatically prints and assigns the voucher/s. + +Installation +============ + +To install this module, you need to: + +#. Only need to install the module + +Configuration +============= + +To configure this module, you need to: + +#. To configure Books: Go to Stock / Configurations / Books. +#. To configure the Declared Value , Book Required: Go to Stock Pincking Type. + +Usage +===== + +To use this module, you need to: + +#. Just create a sale order, confirm and transfer the products. + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: http://runbot.adhoc.com.ar/ + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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. + +Credits +======= + +Images +------ + +* |company| |icon| + +Contributors +------------ + +Maintainer +---------- + +|company_logo| + +This module is maintained by the |company|. + +To contribute to this module, please visit https://www.adhoc.com.ar. diff --git a/stock_voucher_ux/__init__.py b/stock_voucher_ux/__init__.py new file mode 100644 index 000000000..bc704a047 --- /dev/null +++ b/stock_voucher_ux/__init__.py @@ -0,0 +1,6 @@ +############################################################################## +# For copyright and license notices, see __manifest__.py file in module root +# directory +############################################################################## +from . import models +from . import controllers diff --git a/stock_voucher_ux/__manifest__.py b/stock_voucher_ux/__manifest__.py new file mode 100644 index 000000000..d6504eb80 --- /dev/null +++ b/stock_voucher_ux/__manifest__.py @@ -0,0 +1,46 @@ +############################################################################## +# +# Copyright (C) 2015 ADHOC SA (http://www.adhoc.com.ar) +# All Rights Reserved. +# +# 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 . +# +############################################################################## +{ + 'name': 'Stock Voucher UX', + 'version': "18.0.1.0.0", + 'category': 'Warehouse Management', + 'sequence': 14, + 'summary': '', + 'author': 'ADHOC SA', + 'website': 'www.adhoc.com.ar', + 'license': 'AGPL-3', + 'images': [ + ], + 'depends': [ + 'stock_voucher', + 'report_aeroo', + 'l10n_ar_stock', + ], + 'data': [ + 'views/stock_book_views.xml', + 'views/stock_picking_views.xml', + 'views/report_deliveryslip.xml', + ], + 'demo': [ + ], + 'installable': True, + 'auto_install': False, + 'application': False, +} diff --git a/stock_voucher_ux/controllers/__init__.py b/stock_voucher_ux/controllers/__init__.py new file mode 100644 index 000000000..6799fd411 --- /dev/null +++ b/stock_voucher_ux/controllers/__init__.py @@ -0,0 +1,7 @@ +################################################################################ +# +# This file is part of Aeroo Reports software - for license refer LICENSE file +# +################################################################################ + +from . import main diff --git a/stock_voucher_ux/controllers/main.py b/stock_voucher_ux/controllers/main.py new file mode 100644 index 000000000..5c0a1a728 --- /dev/null +++ b/stock_voucher_ux/controllers/main.py @@ -0,0 +1,72 @@ +# Copyright 2017 ACSONE SA/NV +# Copyright 2018 - Brain-tec AG - Carlos Jesus Cebrian +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) +import io +import json +import urllib.parse +import re + +from odoo.http import route, request +from odoo.addons.web.controllers import report +from PyPDF2 import PdfFileReader + + +class ReportController(report.ReportController): + + @route() + def report_download(self, data, context=None): + """This function is used by 'qwebactionmanager.js' in order to trigger + the download of a py3o/controller report. + :param data: a javascript array JSON.stringified containg report + internal url ([0]) and type [1] + :returns: Response with a filetoken cookie and an attachment header + """ + response = super().report_download(data, context) + #NTH detect if the binary is a PDF, no matter ifn it was generated by a QWeb or Aeroo + requestcontent = json.loads(data) + url, type = requestcontent[0], requestcontent[1] + # context_part = json.loads(data)[0].split('context=')[1] + # context_dict = json.loads(urllib.parse.unquote(context_part)) + # model = context_dict.get('params', {}).get('model') + if type == 'aeroo': + context_part = json.loads(data)[0].split('context=')[1] + context_dict = json.loads(urllib.parse.unquote(context_part)) + model = context_dict.get('params', {}).get('model') + if model == 'stock.picking': + context_part = json.loads(data)[0].split('context=')[1] + context_dict = json.loads(urllib.parse.unquote(context_part)) + picking_id = context_dict.get('active_ids') + # Get assign on the context. If true, then is not an autoprinted + assign = context_dict.get('assign') + book_id = request.env['stock.picking'].browse(picking_id).book_id + if assign and book_id and picking_id: + pdf_response = response.response[0] + reader = PdfFileReader(io.BytesIO(pdf_response)) + # The number of pages will assign the number of vouchers + number_pages = len(reader.pages) + + # See if there are vouchers already assigned. If not, then it assigns the vouchers + if not request.env['stock.picking'].browse(picking_id).voucher_ids and book_id: + request.env['stock.picking'].browse(picking_id).assign_numbers(number_pages, book_id) + else: + dict_context = json.loads(context) + model = dict_context['active_model'] + if model == 'stock.picking': + # If the report is not an aeroo, the assign method should only assign one voucher + match = re.search(r'(\d+)$', json.loads(data)[0]) + if match: + picking_id = int(match.group(1)) + book_id = request.env['stock.picking'].browse(picking_id).book_id + if 'report_deliveryslip' in url and book_id and book_id.autoprinted == False and picking_id: + pdf_response = response.response[0] + reader = PdfFileReader(io.BytesIO(pdf_response)) + # The number of pages will assign the number of vouchers + number_pages = len(reader.pages) + + if not request.env['stock.picking'].browse(picking_id).voucher_ids and book_id: + request.env['stock.picking'].browse(picking_id).assign_numbers(number_pages, book_id) + + elif not request.env['stock.picking'].browse(picking_id).voucher_ids and book_id: + request.env['stock.picking'].browse(picking_id).assign_numbers(1, book_id) + + return response diff --git a/stock_voucher_ux/i18n/es.po b/stock_voucher_ux/i18n/es.po new file mode 100644 index 000000000..d86c87d7b --- /dev/null +++ b/stock_voucher_ux/i18n/es.po @@ -0,0 +1,88 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_voucher +# +# Translators: +# Juan José Scarafía , 2023 +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2023-08-01 16:21+0000\n" +"PO-Revision-Date: 2023-01-13 13:59+0000\n" +"Last-Translator: Juan José Scarafía , 2023\n" +"Language-Team: Spanish (https://app.transifex.com/adhoc/teams/46451/es/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: es\n" +"Plural-Forms: nplurals=3; plural=n == 1 ? 0 : n != 0 && n % 1000000 == 0 ? 1 : 2;\n" + +#. module: stock_voucher_ux +#: model_terms:ir.ui.view,arch_db:stock_voucher_ux.view_print_stock_voucher_form_ux +msgid "THE VOUCHER IT'S PRINTED." +msgstr "EL COMPROBANTE ESTÁ IMPRESO." + +#. module: stock_voucher_ux +#: model_terms:ir.ui.view,arch_db:stock_voucher_ux.view_print_stock_voucher_form_ux +msgid "Print" +msgstr "Imprimir" + +#. module: stock_voucher_ux +#: model_terms:ir.ui.view,arch_db:stock_voucher_ux.view_print_stock_voucher_form_ux +msgid "Number estimated of pages" +msgstr "Número estimado de paginas" + +#. module: stock_voucher_ux +#: model_terms:ir.ui.view,arch_db:stock_voucher_ux.view_print_stock_voucher_form_ux +msgid "Estimate calculated to have an idea of the approximate number of pages. The real value will be known after printing" +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" + +#. module: stock_voucher_ux +#: model:ir.model.fields,help:stock_voucher_ux.field_stock_book__autoprinted +msgid "" +"If voucher is not an autoprinted, it will assign as many vouchers as pages the report has. " +"Otherwise, it will assign only one voucher" +msgstr "" +"Si el remito no es un autoimpreso, se asignará cantidad de remitos como número de paginas haya. " +"De otra manera, asignará un único remito" + +#. module: stock_voucher_ux +#: model:ir.model.fields,field_description:stock_voucher_ux.field_stock_book__autoprinted +msgid "autoprinted" +msgstr "Autoimpreso" + +#. module: stock_voucher_ux +#: model_terms:ir.ui.view,arch_db:stock_voucher_ux.view_print_stock_voucher_form_ux +msgid "Print" +msgstr "Imprimir" + +#. module: stock_voucher_ux +#: model_terms:ir.ui.view,arch_db:stock_voucher_ux.view_picking_form +msgid "Print" +msgstr "Imprimir" + +#. module: stock_voucher_ux +#: model:ir.model.fields,field_description:stock_voucher_ux.field_stock_picking__book_id +msgid "Book" +msgstr "Talonario" + +#. module: stock_voucher_ux +#: model_terms:ir.ui.view,arch_db:stock_voucher_ux.view_picking_form +msgid "Print Vouchers" +msgstr "Imprimir Remitos" + +#. module: stock_voucher_ux +#: model_terms:ir.ui.view,arch_db:stock_voucher_ux.view_picking_form +msgid "Clean Voucher Data" +msgstr "Limpiar Remitos" + +#. module: stock_voucher_ux +#. odoo-python +#: code:addons/stock_voucher_ux/models/stock_picking.py:0 +#, python-format +msgid "" +"First you have to set a book" +msgstr "" +"Primero debe seleccionar un talonario" diff --git a/stock_voucher_ux/models/__init__.py b/stock_voucher_ux/models/__init__.py new file mode 100644 index 000000000..e00b401a5 --- /dev/null +++ b/stock_voucher_ux/models/__init__.py @@ -0,0 +1,6 @@ +############################################################################## +# For copyright and license notices, see __manifest__.py file in module root +# directory +############################################################################## +from . import stock_book +from . import stock_picking diff --git a/stock_voucher_ux/models/stock_book.py b/stock_voucher_ux/models/stock_book.py new file mode 100644 index 000000000..c4d00a4fb --- /dev/null +++ b/stock_voucher_ux/models/stock_book.py @@ -0,0 +1,15 @@ +############################################################################## +# For copyright and license notices, see __manifest__.py file in module root +# directory +############################################################################## +from odoo import fields, models + + +class StockBook(models.Model): + _inherit = 'stock.book' + + + autoprinted = fields.Boolean( + help="If voucher is not an autoprinted, it will assign as many vouchers as pages the report has. " + "Otherwise, it will assign only one voucher", + ) diff --git a/stock_voucher_ux/models/stock_picking.py b/stock_voucher_ux/models/stock_picking.py new file mode 100644 index 000000000..643ab5287 --- /dev/null +++ b/stock_voucher_ux/models/stock_picking.py @@ -0,0 +1,61 @@ +############################################################################## +# For copyright and license notices, see __manifest__.py file in module root +# directory +############################################################################## +from odoo import fields, models, api +from odoo.exceptions import UserError + + +class StockPicking(models.Model): + _inherit = 'stock.picking' + + + printed = fields.Boolean( + ) + + with_vouchers = fields.Boolean( + compute='_compute_with_vouchers', + ) + + book_id = fields.Many2one( + 'stock.book', + 'Book', + default=lambda self: self._get_book(), + ) + + next_voucher_number = fields.Integer( + 'Next Voucher Number', + related='book_id.sequence_id.number_next_actual', + ) + + autoprinted = fields.Boolean( + related='book_id.autoprinted', + ) + + @api.model + def _get_book(self): + return self.book_id or self.env['stock.book'].search([('company_id', '=', self.company_id.id)], limit=1) + + @api.depends('voucher_ids') + def _compute_with_vouchers(self): + for rec in self: + rec.with_vouchers = bool(self.voucher_ids) + + def do_print_voucher(self): + self.printed = True + if self.book_id: + self.book_id = self.book_id.id + return super(StockPicking, self).do_print_voucher() + + def do_print_and_assign(self): + if not self.book_id: + raise UserError("Primero debe seleccionar un talonario") + if self.autoprinted == False: + self.printed = True + return self.with_context(assign=True).do_print_voucher() + else: + self.assign_numbers(1,self.book_id) + return self.do_print_voucher() + + def clean_voucher_data(self): + return super(StockPicking, self).clean_voucher_data() diff --git a/stock_voucher_ux/views/report_deliveryslip.xml b/stock_voucher_ux/views/report_deliveryslip.xml new file mode 100644 index 000000000..1fb7a08a2 --- /dev/null +++ b/stock_voucher_ux/views/report_deliveryslip.xml @@ -0,0 +1,22 @@ + + + + diff --git a/stock_voucher_ux/views/stock_book_views.xml b/stock_voucher_ux/views/stock_book_views.xml new file mode 100644 index 000000000..e5a4de8c9 --- /dev/null +++ b/stock_voucher_ux/views/stock_book_views.xml @@ -0,0 +1,21 @@ + + + stock.book.form.ux + stock.book + + + + + + + 1 + + + autoprinted == False + + + autoprinted == False + + + + diff --git a/stock_voucher_ux/views/stock_picking_views.xml b/stock_voucher_ux/views/stock_picking_views.xml new file mode 100644 index 000000000..768e0c79c --- /dev/null +++ b/stock_voucher_ux/views/stock_picking_views.xml @@ -0,0 +1,22 @@ + + + stock.picking.delivery_extension.form + stock.picking + + + + + + +