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

[16.0][IMP/ADD] shipment_advice*: Add action on shipment advice to print delivery slip and cash on delivery invoices #118

Closed
wants to merge 2 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
6 changes: 6 additions & 0 deletions setup/shipment_advice_cash_on_delivery/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
1 change: 1 addition & 0 deletions shipment_advice/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"data/ir_sequence.xml",
"data/queue_job_channel.xml",
"data/queue_job_function.xml",
"report/reports.xml",
"views/res_config_settings.xml",
"views/shipment_advice.xml",
"views/stock_picking.xml",
Expand Down
8 changes: 8 additions & 0 deletions shipment_advice/models/shipment_advice.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,3 +524,11 @@ def button_open_receptions_in_progress(self):
action["views"][tree_view_index] = (view_tree.id, "tree")
action["domain"] = [("id", "in", self.planned_picking_ids.ids)]
return action

def print_all_deliveryslip(self):
pickings = self.mapped("loaded_picking_ids").filtered(
lambda p: p.picking_type_code == "outgoing" and p.state != "cancel"
)
if pickings:
return self.env.ref("stock.action_report_delivery").report_action(pickings)
return {}
11 changes: 11 additions & 0 deletions shipment_advice/tests/test_shipment_advice.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,17 @@ def test_shipment_advice_done_full(self):
)
)
self.assertEqual(picking.state, "done")
# Print deliveryslip
action = self.shipment_advice_out.with_context(
discard_logo_check=True
).print_all_deliveryslip()
self.assertEqual(action.get("type"), "ir.actions.report")
self.assertEqual(action.get("report_name"), "stock.report_deliveryslip")
self.assertEqual(action.get("report_type"), "qweb-pdf")
self.assertEqual(
action.get("context").get("active_ids"),
picking.ids,
)

def test_shipment_advice_done_backorder_policy_disabled(self):
"""Validating a shipment with no backorder policy should let partial
Expand Down
23 changes: 23 additions & 0 deletions shipment_advice/views/shipment_advice.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@
class="btn-secondary"
states="cancel"
/>
<button
name="%(action_report_shipment_advice)d"
type="action"
string="Print Shipment Advice"
class="btn-secondary"
states="in_progress,done"
/>
<button
name="print_all_deliveryslip"
type="object"
string="Print Delivery Slip"
class="btn-secondary"
states="in_progress,done"
/>
<field
name="state"
widget="statusbar"
Expand Down Expand Up @@ -364,4 +378,13 @@
parent="stock.menu_stock_warehouse_mgmt"
action="shipment_advice_action"
/>
<!-- Shipment Advice - Print Delivery Slip -->
<record id="action_print_batch_delivery_slip" model="ir.actions.server">
<field name="name">Print Delivery Slip</field>
<field name="model_id" ref="shipment_advice.model_shipment_advice" />
<field name="binding_model_id" ref="shipment_advice.model_shipment_advice" />
<field name="state">code</field>
<field name="code">action = records.print_all_deliveryslip()
</field>
</record>
</odoo>
88 changes: 88 additions & 0 deletions shipment_advice_cash_on_delivery/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
================================
Shipment Advice Cash on Delivery
================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:402231bc491adcd94e5edba386548075cb5aa8332caa2ca5843f7bea5ba88f0f
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstock--logistics--transport-lightgray.png?logo=github
:target: https://github.com/OCA/stock-logistics-transport/tree/16.0/shipment_advice_cash_on_delivery
:alt: OCA/stock-logistics-transport
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/stock-logistics-transport-16-0/stock-logistics-transport-16-0-shipment_advice_cash_on_delivery
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-transport&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

Allow to mark a payment mode as "cash on delivery".
When the picking is delivered, an invoice is automaticaly generated with the
amount to be paid.
Allows users to print cash on delivery invoices from a shipment advice

**Table of contents**

.. contents::
:local:

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

You must mark a payment mode as "cash on delivery".

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/stock-logistics-transport/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/stock-logistics-transport/issues/new?body=module:%20shipment_advice_cash_on_delivery%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* BCIM
* ACSONE SA/NV
* Camptocamp

Contributors
~~~~~~~~~~~~

* Jacques-Etienne Baudoux <[email protected]>
* Souheil Bejaoui <[email protected]>
* Tuan Tran <[email protected]>

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/stock-logistics-transport <https://github.com/OCA/stock-logistics-transport/tree/16.0/shipment_advice_cash_on_delivery>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions shipment_advice_cash_on_delivery/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
24 changes: 24 additions & 0 deletions shipment_advice_cash_on_delivery/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2018 Jacques-Etienne Baudoux (BCIM) <[email protected]>
# Copyright 2023 ACSONE SA/NV
# Copyright 2024 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

{
"name": "Shipment Advice Cash on Delivery",
"summary": """This module allows users to print cash on delivery invoices
from a shipment advice""",
"version": "16.0.1.0.0",
"license": "AGPL-3",
"author": "BCIM, ACSONE SA/NV, Camptocamp, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-logistics-transport",
"depends": [
"account_payment_sale",
"shipment_advice",
"partner_invoicing_mode_at_shipping",
],
"data": [
"views/account_payment_mode_views.xml",
"views/shipment_advice.xml",
"views/stock_picking_views.xml",
],
}
3 changes: 3 additions & 0 deletions shipment_advice_cash_on_delivery/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import account_payment_mode
from . import shipment_advice
from . import stock_picking
10 changes: 10 additions & 0 deletions shipment_advice_cash_on_delivery/models/account_payment_mode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright 2018 Jacques-Etienne Baudoux (BCIM) <[email protected]>

from odoo import fields, models


class AccountPaymentMode(models.Model):
_inherit = "account.payment.mode"

cash_on_delivery = fields.Boolean("Cash on Delivery")
auto_validate_invoice = fields.Boolean()
20 changes: 20 additions & 0 deletions shipment_advice_cash_on_delivery/models/shipment_advice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2018 Jacques-Etienne Baudoux (BCIM) <[email protected]>
# Copyright 2023 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import models


class ShipmentAdvice(models.Model):
_inherit = "shipment.advice"

def print_cash_on_delivery_invoices(self):
done_shipment_advices = self.filtered(lambda s: s.state == "done")
cod_invoices = done_shipment_advices.mapped("loaded_picking_ids").mapped(
"cash_on_delivery_invoice_ids"
)
if cod_invoices:
return self.env.ref(
"account.account_invoices_without_payment"
).report_action(cod_invoices)
return {}
45 changes: 45 additions & 0 deletions shipment_advice_cash_on_delivery/models/stock_picking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright 2018 Jacques-Etienne Baudoux (BCIM) <[email protected]>
# Copyright 2023 ACSONE SA/NV
# Copyright 2024 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import fields, models


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

cash_on_delivery_invoice_ids = fields.Many2many(
"account.move", string="COD Invoices", copy=False, readonly=True
)

def _invoice_at_shipping(self):
self.ensure_one()
res = super()._invoice_at_shipping()
res = res or self.sale_id.payment_mode_id.cash_on_delivery
return res

def _invoicing_at_shipping_validation(self, invoices):
# COD invoices will be validated automatically
cod_invoices_to_validate = invoices.filtered(
lambda invoice: invoice.payment_mode_id.cash_on_delivery
and invoice.payment_mode_id.auto_validate_invoice
)
# Non-COD invoices need to check in the call of `super`
invoices_to_validate = invoices.filtered(
lambda invoice: not invoice.payment_mode_id.cash_on_delivery
)
res = super()._invoicing_at_shipping_validation(invoices_to_validate)
jbaudoux marked this conversation as resolved.
Show resolved Hide resolved
if cod_invoices_to_validate:
res |= cod_invoices_to_validate
return res

def _invoicing_at_shipping(self):
jbaudoux marked this conversation as resolved.
Show resolved Hide resolved
self.ensure_one()
res = super()._invoicing_at_shipping()
jbaudoux marked this conversation as resolved.
Show resolved Hide resolved
if not isinstance(res, str):
cod_invoices = res.filtered(
lambda inv: inv.payment_mode_id.cash_on_delivery
)
self.cash_on_delivery_invoice_ids = cod_invoices
return res
1 change: 1 addition & 0 deletions shipment_advice_cash_on_delivery/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
You must mark a payment mode as "cash on delivery".
3 changes: 3 additions & 0 deletions shipment_advice_cash_on_delivery/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* Jacques-Etienne Baudoux <[email protected]>
* Souheil Bejaoui <[email protected]>
* Tuan Tran <[email protected]>
4 changes: 4 additions & 0 deletions shipment_advice_cash_on_delivery/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Allow to mark a payment mode as "cash on delivery".
When the picking is delivered, an invoice is automaticaly generated with the
amount to be paid.
Allows users to print cash on delivery invoices from a shipment advice
Loading
Loading