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] stock_location_address_purchase: migration to 16.0 #165

Open
wants to merge 23 commits into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
86fd82e
[ADD] stock_location_address_purchase
etobella Mar 26, 2018
be072d2
- code style fixes
JordiBForgeFlow Apr 10, 2018
3fbf77f
[MIG] stocK_location_address_purchase: Migration to 12.0
Oct 30, 2019
b0e41c2
[UPD] Update stock_location_address_purchase.pot
oca-travis Nov 11, 2019
667d9a0
[IMP] stock_location_address_purchase: black, isort
JoanSForgeFlow Jan 10, 2020
601ea05
[MIG] stock_location_address_purchase: Migration to 13.0
JoanSForgeFlow Jan 10, 2020
55d0906
[UPD] Update stock_location_address_purchase.pot
oca-travis Jan 15, 2020
94a5ddf
[FIX] stock_location_address_purchase: Address was not passed when ru…
etobella Apr 13, 2021
d59db5e
[UPD] Update stock_location_address_purchase.pot
oca-travis Apr 14, 2021
24bbb44
stock_location_address_purchase 13.0.1.0.1
OCA-git-bot Apr 14, 2021
6ef1a68
[IMP] stock_location_address_purchase: black, isort, prettier
JoanMForgeFlow Dec 13, 2021
6d0fab4
[MIG] stock_location_addres_purchase: Migration to 14.0
JoanMForgeFlow Dec 13, 2021
aa44108
[UPD] Update stock_location_address_purchase.pot
oca-travis Dec 14, 2021
fb56b64
[MIG] stock_location_address_purchase: Migration to 15.0
JoanMForgeFlow Dec 23, 2021
8e7c4ee
[UPD] Update stock_location_address_purchase.pot
Jan 13, 2022
976f7d9
[FIX] TestPurchaseBuyRule.test_no_destination and TestPurchaseBuyRule…
nitohu Jul 21, 2022
00b8cbf
[IMP] stock_location_address_purchase: black, isort, prettier
nitohu Jul 21, 2022
28b3ca7
[ADD] TypeError test for _create_make_procurement function
nitohu Jul 27, 2022
8b2d051
[IMP] stock_location_address_purchase: black, isort, prettier
nitohu Jul 27, 2022
398688c
stock_location_address_purchase 15.0.1.0.1
OCA-git-bot Jul 27, 2022
832062d
[IMP] stock_location_address_purchase: black, isort, prettier
kluna1998 Jan 13, 2025
3c4efbe
[MIG] stock_location_address_purchase: migration to 16.0
kluna1998 Jan 20, 2025
16e1e0b
[FIX] shipment_advice_planner: fix test
kluna1998 Jan 20, 2025
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: 6 additions & 0 deletions setup/stock_location_address_purchase/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,
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class TestShipmentAdvicePlanner(TestShipmentAdvicePlannerCommon):
def test_shipment_advice_planner_multi_warehouse(self):
self.assertEqual(len(self.pickings), 31)
self.assertEqual(len(self.pickings), 32)
self.assertEqual(len(self.wizard_form.picking_to_plan_ids), 10)
wizard = self.wizard_form.save()
action = wizard.button_plan_shipments()
Expand Down
55 changes: 55 additions & 0 deletions stock_location_address_purchase/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
.. image:: https://img.shields.io/badge/licence-LGPL--3-blue.svg
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3

=========================
Purchase Location address
=========================

This module allows to use the location address on purchases

Usage
=====

#. Go to 'Purchases / Requests for Quotation'
#. Create a Purchase order and select the created operation type
#. The delivery address of the purchase will be the one selected on the
operation type destination location


.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/168/11.0


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 smash it by providing detailed and welcomed feedback.


Credits
=======

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

* Enric Tobella <[email protected]>.

Maintainer
----------

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

This module is maintained by the OCA.

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.

To contribute to this module, please visit https://odoo-community.org.
1 change: 1 addition & 0 deletions stock_location_address_purchase/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
14 changes: 14 additions & 0 deletions stock_location_address_purchase/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2018 Creu Blanca
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

{
"name": "Purchase Location address",
"summary": "Uses the location address on purchases",
"version": "16.0.1.0.1",
"license": "AGPL-3",
"website": "https://github.com/OCA/stock-logistics-transport",
"author": "Creu Blanca, Odoo Community Association (OCA)",
"category": "Purchases",
"depends": ["purchase_stock", "stock_location_address"],
"installable": True,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * stock_location_address_purchase
#
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: stock_location_address_purchase
#: model:ir.model,name:stock_location_address_purchase.model_purchase_order
msgid "Purchase Order"
msgstr ""

#. module: stock_location_address_purchase
#: model:ir.model,name:stock_location_address_purchase.model_stock_rule
msgid "Stock Rule"
msgstr ""
2 changes: 2 additions & 0 deletions stock_location_address_purchase/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import purchase
from . import stock_rule
23 changes: 23 additions & 0 deletions stock_location_address_purchase/models/purchase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2018 Creu Blanca
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import api, models


class PurchaseOrder(models.Model):
_inherit = "purchase.order"

@api.onchange("picking_type_id")
def _onchange_picking_type_id(self):
location = self.picking_type_id.default_location_dest_id
if location.usage == "internal":
self.dest_address_id = location.real_address_id
return
super()._onchange_picking_type_id()

def _get_destination_location(self):
self.ensure_one()
lc = self.picking_type_id.default_location_dest_id
if self.dest_address_id and lc.real_address_id == self.dest_address_id:
return lc.id
return super()._get_destination_location()
16 changes: 16 additions & 0 deletions stock_location_address_purchase/models/stock_rule.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2021 Creu Blanca
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import models


class StockRule(models.Model):

_inherit = "stock.rule"

def _prepare_purchase_order(self, company_id, origins, values):
res = super()._prepare_purchase_order(company_id, origins, values)
location = self.picking_type_id.default_location_dest_id
if not res.get("dest_address_id", False) and location.usage == "internal":
res["dest_address_id"] = location.real_address_id.id
return res
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions stock_location_address_purchase/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import test_purchase_address
from . import test_purchase_buy_rule
112 changes: 112 additions & 0 deletions stock_location_address_purchase/tests/test_purchase_address.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# Copyright 2018 Creu Blanca
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import fields
from odoo.tests import TransactionCase


class TestPickingAddress(TransactionCase):
def setUp(self):
super().setUp()
self.warehouse = self.env["stock.warehouse"].create(
{"name": "Test Warehouse", "code": "TEST_WH"}
)
self.sequence = self.env["ir.sequence"].create(
{"name": "Picking test sequence", "company_id": False}
)
self.partner = self.env["res.partner"].create({"name": "Partner"})
self.location_partner = self.env["res.partner"].create(
{"name": "Location_address"}
)
self.location = self.env["stock.location"].create(
{
"name": "Location",
"location_id": self.warehouse.view_location_id.id,
"usage": "internal",
"address_id": self.location_partner.id,
}
)
self.picking_01 = self.env["stock.picking.type"].create(
{
"code": "incoming",
"name": "Picking 01",
"sequence_id": self.sequence.id,
"sequence_code": "IN",
"warehouse_id": self.warehouse.id,
"default_location_dest_id": self.location.id,
}
)
self.picking_02 = self.env["stock.picking.type"].create(
{
"code": "incoming",
"name": "Picking 02",
"sequence_id": self.sequence.id,
"sequence_code": "IN",
"warehouse_id": self.warehouse.id,
"default_location_dest_id": self.warehouse.lot_stock_id.id,
}
)
self.product = self.env["product.product"].create(
{"name": "Product", "type": "product", "purchase_ok": True}
)

def test_onchange_purchase(self):
purchase = self.env["purchase.order"].new(
{"partner_id": self.partner.id, "picking_type_id": self.picking_01.id}
)
purchase._onchange_picking_type_id()
self.assertEqual(self.location_partner, purchase.dest_address_id)
purchase.update({"picking_type_id": self.picking_02.id})
purchase._onchange_picking_type_id()
self.assertFalse(purchase.dest_address_id)

def test_purchase_with_destination(self):
purchase = self.env["purchase.order"].create(
{
"partner_id": self.partner.id,
"picking_type_id": self.picking_01.id,
"order_line": [
(
0,
0,
{
"product_id": self.product.id,
"product_qty": 1,
"name": self.product.name,
"date_planned": fields.Date.today(),
"product_uom": self.product.uom_po_id.id,
"price_unit": 1,
},
)
],
}
)
purchase._onchange_picking_type_id()
self.assertEqual(self.location.address_id, purchase.dest_address_id)
purchase.button_confirm()
self.assertEqual(purchase.picking_ids.location_dest_id, self.location)

def test_purchase_without_destination(self):
purchase = self.env["purchase.order"].create(
{
"partner_id": self.partner.id,
"picking_type_id": self.picking_02.id,
"order_line": [
(
0,
0,
{
"product_id": self.product.id,
"name": self.product.name,
"date_planned": fields.Date.today(),
"product_qty": 1,
"product_uom": self.product.uom_po_id.id,
"price_unit": 1,
},
)
],
}
)
purchase._onchange_picking_type_id()
purchase.button_confirm()
self.assertFalse(purchase.dest_address_id)
55 changes: 55 additions & 0 deletions stock_location_address_purchase/tests/test_purchase_buy_rule.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from datetime import timedelta

from odoo import fields

from odoo.addons.purchase_stock.tests.common import PurchaseTestCommon


class TestPurchaseBuyRule(PurchaseTestCommon):
def test_no_destination(self):
company = self.env.ref("base.main_company")
# Update company with Purchase Lead Time
company.write({"po_lead": 3.00})
date_planned = fields.Datetime.now() + timedelta(days=10)
# Prepare string from timestamp
date_planned_str = fields.Datetime.to_string(date_planned)
# This function takes a date as argument
self._create_make_procurement(self.product_1, 15.00, date_planned=date_planned)
purchase = (
self.env["purchase.order.line"]
.search([("product_id", "=", self.product_1.id)], limit=1)
.order_id
)
self.assertTrue(purchase)
self.assertFalse(purchase.dest_address_id)
# Test for TypeError when passing date as string
self.assertRaises(
TypeError,
self._create_make_procurement(
self.product_1, 15.00, date_planned=date_planned_str
),
)

def test_destination(self):
company = self.env.ref("base.main_company")
# Update company with Purchase Lead Time
company.write({"po_lead": 3.00})
date_planned = fields.Datetime.now() + timedelta(days=10)
date_planned_str = fields.Datetime.to_string(date_planned)
partner = self.env["res.partner"].create({"name": "DEMO Partner"})
self.warehouse_1.lot_stock_id.real_address_id = partner
self._create_make_procurement(self.product_1, 15.00, date_planned=date_planned)
purchase = (
self.env["purchase.order.line"]
.search([("product_id", "=", self.product_1.id)], limit=1)
.order_id
)
self.assertTrue(purchase)
self.assertTrue(purchase.dest_address_id)
self.assertEqual(purchase.dest_address_id, partner)
self.assertRaises(
TypeError,
self._create_make_procurement(
self.product_1, 15.00, date_planned=date_planned_str
),
)
Loading