Skip to content

Commit

Permalink
[IMP]stock_batch_picking_voucher:new module
Browse files Browse the repository at this point in the history
  • Loading branch information
jcadhoc committed Sep 19, 2024
1 parent e93897c commit 895aa6a
Show file tree
Hide file tree
Showing 17 changed files with 535 additions and 0 deletions.
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.
7 changes: 7 additions & 0 deletions stock_batch_picking_voucher/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
##############################################################################
# For copyright and license notices, see __manifest__.py file in module root
# directory
##############################################################################
from . import models
from . import wizards
from . import controllers
50 changes: 50 additions & 0 deletions stock_batch_picking_voucher/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
##############################################################################
#
# 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'
],
'data': [
'security/ir.model.access.csv',
'wizards/stock_print_batch_stock_voucher_views.xml',
'report/batch_picking_preprinted_data.xml',
'views/stock_batch_picking_views.xml',
'views/stock_picking_views.xml',

],
'demo': [
],
'installable': True,
'auto_install': True,
'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
42 changes: 42 additions & 0 deletions stock_batch_picking_voucher/controllers/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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:
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
3 changes: 3 additions & 0 deletions stock_batch_picking_voucher/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import stock_picking_voucher
from . import stock_batch_picking
# from . import stock_picking
44 changes: 44 additions & 0 deletions stock_batch_picking_voucher/models/stock_batch_picking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
##############################################################################
# For copyright and license notices, see __manifest__.py file in module root
# directory
##############################################################################
from odoo import fields, api, models, _

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
)

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'].create(list_of_vouchers)
self.message_post(body=_(
'Números de remitos asignados: %s') % (self.vouchers))
self.write({'book_id': book.id})
return {
'type': 'ir.actions.act_window',
'res_model': 'stock.picking.batch',
'view_mode': 'form',
'res_id': self.id,
'target': 'current',
}
22 changes: 22 additions & 0 deletions stock_batch_picking_voucher/models/stock_picking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# flake8: noqa
##############################################################################
# For copyright and license notices, see __manifest__.py file in module root
# directory
##############################################################################
from odoo import models, fields, api, _
from odoo.exceptions import ValidationError, UserError


class StockPicking(models.Model):

_inherit = 'stock.picking'

batch_vouchers = printed = fields.Boolean(compute = '_batch_vouchers')

def _batch_vouchers(self):
for rec in self:
if rec.batch_id and rec.batch_id.voucher_ids:
return True
else:
return False

42 changes: 42 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,42 @@
##############################################################################
# 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")

@api.model
def create(self, vals):
if 'batch_id' in vals and vals['batch_id']:
vals['picking_id'] = False
return super(StockPickingVoucher, self).create(vals)

def write(self, vals):
if 'batch_id' in vals and vals['batch_id']:
vals['picking_id'] = False
return super(StockPickingVoucher, self).write(vals)
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0"?>
<odoo noupdate="1">
<record id="batch_picking_preprinted" model="ir.actions.report">
<field name="name">Preprinted Voucher</field>
<field name="model">stock.picking.batch</field>
<field name="report_name">batch_picking_preprinted</field>
<field name="report_type">aeroo</field>
<field name="in_format">oo-odt</field>
<field name="report_file">stock_batch_picking_voucher/report/batch_picking_preprinted.odt</field>
<field name="out_format" ref="report_aeroo.report_mimetypes_pdf_odt"/>
<field name="tml_source">file</field>
<field name="binding_model_id" ref="stock_picking_batch.model_stock_picking_batch"/>
<field name="binding_type">report</field>
</record>

</odoo>
5 changes: 5 additions & 0 deletions stock_batch_picking_voucher/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
stock_batch_picking_voucher.access_stock_print_batch_stock_voucher,access_stock_print_batch_stock_voucher,stock_batch_picking_voucher.model_stock_print_batch_stock_voucher,base.group_user,1,1,1,0
stock_batch_picking_voucher.access_stock_voucher,access_stock_voucher,model_stock_picking_voucher,base.group_user,1,1,1,0


42 changes: 42 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,42 @@
<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="arch" type="xml">
<button name="action_print" position="after">
<button name="%(action_stock_print_batch_voucher)d" string="Vouchers" type="action" invisible="state not in ('done')"/>
</button>
<field name="user_id" position="after">
<field name="book_id"/>
<field name="voucher_ids" widget="many2many_tags"/>
</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="arch" type="xml">
<xpath expr="//button[@name='%(stock_voucher.action_stock_print_voucher)d']" position="attributes">
<attribute name="invisible">('picking_type_code','=','incoming') or ('state','!=','done') or batch_id</attribute>
</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="arch" type="xml">
<xpath expr="//button[@name='%(stock_voucher.action_stock_print_voucher)d'][1]" position="attributes">
<attribute name="invisible">not book_id or picking_type_code == 'incoming' or state != 'done' or batch_id</attribute>
</xpath>
<xpath expr="//button[@name='%(stock_voucher.action_stock_print_voucher)d'][2]" position="attributes">
<attribute name="invisible">book_id or picking_type_code == 'incoming' or state != 'done' or batch_id</attribute>
</xpath>
</field>
</record>
</odoo>
22 changes: 22 additions & 0 deletions stock_batch_picking_voucher/views/stock_picking_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<odoo>
<record model="ir.ui.view" id="stock_picking_form_exception">
<field name="name">stock.picking.form.exception</field>
<field name="model">stock.picking</field>
<field name="priority">99</field>
<field name="inherit_id" ref="stock.view_picking_form"/>
<field name="arch" type="xml">
<sheet position="before">
<!-- <field name="batch_vouchers" invisible="1"/> -->
<div class="alert alert-warning mb-2" invisible="not batch_id" role="alert">
<strong>Advertencia:</strong> La asignación de remitos se hace desde el lote de traslados, si quiere hacerlos desde este traslado cancele el lote o separe el traslado del mismo
</div>
</sheet>
<field name="book_id" position="attributes">
<attribute name="readonly">batch_id</attribute>
</field>
<field name="voucher_ids" position="attributes">
<attribute name="readonly">batch_id</attribute>
</field>
</field>
</record>
</odoo>
1 change: 1 addition & 0 deletions stock_batch_picking_voucher/wizards/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import stock_print_batch_stock_voucher
Loading

0 comments on commit 895aa6a

Please sign in to comment.