Skip to content

Commit 2d087cd

Browse files
committed
Merge PR #3592 into 16.0
Signed-off-by rousseldenis
2 parents e963926 + 2a6f38f commit 2d087cd

17 files changed

Lines changed: 812 additions & 0 deletions

File tree

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
=============================
2+
Sale Order Warehouse Location
3+
=============================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:a6fbbfbf138dc7d4dec4d4c16d04d747ddfa8d743886c87bb0f653667b0322ab
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18+
:alt: License: AGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsale--workflow-lightgray.png?logo=github
20+
:target: https://github.com/OCA/sale-workflow/tree/16.0/sale_order_warehouse_location
21+
:alt: OCA/sale-workflow
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/sale-workflow-16-0/sale-workflow-16-0-sale_order_warehouse_location
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/sale-workflow&target_branch=16.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
This module allows to set countries and states in warehouses, so they
32+
can automatically be set in a sale order when its shipping address
33+
matches the countries and states selected in a given warehouse.
34+
35+
**Table of contents**
36+
37+
.. contents::
38+
:local:
39+
40+
Configuration
41+
=============
42+
43+
In configure countries and states in warehouses you need to:
44+
45+
1. Go to Inventory > Configuration > Warehouses and access a warehouse.
46+
2. Select the countries and/or states where the warehouse has to be
47+
automatically set in a sale order based on its shipping address. Only
48+
states that belong to the selected countries can be chosen.
49+
50+
Usage
51+
=====
52+
53+
When the shipping address field in a sale order is modified, it is
54+
checked whether a warehouse is applied in the region according to the
55+
shipping address' country and state. In order to determine if the
56+
warehouse matches the address, the country in the shipping address must
57+
be part of the "Sale Order Countries" field in a warehouse. Moreover, if
58+
the warehouse has some states in its "Sale Order States" field, the
59+
state in the shipping address must be part of this field too. If no
60+
warehouses are found, the default process for warehouse selection is
61+
followed.
62+
63+
Keep in mind that the Warehouse field in sale orders is only visible if
64+
the user has multi-warehouse rights.
65+
66+
Bug Tracker
67+
===========
68+
69+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/sale-workflow/issues>`_.
70+
In case of trouble, please check there if your issue has already been reported.
71+
If you spotted it first, help us to smash it by providing a detailed and welcomed
72+
`feedback <https://github.com/OCA/sale-workflow/issues/new?body=module:%20sale_order_warehouse_location%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
73+
74+
Do not contact contributors directly about support or help with technical issues.
75+
76+
Credits
77+
=======
78+
79+
Authors
80+
-------
81+
82+
* Sygel
83+
84+
Contributors
85+
------------
86+
87+
- Manuel Regidor <manuel.regidor@sygel.es>
88+
- Valentín Vinadre <valentin.vinagre@sygel.es>
89+
90+
Maintainers
91+
-----------
92+
93+
This module is maintained by the OCA.
94+
95+
.. image:: https://odoo-community.org/logo.png
96+
:alt: Odoo Community Association
97+
:target: https://odoo-community.org
98+
99+
OCA, or the Odoo Community Association, is a nonprofit organization whose
100+
mission is to support the collaborative development of Odoo features and
101+
promote its widespread use.
102+
103+
This module is part of the `OCA/sale-workflow <https://github.com/OCA/sale-workflow/tree/16.0/sale_order_warehouse_location>`_ project on GitHub.
104+
105+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Copyright 2025 Manuel Regidor <manuel.regidor@sygel.es>
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
from . import models
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright 2025 Manuel Regidor <manuel.regidor@sygel.es>
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
{
5+
"name": "Sale Order Warehouse Location",
6+
"summary": "Set warehouse in sales orders based on delivery country/state.",
7+
"version": "16.0.1.0.0",
8+
"category": "Stock",
9+
"website": "https://github.com/OCA/sale-workflow",
10+
"author": "Sygel, Odoo Community Association (OCA)",
11+
"license": "AGPL-3",
12+
"application": False,
13+
"installable": True,
14+
"depends": [
15+
"sale_stock",
16+
],
17+
"data": [
18+
"views/stock_warehouse_views.xml",
19+
],
20+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Copyright 2025 Manuel Regidor <manuel.regidor@sygel.es>
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
from . import sale_order
5+
from . import stock_warehouse
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright 2025 Manuel Regidor <manuel.regidor@sygel.es>
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
from odoo import api, models
5+
from odoo.fields import first
6+
7+
8+
class SaleOrder(models.Model):
9+
_inherit = "sale.order"
10+
11+
@api.depends("partner_shipping_id")
12+
def _compute_warehouse_id(self):
13+
ret_vals = super()._compute_warehouse_id()
14+
warehouses = self.env["stock.warehouse"].search(
15+
[("company_id", "in", [False] + self.company_id.ids)]
16+
)
17+
for order in self:
18+
if not (order.partner_shipping_id and order.state in ["draft", "sent"]):
19+
continue
20+
available_warehouse = first(
21+
warehouses.filtered(
22+
lambda wh: wh.company_id.id in [False, order.company_id.id]
23+
).warehouses_by_country_state(order.partner_shipping_id)
24+
)
25+
if available_warehouse and order.warehouse_id != available_warehouse:
26+
order.warehouse_id = available_warehouse
27+
return ret_vals
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Copyright 2025 Manuel Regidor <manuel.regidor@sygel.es>
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
from odoo import api, fields, models
5+
6+
7+
class StockWarehouse(models.Model):
8+
_inherit = "stock.warehouse"
9+
10+
sale_country_ids = fields.Many2many(
11+
comodel_name="res.country",
12+
string="Sale Order Countries",
13+
relation="warehouse_sale_country_rel",
14+
)
15+
sale_state_ids = fields.Many2many(
16+
string="Sale Order States",
17+
comodel_name="res.country.state",
18+
compute="_compute_sale_state_ids",
19+
store=True,
20+
readonly=False,
21+
domain="[('country_id', 'in', sale_country_ids)]",
22+
relation="warehouse_sale_state_rel",
23+
)
24+
25+
@api.depends("sale_country_ids")
26+
def _compute_sale_state_ids(self):
27+
for warehouse in self:
28+
sale_state_ids = self.sale_state_ids.filtered(
29+
lambda state: state.country_id.id in self.sale_country_ids.ids
30+
)
31+
warehouse.sale_state_ids = [(6, 0, sale_state_ids.ids)]
32+
33+
def warehouses_by_country_state(self, partner):
34+
return self.filtered(lambda w: w._match_country_state(partner))
35+
36+
def _match_country_state(self, partner):
37+
self.ensure_one()
38+
return (
39+
self.sale_country_ids
40+
and partner.country_id.id in self.sale_country_ids.ids
41+
and (
42+
not self.sale_state_ids
43+
or partner.state_id.id in self.sale_state_ids.ids
44+
)
45+
)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
In configure countries and states in warehouses you need to:
2+
3+
1. Go to Inventory > Configuration > Warehouses and access a warehouse.
4+
2. Select the countries and/or states where the warehouse has to be automatically set in a sale order based on its shipping address. Only states that belong to the selected countries can be chosen.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Manuel Regidor \<<manuel.regidor@sygel.es>\>
2+
- Valentín Vinadre \<<valentin.vinagre@sygel.es>\>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This module allows to set countries and states in warehouses, so they can automatically be set in a sale order when its shipping address matches the countries and states selected in a given warehouse.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
When the shipping address field in a sale order is modified, it is checked whether a warehouse is applied in the region according to the shipping address' country and state. In order to determine if the warehouse matches the address, the country in the shipping address must be part of the "Sale Order Countries" field in a warehouse. Moreover, if the warehouse has some states in its "Sale Order States" field, the state in the shipping address must be part of this field too. If no warehouses are found, the default process for warehouse selection is followed.
2+
3+
Keep in mind that the Warehouse field in sale orders is only visible if the user has multi-warehouse rights.

0 commit comments

Comments
 (0)