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_order_line_delivery_state: Migration to 16.0 #2684

Merged
merged 10 commits into from
Sep 19, 2023
90 changes: 90 additions & 0 deletions sale_order_line_delivery_state/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
==============================
Sale Order Line Delivery State
==============================

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

.. |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_order_line_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_order_line_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 line. It is based on the
module sale_delivery_state, which adds the field at sale order level.

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

The state of the sale order line 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.

**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_order_line_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
~~~~~~~

* ForgeFlow

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

* Jordi Masvidal <[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_order_line_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_order_line_delivery_state/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
16 changes: 16 additions & 0 deletions sale_order_line_delivery_state/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2021 ForgeFlow S.L. (https://www.forgeflow.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Sale Order Line Delivery State",
"summary": "Show the delivery state on the sale order line",
"version": "16.0.1.0.0",
"category": "Product",
"website": "https://github.com/OCA/sale-workflow",
"author": "ForgeFlow, Odoo Community Association (OCA)",
"license": "AGPL-3",
"installable": True,
"depends": ["sale"],
"data": ["views/sale_order_views.xml"],
"demo": [],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * sale_order_line_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_order_line_delivery_state
#: model:ir.model.fields,help:sale_order_line_delivery_state.field_sale_order_line__force_delivery_state
msgid ""
"Allow to enforce done state of delivery, for instance if some quantities "
"were cancelled"
msgstr ""

#. module: sale_order_line_delivery_state
#: model:ir.model.fields,field_description:sale_order_line_delivery_state.field_sale_order_line__delivery_state
#: model_terms:ir.ui.view,arch_db:sale_order_line_delivery_state.view_order_form
msgid "Delivery State"
msgstr ""

#. module: sale_order_line_delivery_state
#: model:ir.model.fields.selection,name:sale_order_line_delivery_state.selection__sale_order_line__delivery_state__done
msgid "Done"
msgstr ""

#. module: sale_order_line_delivery_state
#: model:ir.model.fields,field_description:sale_order_line_delivery_state.field_sale_order_line__force_delivery_state
msgid "Force Delivery State"
msgstr ""

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

#. module: sale_order_line_delivery_state
#: model:ir.model.fields.selection,name:sale_order_line_delivery_state.selection__sale_order_line__delivery_state__no
msgid "No delivery"
msgstr ""

#. module: sale_order_line_delivery_state
#: model:ir.model.fields.selection,name:sale_order_line_delivery_state.selection__sale_order_line__delivery_state__partially
msgid "Partially processed"
msgstr ""

#. module: sale_order_line_delivery_state
#: model:ir.model,name:sale_order_line_delivery_state.model_sale_order_line
msgid "Sales Order Line"
msgstr ""

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

#. module: sale_order_line_delivery_state
#: model:ir.model.fields.selection,name:sale_order_line_delivery_state.selection__sale_order_line__delivery_state__unprocessed
msgid "Unprocessed"
msgstr ""
1 change: 1 addition & 0 deletions sale_order_line_delivery_state/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import sale_order_line
82 changes: 82 additions & 0 deletions sale_order_line_delivery_state/models/sale_order_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Copyright 2021 ForgeFlow S.L. (https://www.forgeflow.com)
# 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 SaleOrderLine(models.Model):
_inherit = "sale.order.line"

delivery_state = fields.Selection(
[
("no", "No delivery"),
("unprocessed", "Unprocessed"),
("partially", "Partially processed"),
("done", "Done"),
],
# Compute method have a different name then the field because
# the method _compute_delivery_state already exist to compute
# the field delivery_set in odoo delivery module
compute="_compute_sale_line_delivery_state",
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 line has qty_delivered >= to ordered quantities

:returns: boolean
"""
self.ensure_one()
precision = self.env["decimal.precision"].precision_get(
"Product Unit of Measure"
)
return (
float_compare(
self.qty_delivered, self.product_uom_qty, precision_digits=precision
)
>= 0
)

def _partially_delivered(self):
"""
Returns True if line has qty_delivered != to 0 and < ordered
quantities.

:returns: boolean
"""
self.ensure_one()
precision = self.env["decimal.precision"].precision_get(
"Product Unit of Measure"
)
return not float_is_zero(self.qty_delivered, precision_digits=precision)

@api.depends("qty_delivered", "state", "force_delivery_state")
def _compute_sale_line_delivery_state(self):
"""
If `delivery` module is installed, lines with delivery costs are marked
as 'No delivery'.
"""
for line in self:
if line.state in ("draft", "cancel") or line._is_delivery():
line.delivery_state = "no"
elif line.force_delivery_state or line._all_qty_delivered():
line.delivery_state = "done"
elif line._partially_delivered():
line.delivery_state = "partially"
else:
line.delivery_state = "unprocessed"

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

Check warning on line 79 in sale_order_line_delivery_state/models/sale_order_line.py

View check run for this annotation

Codecov / codecov/patch

sale_order_line_delivery_state/models/sale_order_line.py#L79

Added line #L79 was not covered by tests

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

Check warning on line 82 in sale_order_line_delivery_state/models/sale_order_line.py

View check run for this annotation

Codecov / codecov/patch

sale_order_line_delivery_state/models/sale_order_line.py#L82

Added line #L82 was not covered by tests
1 change: 1 addition & 0 deletions sale_order_line_delivery_state/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Jordi Masvidal <[email protected]>
15 changes: 15 additions & 0 deletions sale_order_line_delivery_state/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
This odoo module add delivery state on the sale order line. It is based on the
module sale_delivery_state, which adds the field at sale order level.

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

The state of the sale order line 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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading