Skip to content

Commit

Permalink
[ADD] shipment_advice_cash_on_delivery: Add action on shipment advice…
Browse files Browse the repository at this point in the history
… to print cash on delivery invoices
  • Loading branch information
tuantrantg committed Apr 19, 2024
1 parent d1b165d commit 1d11d86
Show file tree
Hide file tree
Showing 19 changed files with 941 additions and 2 deletions.
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,
)
3 changes: 1 addition & 2 deletions shipment_advice/models/shipment_advice.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,9 +526,8 @@ def button_open_receptions_in_progress(self):
return action

def print_all_deliveryslip(self):
picking_type = self.env.ref("stock.picking_type_out")
pickings = self.mapped("loaded_picking_ids").filtered(
lambda p: p.picking_type_id == picking_type and p.state != "cancel"
lambda p: p.picking_type_code == "outgoing" and p.state != "cancel"
)
if pickings:
return self.env.ref("stock.action_report_delivery").report_action(pickings)
Expand Down
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)
if cod_invoices_to_validate:
res |= cod_invoices_to_validate
return res

def _invoicing_at_shipping(self):
self.ensure_one()
res = super()._invoicing_at_shipping()
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

0 comments on commit 1d11d86

Please sign in to comment.