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

[IMP]stock_batch_picking_ux:new preprinted report #539

Closed
wants to merge 5 commits into from
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/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
'views/stock_batch_picking_views.xml',
'views/stock_move_line_views.xml',
'views/stock_picking_views.xml',
'report/batch_picking_list_data.xml',
],
'demo': [
],
Expand Down
8 changes: 0 additions & 8 deletions stock_batch_picking_ux/migrations/13.0.1.2.0/mig_data.xml

This file was deleted.

This file was deleted.

5 changes: 2 additions & 3 deletions stock_batch_picking_ux/models/stock_batch_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def action_done(self):
for rec in self:
# al agregar la restriccion de que al menos una tenga que tener
# cantidad entonces nunca se manda el force_qty al picking
if all(operation.qty_done == 0
if all(operation.quantity == 0
for operation in rec.move_line_ids):
raise UserError(_(
'Debe definir Cantidad Realizada en al menos una '
Expand All @@ -134,14 +134,13 @@ def action_done(self):
# que no se van a recibir ya que todavia no se limpiaron
# y ademas, por lo de arriba, no se fuerza la cantidad
# si son todos cero, se terminan sacando
if all(operation.qty_done == 0
if all(operation.quantity == 0
for operation in picking.move_line_ids):
continue
rec.env['stock.picking.voucher'].create({
'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: 6 additions & 6 deletions stock_batch_picking_ux/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ def force_transfer(self, force_qty=True):
""" Do the picking transfer (by calling do_transfer)

If *force_qty* is True, force the transfer for all product_qty
when qty_done is 0.
when quantity is 0.

Otherwise, process only pack operation with qty_done.
If a picking has no qty_done filled, we released it from his batch
Otherwise, process only pack operation with quantity.
If a picking has no quantity filled, we released it from his batch
"""
for pick in self:
if pick.state != 'assigned':
Expand All @@ -32,19 +32,19 @@ def force_transfer(self, force_qty=True):

if force_qty:
for pack in pick.move_line_ids:
pack.qty_done = pack.quantity
pack.quantity = pack.quantity
else:
if all(
float_is_zero(
pack.qty_done,
pack.quantity,
precision_rounding=pack.product_uom_id.rounding)
for pack in pick.move_line_ids):
# No qties to process, release out of the batch
pick.batch_id = False
continue
else:
for pack in pick.move_line_ids:
if not pack.qty_done:
if not pack.quantity:
pack.unlink()

pick._action_done()
Expand Down
Binary file removed stock_batch_picking_ux/report/batch_picking_list.ods
Binary file not shown.
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
49 changes: 49 additions & 0 deletions stock_batch_picking_voucher/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
##############################################################################
#
# 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': [
'report/batch_picking_preprinted_data.xml',
'views/stock_batch_picking_views.xml',
'views/stock_picking_views.xml',

],
'demo': [
],
'installable': True,
'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'))
Loading