Skip to content

Commit

Permalink
[IMP] delivery_package_number: Add label to print package numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosRoca13 committed Nov 10, 2023
1 parent 1db5b74 commit ce519df
Show file tree
Hide file tree
Showing 19 changed files with 271 additions and 35 deletions.
3 changes: 2 additions & 1 deletion delivery_package_number/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Stock Picking Package Number
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:31b575fcdeb76a4c5f1e734c28cf09ecfd809bc0208c4821ced9abe822aab07f
!! source digest: sha256:2aa32ff8f56811f0cd7e4783e46f63faebfbe11845c0391d6a5b4b9e92d91fa6
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down Expand Up @@ -83,6 +83,7 @@ Contributors
* Pedro M. Baeza
* David Vidal
* Marçal Isern
* Carlos Roca


* `Sygel <https://www.sygel.es>`_:
Expand Down
5 changes: 5 additions & 0 deletions delivery_package_number/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@
"application": False,
"depends": ["delivery"],
"data": [
"security/ir.model.access.csv",
"data/paperformat_data.xml",
"reports/report_package_number.xml",
"views/stock_picking_type_views.xml",
"views/stock_picking_views.xml",
"wizard/stock_immediate_transfer_views.xml",
"wizard/stock_backorder_confirmation_views.xml",
"wizard/stock_number_package_validate_wiz_view.xml",
],
}
20 changes: 20 additions & 0 deletions delivery_package_number/data/paperformat_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">

<record id="paperformat_number_of_packages_label" model="report.paperformat">
<field name="name">Number of package label</field>
<field name="default" eval="True" />
<field name="format">custom</field>
<field name="page_width">100</field>
<field name="page_height">50</field>
<field name="orientation">Portrait</field>
<field name="margin_top">0</field>
<field name="margin_bottom">0</field>
<field name="margin_left">5</field>
<field name="margin_right">5</field>
<field name="header_line" eval="False" />
<field name="header_spacing">0</field>
<field name="dpi">150</field>
</record>

</odoo>
1 change: 1 addition & 0 deletions delivery_package_number/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import stock_picking_type
from . import stock_picking
39 changes: 38 additions & 1 deletion delivery_package_number/models/stock_picking.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2020 Tecnativa - David Vidal
# Copyright 2023 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
from odoo import _, api, fields, models


class StockPicking(models.Model):
Expand All @@ -21,3 +21,40 @@ def _compute_number_of_packages(self):
for picking in self:
if picking.package_ids:
picking.number_of_packages = len(picking.package_ids)

def _action_generate_number_of_packages_wizard(self):
view = self.env.ref("delivery_package_number.view_number_package_validate")

Check warning on line 26 in delivery_package_number/models/stock_picking.py

View check run for this annotation

Codecov / codecov/patch

delivery_package_number/models/stock_picking.py#L26

Added line #L26 was not covered by tests
return {
"name": _("Set number of packages"),
"type": "ir.actions.act_window",
"view_mode": "form",
"res_model": "stock.number.package.validate.wizard",
"views": [(view.id, "form")],
"view_id": view.id,
"target": "new",
"context": dict(
self.env.context, default_pick_ids=[(4, p.id) for p in self]
),
}

def _check_set_number_of_packages(self):
pickings_to_set_number_of_packages = self.browse()
for picking in self:
if (
picking.picking_type_id.force_set_number_of_packages
and not picking.number_of_packages
):
pickings_to_set_number_of_packages |= picking

Check warning on line 47 in delivery_package_number/models/stock_picking.py

View check run for this annotation

Codecov / codecov/patch

delivery_package_number/models/stock_picking.py#L47

Added line #L47 was not covered by tests
return pickings_to_set_number_of_packages

def _pre_action_done_hook(self):
res = super()._pre_action_done_hook()
if (
res
and isinstance(res, bool)
and not self.env.context.get("bypass_set_number_of_packages")
):
pickings_to_set_nop = self._check_set_number_of_packages()
if pickings_to_set_nop:
return pickings_to_set_nop._action_generate_number_of_packages_wizard()

Check warning on line 59 in delivery_package_number/models/stock_picking.py

View check run for this annotation

Codecov / codecov/patch

delivery_package_number/models/stock_picking.py#L59

Added line #L59 was not covered by tests
return res
9 changes: 9 additions & 0 deletions delivery_package_number/models/stock_picking_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright 2023 Tecnativa - Carlos Roca
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models


class StockPickingType(models.Model):
_inherit = "stock.picking.type"

force_set_number_of_packages = fields.Boolean()
1 change: 1 addition & 0 deletions delivery_package_number/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Pedro M. Baeza
* David Vidal
* Marçal Isern
* Carlos Roca


* `Sygel <https://www.sygel.es>`_:
Expand Down
80 changes: 80 additions & 0 deletions delivery_package_number/reports/report_package_number.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<template id="delivery_package_number_document">
<t t-call="web.basic_layout">
<t
t-set="move_ids"
t-value="doc.move_lines._rollup_move_dests({doc.move_lines[:1].id})"
/>
<t
t-set="dest_picking"
t-value="doc.move_lines.browse(move_ids).filtered('sale_line_id')[:1].picking_id"
/>
<t t-foreach="doc.number_of_packages" t-as="pack_num">
<div class="page">
<div class="row">
<div class="col-5" name="logo">
<img
t-if="doc.company_id.logo"
t-att-src="image_data_uri(doc.company_id.logo)"
style="max-height: 80px;"
class="float-left"
/>
</div>
<div class="col-2" />
<div class="col-5 text-center pt-3" name="picking_ref">
<div
t-field="dest_picking.name"
t-options="{'widget': 'barcode', 'img_style': 'width:100%'}"
/>
<h4>
<strong t-field="dest_picking.name" />
</h4>
</div>
</div>
<div class="row mt-3">
<div
class="col-5 border border-dark rounded text-center"
style="padding: 60px 0;"
name="client"
>
<span t-field="dest_picking.partner_id" />
</div>
<div class="col-2" />
<div
class="col-5 border border-dark rounded"
name="package_number"
>
<h6>Number of packages:</h6>
<div style="font-size: 4em" class="text-center">
<span t-out="pack_num + 1" />/<span
t-field="doc.number_of_packages"
/>
</div>
</div>
</div>

</div>
<div style="page-break-before:always;" />
</t>
</t>
</template>
<template id="delivery_package_number_report">
<t t-foreach="docs" t-as="doc">
<t t-call="delivery_package_number.delivery_package_number_document" />
</t>
</template>
<record id="action_delivery_package_number_report" model="ir.actions.report">
<field name="name">Delivery packages</field>
<field name="model">stock.picking</field>
<field name="binding_model_id" ref="stock.model_stock_picking" />
<field name="report_type">qweb-pdf</field>
<field
name="report_name"
>delivery_package_number.delivery_package_number_report</field>
<field
name="report_file"
>delivery_package_number.delivery_package_number_report</field>
<field name="paperformat_id" ref="paperformat_number_of_packages_label" />
</record>
</odoo>
2 changes: 2 additions & 0 deletions delivery_package_number/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_stock_number_package_validate_wizard,access.stock.number.package.validate.wizard,model_stock_number_package_validate_wizard,stock.group_stock_user,1,1,1,0
3 changes: 2 additions & 1 deletion delivery_package_number/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Stock Picking Package Number</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:31b575fcdeb76a4c5f1e734c28cf09ecfd809bc0208c4821ced9abe822aab07f
!! source digest: sha256:2aa32ff8f56811f0cd7e4783e46f63faebfbe11845c0391d6a5b4b9e92d91fa6
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/delivery-carrier/tree/15.0/delivery_package_number"><img alt="OCA/delivery-carrier" src="https://img.shields.io/badge/github-OCA%2Fdelivery--carrier-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/delivery-carrier-15-0/delivery-carrier-15-0-delivery_package_number"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/delivery-carrier&amp;target_branch=15.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module recovers the number of packages field that was present in previous
Expand Down Expand Up @@ -427,6 +427,7 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<li>Pedro M. Baeza</li>
<li>David Vidal</li>
<li>Marçal Isern</li>
<li>Carlos Roca</li>
</ul>
</li>
</ul>
Expand Down
14 changes: 14 additions & 0 deletions delivery_package_number/views/stock_picking_type_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record model="ir.ui.view" id="view_picking_type_form">
<field name="model">stock.picking.type</field>
<field name="inherit_id" ref="stock.view_picking_type_form" />
<field name="arch" type="xml">
<xpath expr="//field[@name='default_location_src_id']/.." position="after">
<group string="Number of packages">
<field name="force_set_number_of_packages" />
</group>
</xpath>
</field>
</record>
</odoo>
2 changes: 2 additions & 0 deletions delivery_package_number/wizard/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
from . import stock_number_package_mixin
from . import stock_inmediate_transfer
from . import stock_backorder_confirmation
from . import stock_number_package_validate_wiz
19 changes: 3 additions & 16 deletions delivery_package_number/wizard/stock_backorder_confirmation.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
# Copyright 2023 Ángel García de la Chica Herrera <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models
from odoo import models


class StockBackorderConfirmation(models.TransientModel):
_inherit = "stock.backorder.confirmation"

number_of_packages = fields.Integer(
help="Set the number of packages for picking to be validated",
)
ask_number_of_packages = fields.Boolean(compute="_compute_ask_number_of_packages")

@api.depends("pick_ids")
def _compute_ask_number_of_packages(self):
for item in self:
# we use ._origin because if not, a NewId is used for the checks and the returned
# value of package_ids is wrong.
item.ask_number_of_packages = bool(
item.pick_ids.carrier_id and not item.pick_ids._origin.package_ids
)
_inherit = ["stock.backorder.confirmation", "stock.number.package.mixin"]
_name = "stock.backorder.confirmation"

def process(self):
if self.number_of_packages:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@
<field name="number_of_packages" />
</group>
</xpath>
<xpath expr="//button[@special='cancel']" position="after">
<field
name="print_package_label"
widget="boolean_toggle"
attrs="{'invisible': [('ask_number_of_packages','=',False)]}"
/>
<label
for="print_package_label"
attrs="{'invisible': [('ask_number_of_packages','=',False)]}"
/>
</xpath>
</field>
</record>
</odoo>
11 changes: 11 additions & 0 deletions delivery_package_number/wizard/stock_immediate_transfer_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@
<field name="number_of_packages" />
</group>
</xpath>
<xpath expr="//button[@special='cancel']" position="after">
<field
name="print_package_label"
widget="boolean_toggle"
attrs="{'invisible': [('ask_number_of_packages','=',False)]}"
/>
<label
for="print_package_label"
attrs="{'invisible': [('ask_number_of_packages','=',False)]}"
/>
</xpath>
</field>
</record>
</odoo>
19 changes: 3 additions & 16 deletions delivery_package_number/wizard/stock_inmediate_transfer.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
# Copyright 2020 Tecnativa - David Vidal
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
from odoo import models


class StockImmediateTransfer(models.TransientModel):
_inherit = "stock.immediate.transfer"

number_of_packages = fields.Integer(
help="Set the number of packages for this picking(s)",
)
ask_number_of_packages = fields.Boolean(compute="_compute_ask_number_of_packages")

@api.depends("pick_ids")
def _compute_ask_number_of_packages(self):
for item in self:
# we use ._origin because if not, a NewId is used for the checks and the returned
# value of package_ids is wrong.
item.ask_number_of_packages = bool(
item.pick_ids.carrier_id and not item.pick_ids._origin.package_ids
)
_inherit = ["stock.immediate.transfer", "stock.number.package.mixin"]
_name = "stock.immediate.transfer"

def process(self):
if self.number_of_packages:
Expand Down
23 changes: 23 additions & 0 deletions delivery_package_number/wizard/stock_number_package_mixin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2023 Tecnativa - Carlos Roca
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, fields, models


class StockNumberPackageMixin(models.AbstractModel):
_name = "stock.number.package.mixin"
_description = "Mixin to set number of packages"

number_of_packages = fields.Integer(
help="Set the number of packages for this picking(s)",
)
ask_number_of_packages = fields.Boolean(compute="_compute_ask_number_of_packages")
print_package_label = fields.Boolean()

@api.depends("pick_ids")
def _compute_ask_number_of_packages(self):
for item in self:
# we use ._origin because if not, a NewId is used for the checks and the returned
# value of package_ids is wrong.
item.ask_number_of_packages = bool(
item.pick_ids.carrier_id and not item.pick_ids._origin.package_ids
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2023 Tecnativa - Carlos Roca
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models


class StockNumberPackageValidateWiz(models.TransientModel):
_inherit = "stock.number.package.mixin"
_name = "stock.number.package.validate.wizard"
_description = "Wizard to force set number of pickings when validate"

pick_ids = fields.Many2many("stock.picking", "stock_picking_number_package_rel")

def process(self):
if self.number_of_packages:
self.pick_ids.write({"number_of_packages": self.number_of_packages})

Check warning on line 15 in delivery_package_number/wizard/stock_number_package_validate_wiz.py

View check run for this annotation

Codecov / codecov/patch

delivery_package_number/wizard/stock_number_package_validate_wiz.py#L15

Added line #L15 was not covered by tests
# put context key for avoiding `base_delivery_carrier_label` auto-packaging feature
return self.pick_ids.with_context(

Check warning on line 17 in delivery_package_number/wizard/stock_number_package_validate_wiz.py

View check run for this annotation

Codecov / codecov/patch

delivery_package_number/wizard/stock_number_package_validate_wiz.py#L17

Added line #L17 was not covered by tests
set_default_package=False, bypass_set_number_of_packages=True
).button_validate()
Loading

0 comments on commit ce519df

Please sign in to comment.