diff --git a/setup/stock_request_partner/odoo/addons/stock_request_partner b/setup/stock_request_partner/odoo/addons/stock_request_partner new file mode 120000 index 000000000..e1b5ce9e7 --- /dev/null +++ b/setup/stock_request_partner/odoo/addons/stock_request_partner @@ -0,0 +1 @@ +../../../../stock_request_partner \ No newline at end of file diff --git a/setup/stock_request_partner/setup.py b/setup/stock_request_partner/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/stock_request_partner/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/stock_request_partner/README.rst b/stock_request_partner/README.rst new file mode 100644 index 000000000..7b1945c35 --- /dev/null +++ b/stock_request_partner/README.rst @@ -0,0 +1,89 @@ +===================== +Stock Request Partner +===================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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-LGPL--3-blue.png + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstock--logistics--warehouse-lightgray.png?logo=github + :target: https://github.com/OCA/stock-logistics-warehouse/tree/14.0/stock_request_partner + :alt: OCA/stock-logistics-warehouse +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/stock-logistics-warehouse-14-0/stock-logistics-warehouse-14-0-stock_request_partner + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/153/14.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module was written to allow to define partner in stock request and pass the partner +to the related pickings. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +## Creation + +* Go to 'Stock Requests / Stock Requests' and create a new Request. +* Indicate a partner, product, quantity and location. +* Press 'Confirm'. + +In case that transfers are created, if the partner is set, a procurement group +will be created automatically with the related partner and it will be propagated +to the related transfers. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Jarsa + +Contributors +~~~~~~~~~~~~ + +* `Jarsa `_ + + * Alan Ramos + +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/stock-logistics-warehouse `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/stock_request_partner/__init__.py b/stock_request_partner/__init__.py new file mode 100644 index 000000000..7f6052db9 --- /dev/null +++ b/stock_request_partner/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2020 Jarsa Sistemas, S.A. de C.V. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from . import models diff --git a/stock_request_partner/__manifest__.py b/stock_request_partner/__manifest__.py new file mode 100644 index 000000000..0d32606dc --- /dev/null +++ b/stock_request_partner/__manifest__.py @@ -0,0 +1,17 @@ +# Copyright 2020 Jarsa Sistemas, S.A. de C.V. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +{ + "name": "Stock Request Partner", + "summary": "Allow to define partner in Stock Request", + "version": "14.0.1.0.0", + "license": "LGPL-3", + "website": "https://github.com/OCA/stock-logistics-warehouse", + "author": "Jarsa, Odoo Community Association (OCA)", + "category": "Warehouse Management", + "depends": ["stock_request"], + "data": [ + "views/stock_request_views.xml", + "views/stock_request_order_views.xml", + ], +} diff --git a/stock_request_partner/models/__init__.py b/stock_request_partner/models/__init__.py new file mode 100644 index 000000000..78cb07e97 --- /dev/null +++ b/stock_request_partner/models/__init__.py @@ -0,0 +1,5 @@ +# Copyright 2020 Jarsa Sistemas, S.A. de C.V. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from . import stock_request +from . import stock_request_order diff --git a/stock_request_partner/models/stock_request.py b/stock_request_partner/models/stock_request.py new file mode 100644 index 000000000..c07534219 --- /dev/null +++ b/stock_request_partner/models/stock_request.py @@ -0,0 +1,36 @@ +# Copyright 2020 Jarsa Sistemas, S.A. de C.V. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from odoo import _, api, fields, models +from odoo.exceptions import ValidationError + + +class StockRequest(models.Model): + _inherit = "stock.request" + + partner_id = fields.Many2one( + "res.partner", states={"draft": [("readonly", False)]}, readonly=True + ) + + def _prepare_procurement_values(self, group_id=False): + res = super()._prepare_procurement_values(group_id) + if self.partner_id: + name = self.name + if self.order_id: + name = self.order_id.name + group = self.env["procurement.group"].search([("name", "=", name)]) + if not group: + group = self.env["procurement.group"].create( + { + "name": name, + "partner_id": self.partner_id.id, + "move_type": self.picking_policy, + } + ) + res["group_id"] = group + return res + + @api.constrains("order_id", "partner_id") + def check_order_partner_id(self): + if self.order_id and self.order_id.partner_id != self.partner_id: + raise ValidationError(_("Partner must be equal to the order")) diff --git a/stock_request_partner/models/stock_request_order.py b/stock_request_partner/models/stock_request_order.py new file mode 100644 index 000000000..48a2e64c7 --- /dev/null +++ b/stock_request_partner/models/stock_request_order.py @@ -0,0 +1,21 @@ +# Copyright 2020 Jarsa Sistemas, S.A. de C.V. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from odoo import api, fields, models + + +class StockRequestOrder(models.Model): + _inherit = "stock.request.order" + + partner_id = fields.Many2one( + "res.partner", states={"draft": [("readonly", False)]}, readonly=True + ) + + @api.onchange("partner_id") + def _onchange_partner_id(self): + if self.partner_id: + self.stock_request_ids.update( + { + "partner_id": self.partner_id, + } + ) diff --git a/stock_request_partner/readme/CONTRIBUTORS.rst b/stock_request_partner/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..1e715abde --- /dev/null +++ b/stock_request_partner/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `Jarsa `_ + + * Alan Ramos diff --git a/stock_request_partner/readme/DESCRIPTION.rst b/stock_request_partner/readme/DESCRIPTION.rst new file mode 100644 index 000000000..f35deeb32 --- /dev/null +++ b/stock_request_partner/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +This module was written to allow to define partner in stock request and pass the partner +to the related pickings. diff --git a/stock_request_partner/readme/USAGE.rst b/stock_request_partner/readme/USAGE.rst new file mode 100644 index 000000000..6683b5068 --- /dev/null +++ b/stock_request_partner/readme/USAGE.rst @@ -0,0 +1,9 @@ +## Creation + +* Go to 'Stock Requests / Stock Requests' and create a new Request. +* Indicate a partner, product, quantity and location. +* Press 'Confirm'. + +In case that transfers are created, if the partner is set, a procurement group +will be created automatically with the related partner and it will be propagated +to the related transfers. diff --git a/stock_request_partner/static/description/icon.png b/stock_request_partner/static/description/icon.png new file mode 100644 index 000000000..d4f6a65ac Binary files /dev/null and b/stock_request_partner/static/description/icon.png differ diff --git a/stock_request_partner/static/description/icon.svg b/stock_request_partner/static/description/icon.svg new file mode 100644 index 000000000..ff839e0b3 --- /dev/null +++ b/stock_request_partner/static/description/icon.svg @@ -0,0 +1,180 @@ + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + diff --git a/stock_request_partner/static/description/index.html b/stock_request_partner/static/description/index.html new file mode 100644 index 000000000..dcf2af76e --- /dev/null +++ b/stock_request_partner/static/description/index.html @@ -0,0 +1,436 @@ + + + + + + +Stock Request Partner + + + +
+

Stock Request Partner

+ + +

Beta License: LGPL-3 OCA/stock-logistics-warehouse Translate me on Weblate Try me on Runbot

+

This module was written to allow to define partner in stock request and pass the partner +to the related pickings.

+

Table of contents

+ +
+

Usage

+

## Creation

+
    +
  • Go to ‘Stock Requests / Stock Requests’ and create a new Request.
  • +
  • Indicate a partner, product, quantity and location.
  • +
  • Press ‘Confirm’.
  • +
+

In case that transfers are created, if the partner is set, a procurement group +will be created automatically with the related partner and it will be propagated +to the related transfers.

+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Jarsa
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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/stock-logistics-warehouse project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/stock_request_partner/tests/__init__.py b/stock_request_partner/tests/__init__.py new file mode 100644 index 000000000..d9b0615a2 --- /dev/null +++ b/stock_request_partner/tests/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2020 Jarsa Sistemas, S.A. de C.V. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from . import test_stock_request diff --git a/stock_request_partner/tests/test_stock_request.py b/stock_request_partner/tests/test_stock_request.py new file mode 100644 index 000000000..b316eac6e --- /dev/null +++ b/stock_request_partner/tests/test_stock_request.py @@ -0,0 +1,81 @@ +# Copyright 2020 Jarsa Sistemas, S.A. de C.V. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from odoo import fields +from odoo.exceptions import ValidationError + +from odoo.addons.stock_request.tests.test_stock_request import TestStockRequest + + +class TestStockRequestPartner(TestStockRequest): + def setUp(self): + super(TestStockRequestPartner, self).setUp() + self.partner = self.env.ref("base.res_partner_12") + self.partner2 = self.env.ref("base.res_partner_2") + + def test_stock_request_partner_to_picking(self): + vals = { + "product_id": self.product.id, + "product_uom_id": self.product.uom_id.id, + "product_uom_qty": 5.0, + "partner_id": self.partner.id, + } + request = ( + self.stock_request.with_user(self.stock_request_manager) + .with_context(company_id=self.main_company.id) + .create(vals) + ) + self.product.route_ids = [(6, 0, self.route.ids)] + request.with_user(self.stock_request_manager).action_confirm() + self.assertEqual(request.picking_ids.partner_id, self.partner) + + def test_stock_request_order(self): + expected_date = fields.Datetime.now() + product2 = self._create_product("SH2", "Shoes 2", False) + vals = { + "partner_id": self.partner.id, + "company_id": self.main_company.id, + "warehouse_id": self.warehouse.id, + "location_id": self.warehouse.lot_stock_id.id, + "expected_date": expected_date, + "stock_request_ids": [ + ( + 0, + 0, + { + "partner_id": self.partner.id, + "product_id": self.product.id, + "product_uom_id": self.product.uom_id.id, + "product_uom_qty": 5.0, + "company_id": self.main_company.id, + "warehouse_id": self.warehouse.id, + "location_id": self.warehouse.lot_stock_id.id, + "expected_date": expected_date, + }, + ), + ( + 0, + 0, + { + "partner_id": self.partner.id, + "product_id": product2.id, + "product_uom_id": product2.uom_id.id, + "product_uom_qty": 10.0, + "company_id": self.main_company.id, + "warehouse_id": self.warehouse.id, + "location_id": self.warehouse.lot_stock_id.id, + "expected_date": expected_date, + }, + ), + ], + } + order = self.request_order.with_user(self.stock_request_user).create(vals) + order.partner_id = self.partner2 + order._onchange_partner_id() + self.assertEqual(order.stock_request_ids.partner_id, self.partner2) + with self.assertRaises(ValidationError): + order.stock_request_ids[0].partner_id = self.partner + self.product.route_ids = [(6, 0, self.route.ids)] + product2.route_ids = [(6, 0, self.route.ids)] + order.with_user(self.stock_request_manager).action_confirm() + self.assertEqual(len(order.picking_ids), 1) diff --git a/stock_request_partner/views/stock_request_order_views.xml b/stock_request_partner/views/stock_request_order_views.xml new file mode 100644 index 000000000..c3c658768 --- /dev/null +++ b/stock_request_partner/views/stock_request_order_views.xml @@ -0,0 +1,28 @@ + + + + stock_request_order.form + stock.request.order + + + + + + + { + 'default_expected_date':expected_date, + 'default_picking_policy': picking_policy, + 'default_warehouse_id': warehouse_id, + 'default_location_id': location_id, + 'default_procurement_group_id': procurement_group_id, + 'default_company_id': company_id, + 'default_state': state, + 'default_partner_id': partner_id, + } + + + + + + + diff --git a/stock_request_partner/views/stock_request_views.xml b/stock_request_partner/views/stock_request_views.xml new file mode 100644 index 000000000..b86682644 --- /dev/null +++ b/stock_request_partner/views/stock_request_views.xml @@ -0,0 +1,13 @@ + + + + stock_request.form + stock.request + + + + + + + +