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 mig sale delivery state #2770

Merged
merged 29 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
432cd6f
[ADD] sale_delivery_state module
PierrickBrun Aug 1, 2018
8df91fb
[IMP] refactor to use a computed field with a close behaviour as invo…
bguillot Sep 30, 2018
4222067
Filter delivery costs that are not considered as delivered
yvaucher Dec 12, 2018
c43b88a
Add a button to force the delivery state
yvaucher Dec 12, 2018
b229fab
Add readme content
yvaucher Dec 12, 2018
ae0ba50
Change Manifest to OCA standards
yvaucher Jan 4, 2019
1901635
Fix xml indent
yvaucher Jan 4, 2019
eac9c7f
[12.0][MIG] migrate module sale_delivery_state to v12
sebastienbeau Oct 9, 2020
7212be6
[IMP] sale_delivery_state: black, isort, prettier
Dec 11, 2020
a3d5f7f
[MIG] sale_delivery_state: Migration to 14.0
Dec 11, 2020
29095e6
[FIX] fix function name conflict
sebastienbeau Dec 19, 2020
517241e
sale_delivery_state: refactor tests mock
simahawk Jul 8, 2021
bc982ee
Update sale_delivery_state/readme/DESCRIPTION.rst
PierrickBrun Jul 9, 2021
f54931c
[UPD] Update sale_delivery_state.pot
oca-travis Jul 16, 2021
7779523
[UPD] README.rst
OCA-git-bot Jul 16, 2021
adcb69d
[ADD] icon.png
OCA-git-bot Jul 16, 2021
6cdeb32
[IMP] sale_delivery_state: UI similar to Invoice Status
dreispt Oct 16, 2021
8549912
[UPD] README.rst
OCA-git-bot Oct 23, 2021
479cb0f
sale_delivery_state 14.0.1.1.0
OCA-git-bot Oct 23, 2021
c65d71f
[15.0] [MIG] sale_delivery_state
celm1990 Jan 13, 2022
2f60abe
[UPD] Update sale_delivery_state.pot
Jan 13, 2022
b6566b5
[UPD] README.rst
OCA-git-bot Jan 13, 2022
a211bfd
[UPD] README.rst
OCA-git-bot Jun 2, 2022
bdbcbff
[UPD] README.rst
OCA-git-bot Jun 2, 2022
0d875dc
[16.0][MIG] - sale_delivery_state
Hardik-OSI Feb 6, 2023
89d79b8
sale_delivery_state: refactor code to reuse native field
sebastienbeau Nov 10, 2023
8e13a26
sale_automatic_workflow: fix issue in test
sebastienbeau Nov 10, 2023
aabc76a
sale_delivery_state: merge sale_delivery_state_view in sale_delivery_…
sebastienbeau Nov 15, 2023
e5a5b9f
sale_stock_delivery_state: update description, and add post init hook
sebastienbeau Nov 23, 2023
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: 4 additions & 2 deletions sale_automatic_workflow/tests/test_automatic_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@ def test_create_invoice_from_sale_order(self):
mocked.assert_called()
self.assertEqual(line.qty_delivered, 1.0)
sale.action_confirm()
self.assertTrue(sale.delivery_status, "pending")
self.assertFalse(sale.all_qty_delivered)
# Force the state to "full"
# note : this is not needed if you have the module sale_delivery_state
# installed but sale_automatic_workflow do not depend on it
# so we just force it so we can check the sale.all_qty_delivered
sale.delivery_status = "full"
sale._compute_all_qty_delivered()
self.assertTrue(sale.all_qty_delivered)
Expand Down
99 changes: 99 additions & 0 deletions sale_delivery_state/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
===================
Sale delivery State
===================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:5e6de03092efc72436a466046560f3139702a1be2ce615fe519211325e7dd488
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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%2Fsale--workflow-lightgray.png?logo=github
:target: https://github.com/OCA/sale-workflow/tree/16.0/sale_delivery_state
:alt: OCA/sale-workflow
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/sale-workflow-16-0/sale-workflow-16-0-sale_delivery_state
: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/sale-workflow&target_branch=16.0
:alt: Try me on Runboat

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

This odoo module add delivery state on the sale order.

Delivery state is computed based on `qty_delivered` field on sale order lines.

This is usefull for other modules to provide the state of delivery.
The state of the sale order can be forced to fully delivered in case
some quantities were cancelled by the customer and you consider you have
nothing more to deliver.

Sale order lines can have products or services, as long as the field `qty_delivered`
is set, it will trigger the computation of delivery state.

This module also works with delivery.carrier fees that are added as a
sale order line. Thoses line are special as they will never be considered delivered.
Delivery fees lines are ignored in the computation of the delivery state.

When the 'sale_stock' module is installed, the glue module 'sale_stock_delivery_state'
should also be installed; this module is designed to override the compute method
of the delivery status field from 'sale_stock'.

**Table of contents**

.. contents::
:local:

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/sale-workflow/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/sale-workflow/issues/new?body=module:%20sale_delivery_state%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
~~~~~~~

* Akretion

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

* Pierrick BRUN <[email protected]>
* Benoît Guillot <[email protected]>
* Yannick Vaucher <[email protected]>
* Daniel Reis <[email protected]>,
`Open Source Integrators <https://opensourceintegrators.com>`_
* Carlos Lopez <[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/sale-workflow <https://github.com/OCA/sale-workflow/tree/16.0/sale_delivery_state>`_ 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 sale_delivery_state/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
21 changes: 21 additions & 0 deletions sale_delivery_state/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2018 Akretion (http://www.akretion.com).
# @author Pierrick BRUN <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Sale delivery State",
"summary": "Show the delivery state on the sale order",
"version": "16.0.1.0.0",
"category": "Product",
"website": "https://github.com/OCA/sale-workflow",
"author": "Akretion, Odoo Community Association (OCA)",
"license": "AGPL-3",
"installable": True,
"depends": ["sale"],
"data": [
"views/sale_order_views.xml",
],
"demo": [
"demo/sale_demo.xml",
],
}
35 changes: 35 additions & 0 deletions sale_delivery_state/demo/sale_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">

<record id="sale_order_1" model="sale.order">
<field name="partner_id" ref="base.res_partner_2" />
<field name="partner_invoice_id" ref="base.res_partner_2" />
<field name="partner_shipping_id" ref="base.res_partner_2" />
<field name="user_id" ref="base.user_demo" />
<field name="pricelist_id" ref="product.list0" />
<field name="team_id" ref="sales_team.team_sales_department" />
<field
name="date_order"
eval="(DateTime.today() - relativedelta(months=1)).strftime('%Y-%m-%d %H:%M')"
/>
</record>

<record id="sale_order_line_1" model="sale.order.line">
<field name="order_id" ref="sale_order_1" />
<field name="name">Laptop E5023</field>
<field name="product_id" ref="product.product_product_25" />
<field name="product_uom_qty">3</field>
<field name="product_uom" ref="uom.product_uom_unit" />
<field name="price_unit">2950.00</field>
</record>

<record id="sale_order_line_2" model="sale.order.line">
<field name="order_id" ref="sale_order_1" />
<field name="name">Pen drive, 16GB</field>
<field name="product_id" ref="product.product_delivery_02" />
<field name="product_uom_qty">5</field>
<field name="product_uom" ref="uom.product_uom_unit" />
<field name="price_unit">145.00</field>
</record>

</odoo>
66 changes: 66 additions & 0 deletions sale_delivery_state/i18n/sale_delivery_state.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * sale_delivery_state
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 15.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: sale_delivery_state
#: model:ir.model.fields,help:sale_delivery_state.field_sale_order__force_delivery_state
msgid ""
"Allow to enforce done state of delivery, for instance if some quantities "
"were cancelled"
msgstr ""

#. module: sale_delivery_state
#: model:ir.model.fields,field_description:sale_delivery_state.field_sale_order__delivery_state
msgid "Delivery State"
msgstr ""

#. module: sale_delivery_state
#: model:ir.model.fields.selection,name:sale_delivery_state.selection__sale_order__delivery_state__done
msgid "Done"
msgstr ""

#. module: sale_delivery_state
#: model:ir.model.fields,field_description:sale_delivery_state.field_sale_order__force_delivery_state
msgid "Force Delivery State"
msgstr ""

#. module: sale_delivery_state
#: model_terms:ir.ui.view,arch_db:sale_delivery_state.view_order_form_inherit_delivery_state
msgid "Force delivery done"
msgstr ""

#. module: sale_delivery_state
#: model:ir.model.fields.selection,name:sale_delivery_state.selection__sale_order__delivery_state__no
msgid "No delivery"
msgstr ""

#. module: sale_delivery_state
#: model:ir.model.fields.selection,name:sale_delivery_state.selection__sale_order__delivery_state__partially
msgid "Partially processed"
msgstr ""

#. module: sale_delivery_state
#: model:ir.model,name:sale_delivery_state.model_sale_order
msgid "Sales Order"
msgstr ""

#. module: sale_delivery_state
#: model_terms:ir.ui.view,arch_db:sale_delivery_state.view_order_form_inherit_delivery_state
msgid "Unforce delivery done"
msgstr ""

#. module: sale_delivery_state
#: model:ir.model.fields.selection,name:sale_delivery_state.selection__sale_order__delivery_state__unprocessed
msgid "Unprocessed"
msgstr ""
1 change: 1 addition & 0 deletions sale_delivery_state/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import sale_order
87 changes: 87 additions & 0 deletions sale_delivery_state/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Copyright 2018 Akretion (http://www.akretion.com).
# @author Pierrick BRUN <[email protected]>
# Copyright 2018 Camptocamp
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models
from odoo.tools import float_compare, float_is_zero


class SaleOrder(models.Model):
_inherit = "sale.order"

delivery_status = fields.Selection(
[
("pending", "Not Delivered"),
("partial", "Partially Delivered"),
("full", "Fully Delivered"),
],
# Compute method have a different name then the field because
# the method _compute_delivery_status already exist in odoo sale_stock
compute="_compute_oca_delivery_status",
store=True,
)

force_delivery_state = fields.Boolean(
help=(
"Allow to enforce done state of delivery, for instance if some"
" quantities were cancelled"
),
)

def _all_qty_delivered(self):
"""
Returns True if all line have qty_delivered >= to ordered quantities
If `delivery` module is installed, ignores the lines with delivery costs
:returns: boolean
"""
self.ensure_one()
# Skip delivery costs lines
sale_lines = self.order_line.filtered(lambda rec: not rec._is_delivery())
precision = self.env["decimal.precision"].precision_get(
"Product Unit of Measure"
)
return all(
float_compare(
line.qty_delivered, line.product_uom_qty, precision_digits=precision
)
>= 0
for line in sale_lines
)

def _partially_delivered(self):
"""
Returns True if at least one line is delivered
:returns: boolean
"""
self.ensure_one()
# Skip delivery costs lines
sale_lines = self.order_line.filtered(lambda rec: not rec._is_delivery())
precision = self.env["decimal.precision"].precision_get(
"Product Unit of Measure"
)
return any(
not float_is_zero(line.qty_delivered, precision_digits=precision)
for line in sale_lines
)

@api.depends("order_line.qty_delivered", "state", "force_delivery_state")
def _compute_oca_delivery_status(self):
for order in self:
if order.state in ("draft", "cancel"):
order.delivery_status = None
elif order.force_delivery_state or order._all_qty_delivered():
order.delivery_status = "full"
elif order._partially_delivered():
order.delivery_status = "partial"
else:
order.delivery_status = "pending"

def action_force_delivery_state(self):
self.write({"force_delivery_state": True})

Check warning on line 84 in sale_delivery_state/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

sale_delivery_state/models/sale_order.py#L84

Added line #L84 was not covered by tests

def action_unforce_delivery_state(self):
self.write({"force_delivery_state": False})

Check warning on line 87 in sale_delivery_state/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

sale_delivery_state/models/sale_order.py#L87

Added line #L87 was not covered by tests
6 changes: 6 additions & 0 deletions sale_delivery_state/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
* Pierrick BRUN <[email protected]>
* Benoît Guillot <[email protected]>
* Yannick Vaucher <[email protected]>
* Daniel Reis <[email protected]>,
`Open Source Integrators <https://opensourceintegrators.com>`_
* Carlos Lopez <[email protected]>
19 changes: 19 additions & 0 deletions sale_delivery_state/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
This odoo module add delivery state on the sale order.

Delivery state is computed based on `qty_delivered` field on sale order lines.

This is usefull for other modules to provide the state of delivery.
The state of the sale order can be forced to fully delivered in case
some quantities were cancelled by the customer and you consider you have
nothing more to deliver.

Sale order lines can have products or services, as long as the field `qty_delivered`
is set, it will trigger the computation of delivery state.

This module also works with delivery.carrier fees that are added as a
sale order line. Thoses line are special as they will never be considered delivered.
Delivery fees lines are ignored in the computation of the delivery state.

When the 'sale_stock' module is installed, the glue module 'sale_stock_delivery_state'
should also be installed; this module is designed to override the compute method
of the delivery status field from 'sale_stock'.
Binary file added sale_delivery_state/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading