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

[18][ADD/MIG] delivery_carrier_option (extracted from base_delivery_carrier_label module) #900

Open
wants to merge 1 commit into
base: 18.0
Choose a base branch
from
Open
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
88 changes: 88 additions & 0 deletions delivery_carrier_option/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
=======================
Delivery Carrier Option
=======================

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

.. |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%2Fdelivery--carrier-lightgray.png?logo=github
:target: https://github.com/OCA/delivery-carrier/tree/18.0/delivery_carrier_option
:alt: OCA/delivery-carrier
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/delivery-carrier-18-0/delivery-carrier-18-0-delivery_carrier_option
: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/delivery-carrier&target_branch=18.0
:alt: Try me on Runboat

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

This module adds the concept of option on carriers that can differ
depending on the picking This module doesn't do anything by itself, it
serves as a base module for other carrier-specific modules.

**Table of contents**

.. contents::
:local:

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/delivery-carrier/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/delivery-carrier/issues/new?body=module:%20delivery_carrier_option%0Aversion:%2018.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
-------

* Camptocamp
* Akretion

Contributors
------------

- David BEAL <[email protected]>
- Sébastien BEAU <[email protected]>
- Yannick Vaucher <[email protected]>
- Alexis de Lattre <[email protected]>
- Angel Moya <[email protected]>
- Ismael Calvo <[email protected]>
- Dave Lasley <[email protected]>
- Timothée Ringeard <[email protected]>
- Pimolnat Suntian <[email protected]>
- Raphaël Reverdy <[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/delivery-carrier <https://github.com/OCA/delivery-carrier/tree/18.0/delivery_carrier_option>`_ 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 delivery_carrier_option/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
20 changes: 20 additions & 0 deletions delivery_carrier_option/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
"name": "Delivery Carrier Option",
"version": "18.0.1.0.0",
"author": "Camptocamp,Akretion,Odoo Community Association (OCA)",
"category": "Delivery",
"depends": [
"stock_delivery",
],
"website": "https://github.com/OCA/delivery-carrier",
"data": [
"views/stock_picking.xml",
"views/delivery_carrier.xml",
"security/ir.model.access.csv",
"views/delivery_carrier_template_option.xml",
"views/delivery_carrier_option.xml",
],
"installable": True,
"license": "AGPL-3",
}
4 changes: 4 additions & 0 deletions delivery_carrier_option/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from . import delivery_carrier
from . import delivery_carrier_template_option
from . import delivery_carrier_option
from . import stock_picking
25 changes: 25 additions & 0 deletions delivery_carrier_option/models/delivery_carrier.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2012 Akretion <http://www.akretion.com>.
# Copyright 2013-2016 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class DeliveryCarrier(models.Model):
_inherit = "delivery.carrier"

available_option_ids = fields.One2many(
comodel_name="delivery.carrier.option",
inverse_name="carrier_id",
string="Option",
context={"active_test": False},
)

def default_options(self):
"""Returns default and available options for a carrier"""
self.ensure_one()
options = self.env["delivery.carrier.option"].browse()
for available_option in self.available_option_ids:
if available_option.mandatory or available_option.by_default:
options |= available_option
return options
53 changes: 53 additions & 0 deletions delivery_carrier_option/models/delivery_carrier_option.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Copyright 2012 Akretion <http://www.akretion.com>.
# Copyright 2013-2016 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class DeliveryCarrierOption(models.Model):
"""Option selected for a carrier method

Those options define the list of available pre-added and available
to be added on delivery orders

"""

_name = "delivery.carrier.option"
_description = "Delivery carrier option"
_inherits = {"delivery.carrier.template.option": "tmpl_option_id"}

active = fields.Boolean(default=True)
mandatory = fields.Boolean(
help=(
"If checked, this option is necessarily applied "
"to the delivery order. Mandatory options show up in orange "
"in the option widget on the picking."
),
)
by_default = fields.Boolean(
string="Applied by Default",
help="By check, user can choose to apply this option "
"to each Delivery Order\n using this delivery method",
)
tmpl_option_id = fields.Many2one(
comodel_name="delivery.carrier.template.option",
string="Option",
required=True,
ondelete="cascade",
)
carrier_id = fields.Many2one(comodel_name="delivery.carrier", string="Carrier")
readonly_flag = fields.Boolean(
help="When True, help to prevent the user to modify some fields "
"option (if attribute is defined in the view)",
)
color = fields.Integer(
compute="_compute_color",
help="Orange if the option is mandatory, otherwise no color",
)

@api.depends("mandatory")
def _compute_color(self):
"""Show that a tag is mandatory using the color attribute"""
for tag in self:
tag.color = 2 if tag.mandatory else False
20 changes: 20 additions & 0 deletions delivery_carrier_option/models/delivery_carrier_template_option.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2012 Akretion <http://www.akretion.com>.
# Copyright 2013-2016 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class DeliveryCarrierTemplateOption(models.Model):
"""Available options for a carrier (partner)"""

_name = "delivery.carrier.template.option"
_description = "Delivery carrier template option"

partner_id = fields.Many2one(comodel_name="res.partner", string="Partner Carrier")
name = fields.Char(readonly=True)
code = fields.Char(readonly=True)
description = fields.Char(
readonly=True,
help="Allow to define a more complete description " "than in the name field.",
)
48 changes: 48 additions & 0 deletions delivery_carrier_option/models/stock_picking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Copyright 2012-2015 Akretion <http://www.akretion.com>.
# Copyright 2013-2016 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import logging

from odoo import api, fields, models

_logger = logging.getLogger(__name__)


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

option_ids = fields.Many2many(
comodel_name="delivery.carrier.option",
string="Options",
compute="_compute_option_ids",
store=True,
readonly=False,
)

@api.depends("carrier_id")
def _compute_option_ids(self):
for picking in self:
picking.option_ids = picking._get_default_options()

def _get_default_options(self):
self.ensure_one()
default_options = []
if self.carrier_id:
default_options = self.carrier_id.default_options()
return default_options

@api.onchange("option_ids")
def onchange_option_ids(self):
if not self.carrier_id:
return
carrier = self.carrier_id
current_options = options = self.option_ids
for available_option in carrier.available_option_ids:
if (
available_option.mandatory
and available_option.id not in self.option_ids.ids
):
options |= available_option
if current_options != options:
self.option_ids = options
3 changes: 3 additions & 0 deletions delivery_carrier_option/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
10 changes: 10 additions & 0 deletions delivery_carrier_option/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
- David BEAL \<<[email protected]>\>
- Sébastien BEAU \<<[email protected]>\>
- Yannick Vaucher \<<[email protected]>\>
- Alexis de Lattre \<<[email protected]>\>
- Angel Moya \<<[email protected]>\>
- Ismael Calvo \<<[email protected]>\>
- Dave Lasley \<<[email protected]>\>
- Timothée Ringeard \<<[email protected]>\>
- Pimolnat Suntian \<<[email protected]>\>
- Raphaël Reverdy \<<[email protected]>\>
3 changes: 3 additions & 0 deletions delivery_carrier_option/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This module adds the concept of option on carriers that can differ
depending on the picking This module doesn't do anything by itself, it
serves as a base module for other carrier-specific modules.
8 changes: 8 additions & 0 deletions delivery_carrier_option/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_delivery_carrier_option_salesman,delivery.carrier.option.salesman,model_delivery_carrier_option,sales_team.group_sale_salesman,1,0,0,0
access_delivery_carrier_option_sale_manager,delivery.carrier.option.sale.manager,model_delivery_carrier_option,sales_team.group_sale_manager,1,1,1,1
access_delivery_carrier_template_option_salesman,delivery.carrier.relation.option.salesman,model_delivery_carrier_template_option,sales_team.group_sale_salesman,1,0,0,0
access_delivery_carrier_template_option_sales_manager,delivery.carrier.relation.option.sale.manager,model_delivery_carrier_template_option,sales_team.group_sale_manager,1,1,1,1
access_delivery_carrier_option_stock_user,delivery.carrier.option stock_user,model_delivery_carrier_option,stock.group_stock_user,1,1,1,1
access_delivery_carrier_template_option_stock_user,delivery.carrier.template.option stock_user,model_delivery_carrier_template_option,stock.group_stock_user,1,0,0,0
access_delivery_carrier_template_option_stock_manager,delivery.carrier.template.option stock_manager,model_delivery_carrier_template_option,stock.group_stock_manager,1,1,1,1
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading