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

[FW][IMP]stock_batch_picking_ux:new preprinted report #606

Closed
Closed
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
1 change: 0 additions & 1 deletion stock_batch_picking_ux/models/stock_batch_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ def action_done(self):
'picking_id': picking.id,
'name': rec.voucher_number,
})

return super(StockPickingBatch, self.with_context(do_not_assign_numbers=True)).action_done()

def action_view_stock_picking(self):
Expand Down
12 changes: 2 additions & 10 deletions stock_batch_picking_ux/views/stock_batch_picking_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,17 @@
</button>

<xpath expr="//div" position="inside">
<button name="add_picking_operation"
class="oe_stat_button"
icon="fa-bars"
type="object"
invisible="state in ('draft', 'cancel', 'done')">
<button name="add_picking_operation" class="oe_stat_button" icon="fa-bars" type="object" invisible="state in ('draft', 'cancel', 'done')">
<div class="o_form_field o_stat_info">
<span class="o_stat_text">Operaciones Detalladas</span>
</div>
</button>
<button name="action_view_stock_picking"
class="oe_stat_button"
icon="fa-truck"
type="object">
<button name="action_view_stock_picking" class="oe_stat_button" icon="fa-truck" type="object">
<div class="o_form_field o_stat_info">
<field string="Pickings" name="picking_count" widget="statinfo" />
</div>
</button>
</xpath>

<field name="user_id" position="before">
<field name="voucher_required" invisible="1"/>
<!-- <field name="picking_type_id"/> -->
Expand Down
65 changes: 65 additions & 0 deletions stock_batch_picking_voucher/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
.. |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

====================================
Pre-printed report in batch pickings
====================================

This module add the following features:
#. Add aeroo report to print Pre-printed from batch pickings

Installation
============

To install this module, you need to:

#. Only need to install the module

Configuration
=============

To configure this module, you need to:

#. Nothing to configure


.. 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_batch_picking_voucher/__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
48 changes: 48 additions & 0 deletions stock_batch_picking_voucher/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
##############################################################################
#
# 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': 'Preprinted report in batch pickings',
'version': "17.0.1.0.0",
'category': 'Warehouse Management',
'sequence': 14,
'summary': '',
'author': 'ADHOC SA',
'website': 'www.adhoc.com.ar',
'license': 'AGPL-3',
'images': [
],
'depends': [
'stock_batch_picking_ux',
'report_aeroo',
'l10n_latam_base',
'delivery_ux',
'stock_voucher',
],
'data': [
'views/stock_batch_picking_views.xml',
'views/stock_picking_views.xml',

],
'demo': [
],
'installable': False,
'auto_install': False,
'application': False,
}
1 change: 1 addition & 0 deletions stock_batch_picking_voucher/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import main
41 changes: 41 additions & 0 deletions stock_batch_picking_voucher/controllers/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import io
import json
import urllib.parse

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]
if type != 'aeroo':
return response
json_string = json.loads(data)[0]
context_part = json_string.split('context=')[1]
decoded_context = urllib.parse.unquote(context_part)
context_dict = json.loads(decoded_context)
batch_id = context_dict.get('active_id')
batch = context_dict.get('batch')
book_id = request.env['stock.picking.batch'].browse(batch_id).book_id
if batch and 'batch_picking_preprinted' in data:
if batch_id:
pdf_response = response.response[0]
reader = PdfFileReader(io.BytesIO(pdf_response))
number_pages = reader.getNumPages()
if not request.env['stock.picking.batch'].browse(batch_id).voucher_ids:
request.env['stock.picking.batch'].browse(batch_id).assign_numbers(number_pages, book_id)

return response
2 changes: 2 additions & 0 deletions stock_batch_picking_voucher/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import stock_picking_voucher
from . import stock_picking_batch
95 changes: 95 additions & 0 deletions stock_batch_picking_voucher/models/stock_picking_batch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
##############################################################################
# For copyright and license notices, see __manifest__.py file in module root
# directory
##############################################################################
from odoo import fields, api, models, _
from odoo.exceptions import UserError

class StockPickingBatch(models.Model):
_inherit = 'stock.picking.batch'

voucher_ids = fields.One2many(
'stock.picking.voucher',
'batch_id',
'Remitos',
copy=False,
)

book_id = fields.Many2one(
'stock.book',
'Talonario',
copy=False,
ondelete='restrict',
check_company=True
)

next_number = fields.Integer(
related='book_id.next_number',
)

def assign_numbers(self, estimated_number_of_pages, book):
self.ensure_one()
list_of_vouchers = []
for page in range(estimated_number_of_pages):
list_of_vouchers.append({
'name': book.sequence_id.next_by_id(),
'book_id': book.id,
'batch_id' : self.id,
})
self.env['stock.picking.voucher'].sudo().create(list_of_vouchers)
self.message_post(body=_(
'Números de remitos asignados: %s') % (self.voucher_ids.mapped("display_name")))
self.write({'book_id': book.id})

############# Cambios post wizard, posible abstract #############

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',
)

estimated_number_of_pages = fields.Integer(
'Number of Pages',
)

@api.model
def _get_book(self):
return self.book_id or self.env['stock.book'].search([('company_id', '=', self.picking_ids[:1].company_id.id)], limit=1)

@api.depends('picking_ids', 'picking_ids.voucher_ids')
def _compute_with_vouchers(self):
for rec in self:
rec.with_vouchers = bool(self.voucher_ids)

def do_print_and_assign(self):
# We override the method to avoid assignation
if not self.book_id:
raise UserError("Primero debe setear un talonario")
if not self.book_id.autoprinted:
self.printed = True
return self.with_context(batch=True).do_print_batch_vouchers()
self.assign_numbers(1,self.book_id)
return self.do_print_batch_vouchers()

def do_print_batch_vouchers(self):
'''This function prints the voucher'''
# self.env.ref('stock_batch_picking_voucher.batch_picking_preprinted').report_action(self)
return self.env.ref('stock_batch_picking_voucher.batch_picking_preprinted').report_action(self)

def do_clean(self):
self.voucher_ids.unlink()
# self.book_id = False
self.message_post(body=_('The assigned voucher were deleted'))
31 changes: 31 additions & 0 deletions stock_batch_picking_voucher/models/stock_picking_voucher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
##############################################################################
# For copyright and license notices, see __manifest__.py file in module root
# directory
##############################################################################
from odoo import fields, models, api, _
from odoo.exceptions import ValidationError


class StockPickingVoucher(models.Model):
_inherit = 'stock.picking.voucher'

batch_id = fields.Many2one(
'stock.picking.batch',
'Batch',
ondelete='cascade',
index=True,
)

picking_id = fields.Many2one(
'stock.picking',
'Picking',
ondelete='cascade',
required=False,
index=True,
)

@api.constrains('picking_id', 'batch_id')
def _check_picking_id_required(self):
for record in self:
if not record.batch_id and not record.picking_id:
raise ValidationError("Al crear un voucher debe estar ligado a una trasnferencia o lote de transferencias")
55 changes: 55 additions & 0 deletions stock_batch_picking_voucher/views/stock_batch_picking_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<odoo>
<!-- stock.picking.batch form view -->
<record model="ir.ui.view" id="stock_batch_picking_form">
<field name="name">stock.picking.batch.form</field>
<field name="model">stock.picking.batch</field>
<field name="inherit_id" ref="stock_picking_batch.stock_picking_batch_form"/>
<field name="priority">99</field>
<field name="arch" type="xml">
<button name="action_print" position="before">
<button name="do_print_and_assign" invisible="voucher_ids or state not in ('done')" string="Imprimir Remitos" type="object" class="oe_highlight" help="Prints pre-printed report and assigns vouchers depending on the number of sheets to be printed (automatic calculation)"/>
<button name="do_print_batch_vouchers" invisible="state not in ('done')" string="Imprimir" type="object" help="Print pre-printed report"/>
<button name="do_clean" invisible="not voucher_ids" string="Limpiar remitos" type="object"/>
</button>
<field name="user_id" position="after">
<field name="book_id" readonly="voucher_ids" string="Talonario"/>
<field name="next_number" invisible="not book_id or voucher_ids"/>
<field name="voucher_ids" widget="many2many_tags" readonly="picking_type_code != 'incoming'"/>
</field>
<!-- Hacemos esto para ajustar visual, sino queda todo en la primer columna -->
<field name="number_of_packages" position="replace"/>
<field name="user_id" position="replace"/>
<field name="scheduled_date" position="after">
<field name="user_id" readonly="state not in ['draft', 'in_progress']"/>
<field name="number_of_packages"/>
</field>
</field>
</record>

<record id="view_tree_inherited" model="ir.ui.view">
<field name="name">stock.picking.tree.inherited</field>
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock_batch_picking_ux.vpicktree"/>
<field name="priority">99</field>
<field name="arch" type="xml">
<xpath expr="//button[@name='%(stock_voucher.action_stock_print_voucher)d']" position="attributes">
<attribute name="invisible" separator=" or " add="batch_id"/>
</xpath>
</field>
</record>

<record id="view_tree_inherited2" model="ir.ui.view">
<field name="name">stock.picking.tree.inherited2</field>
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock_voucher.view_picking_form"/>
<field name="priority">99</field>
<field name="arch" type="xml">
<xpath expr="//button[@name='%(stock_voucher.action_stock_print_voucher)d'][1]" position="attributes">
<attribute name="invisible" separator=" or " add="batch_id"/>
</xpath>
<xpath expr="//button[@name='%(stock_voucher.action_stock_print_voucher)d'][2]" position="attributes">
<attribute name="invisible" separator=" or " add="batch_id"/>
</xpath>
</field>
</record>
</odoo>
Loading