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

[MIG] stock_voucher_ux: Migration to 18.0 #588

Open
wants to merge 1 commit into
base: 18.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions stock_voucher_ux/README.rst
Original file line number Diff line number Diff line change
@@ -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
<https://github.com/ingadhoc/stock/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.
6 changes: 6 additions & 0 deletions stock_voucher_ux/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
##############################################################################
# For copyright and license notices, see __manifest__.py file in module root
# directory
##############################################################################
from . import models
from . import controllers
46 changes: 46 additions & 0 deletions stock_voucher_ux/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'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,
}
7 changes: 7 additions & 0 deletions stock_voucher_ux/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
################################################################################
#
# This file is part of Aeroo Reports software - for license refer LICENSE file
#
################################################################################

from . import main
72 changes: 72 additions & 0 deletions stock_voucher_ux/controllers/main.py
Original file line number Diff line number Diff line change
@@ -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
88 changes: 88 additions & 0 deletions stock_voucher_ux/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * stock_voucher
#
# Translators:
# Juan José Scarafía <[email protected]>, 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 <[email protected]>, 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 "<strong>THE VOUCHER IT'S PRINTED.</strong>"
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"
6 changes: 6 additions & 0 deletions stock_voucher_ux/models/__init__.py
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions stock_voucher_ux/models/stock_book.py
Original file line number Diff line number Diff line change
@@ -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",
)
61 changes: 61 additions & 0 deletions stock_voucher_ux/models/stock_picking.py
Original file line number Diff line number Diff line change
@@ -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()
Loading