diff --git a/pms_purchase/README.rst b/pms_purchase/README.rst new file mode 100644 index 000000000..d473d8286 --- /dev/null +++ b/pms_purchase/README.rst @@ -0,0 +1,94 @@ +============== +PMS - Purchase +============== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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-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%2Fpms-lightgray.png?logo=github + :target: https://github.com/OCA/pms/tree/14.0/pms_purchase + :alt: OCA/pms +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/pms-14-0/pms-14-0-pms_purchase + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/293/14.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows you to select a PMS property on the PO line. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +* Go to Purchase +* Create or select a request for quotation +* Set the warehouse to a building +* Select the property on the lines +* Confirm the request +* Open the receipt +* Transfer the receipt. The product is stored in the location of the property + +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 +~~~~~~~ + +* Open Source Integrators + +Contributors +~~~~~~~~~~~~ + +* `Open Source Integrators `: + + * Maxime Chambreuil + +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. + +.. |maintainer-max3903| image:: https://github.com/max3903.png?size=40px + :target: https://github.com/max3903 + :alt: max3903 + +Current `maintainer `__: + +|maintainer-max3903| + +This module is part of the `OCA/pms `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/pms_purchase/__init__.py b/pms_purchase/__init__.py new file mode 100644 index 000000000..02179fb04 --- /dev/null +++ b/pms_purchase/__init__.py @@ -0,0 +1,2 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from . import models diff --git a/pms_purchase/__manifest__.py b/pms_purchase/__manifest__.py new file mode 100644 index 000000000..6fb2c8d61 --- /dev/null +++ b/pms_purchase/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright (c) 2022 Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +{ + "name": "PMS - Purchase", + "summary": "Select a PMS property on the PO line.", + "version": "14.0.1.0.0", + "category": "purchase", + "website": "https://github.com/OCA/pms", + "author": "Open Source Integrators, Odoo Community Association (OCA)", + "maintainers": ["max3903"], + "license": "AGPL-3", + "depends": ["pms_account", "purchase_stock", "pms_stock", "stock_putaway_method"], + "data": [ + "views/purchase_order.xml", + "views/pms_property.xml", + "views/stock_putaway_views.xml", + ], + "development_status": "Beta", +} diff --git a/pms_purchase/models/__init__.py b/pms_purchase/models/__init__.py new file mode 100644 index 000000000..facdc844c --- /dev/null +++ b/pms_purchase/models/__init__.py @@ -0,0 +1,5 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from . import purchase_order_line +from . import stock_putaway_rule +from . import pms_property +from . import stock_move diff --git a/pms_purchase/models/pms_property.py b/pms_purchase/models/pms_property.py new file mode 100644 index 000000000..9e5bcc38e --- /dev/null +++ b/pms_purchase/models/pms_property.py @@ -0,0 +1,30 @@ +# Copyright (c) 2022 Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo import _, api, fields, models + + +class PmsProperty(models.Model): + _inherit = "pms.property" + + po_line_ids = fields.One2many( + "purchase.order.line", "pms_property_id", string="Purchases" + ) + po_line_count = fields.Integer( + compute="_compute_po_line_count", string="PO Line(s)", readonly=True, copy=False + ) + + @api.depends("po_line_ids") + def _compute_po_line_count(self): + for pms_property in self: + pms_property.po_line_count = len(pms_property.po_line_ids) + + def action_open_po_line(self): + view_id = self.env.ref("purchase.purchase_order_line_tree").id + return { + "name": _("Purchase Order Lines"), + "view_mode": "tree", + "view_id": view_id, + "res_model": "purchase.order.line", + "domain": [("id", "in", self.po_line_ids.ids)], + "type": "ir.actions.act_window", + } diff --git a/pms_purchase/models/purchase_order_line.py b/pms_purchase/models/purchase_order_line.py new file mode 100644 index 000000000..a7a3a7b47 --- /dev/null +++ b/pms_purchase/models/purchase_order_line.py @@ -0,0 +1,17 @@ +# Copyright (c) 2022 Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo import api, fields, models + + +class PurchaseOrderLine(models.Model): + _inherit = "purchase.order.line" + + pms_property_id = fields.Many2one("pms.property", string="Property") + + @api.onchange("pms_property_id") + def _onchange_pms_property_id(self): + account_analytic_id = False + for rec in self: + if rec.pms_property_id and rec.pms_property_id.analytic_id: + account_analytic_id = rec.pms_property_id.analytic_id.id + rec.account_analytic_id = account_analytic_id diff --git a/pms_purchase/models/stock_move.py b/pms_purchase/models/stock_move.py new file mode 100644 index 000000000..76a4723bf --- /dev/null +++ b/pms_purchase/models/stock_move.py @@ -0,0 +1,36 @@ +# Copyright (c) 2022 Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo import models + + +class StockMove(models.Model): + _inherit = "stock.move" + + def _prepare_move_line_vals(self, quantity=None, reserved_quant=None): + self.ensure_one() + rules = self.location_dest_id.putaway_rule_ids.filtered( + lambda x: x.product_id == self.product_id + ) + if not rules: + rules = self.location_dest_id.putaway_rule_ids.filtered( + lambda x: x.category_id == self.product_id.categ_id + ) + rules = rules and rules[0] or self.env["stock.putaway.rule"] + res = super(StockMove, self)._prepare_move_line_vals(quantity, reserved_quant) + po = self.picking_id.purchase_id + po_warehouse_id = po.picking_type_id.default_location_dest_id.get_warehouse().id + line = self.purchase_line_id + property_warehouse_id = ( + line.pms_property_id.stock_location_id.get_warehouse().id + ) + if ( + rules.method == "move_to_property" + and line.pms_property_id + and property_warehouse_id == po_warehouse_id + ): + res.update( + { + "location_dest_id": line.pms_property_id.stock_location_id.id, + } + ) + return res diff --git a/pms_purchase/models/stock_putaway_rule.py b/pms_purchase/models/stock_putaway_rule.py new file mode 100644 index 000000000..0b69f41e0 --- /dev/null +++ b/pms_purchase/models/stock_putaway_rule.py @@ -0,0 +1,13 @@ +# Copyright (c) 2022 Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo import api, models + + +class StockPutawayRule(models.Model): + _inherit = "stock.putaway.rule" + + @api.model + def _get_putaway_options(self): + res = super()._get_putaway_options() + res.append(("move_to_property", "Move to the location of the property")) + return res diff --git a/pms_purchase/readme/CONFIGURATION.rst b/pms_purchase/readme/CONFIGURATION.rst new file mode 100644 index 000000000..f284f38de --- /dev/null +++ b/pms_purchase/readme/CONFIGURATION.rst @@ -0,0 +1,12 @@ +Properties + +* Go to Properties > Master Data > Properties +* Create or select a property +* Go to the inventory tab +* Set the stock location + +Products + +* Go to Properties > Master Data > Products +* Create or select a product +* Set the putaway strategy to "Move to the location of the property" diff --git a/pms_purchase/readme/CONTRIBUTORS.rst b/pms_purchase/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..306ebdcc9 --- /dev/null +++ b/pms_purchase/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `Open Source Integrators `: + + * Maxime Chambreuil diff --git a/pms_purchase/readme/DESCRIPTION.rst b/pms_purchase/readme/DESCRIPTION.rst new file mode 100644 index 000000000..cbf403e88 --- /dev/null +++ b/pms_purchase/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module allows you to select a PMS property on the PO line. diff --git a/pms_purchase/readme/USAGE.rst b/pms_purchase/readme/USAGE.rst new file mode 100644 index 000000000..b5d892381 --- /dev/null +++ b/pms_purchase/readme/USAGE.rst @@ -0,0 +1,7 @@ +* Go to Purchase +* Create or select a request for quotation +* Set the warehouse to a building +* Select the property on the lines +* Confirm the request +* Open the receipt +* Transfer the receipt. The product is stored in the location of the property diff --git a/pms_purchase/static/description/icon.png b/pms_purchase/static/description/icon.png new file mode 100644 index 000000000..a81dd64c3 Binary files /dev/null and b/pms_purchase/static/description/icon.png differ diff --git a/pms_purchase/static/description/index.html b/pms_purchase/static/description/index.html new file mode 100644 index 000000000..e9d809813 --- /dev/null +++ b/pms_purchase/static/description/index.html @@ -0,0 +1,437 @@ + + + + + + +PMS - Purchase + + + +
+

PMS - Purchase

+ + +

Beta License: AGPL-3 OCA/pms Translate me on Weblate Try me on Runbot

+

This module allows you to select a PMS property on the PO line.

+

Table of contents

+ +
+

Usage

+
    +
  • Go to Purchase
  • +
  • Create or select a request for quotation
  • +
  • Set the warehouse to a building
  • +
  • Select the property on the lines
  • +
  • Confirm the request
  • +
  • Open the receipt
  • +
  • Transfer the receipt. The product is stored in the location of the property
  • +
+
+
+

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

+
    +
  • Open Source Integrators
  • +
+
+
+

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.

+

Current maintainer:

+

max3903

+

This module is part of the OCA/pms project on GitHub.

+

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

+
+
+
+ + diff --git a/pms_purchase/tests/__init__.py b/pms_purchase/tests/__init__.py new file mode 100644 index 000000000..01e78c1c6 --- /dev/null +++ b/pms_purchase/tests/__init__.py @@ -0,0 +1,3 @@ +from . import test_putaway_method +from . import test_purchase +from . import test_pms_property diff --git a/pms_purchase/tests/test_pms_property.py b/pms_purchase/tests/test_pms_property.py new file mode 100644 index 000000000..628d55061 --- /dev/null +++ b/pms_purchase/tests/test_pms_property.py @@ -0,0 +1,102 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + + +from odoo.tests import common + + +class TestPmsProperty(common.TransactionCase): + def setUp(self): + super(TestPmsProperty, self).setUp() + + # Get required Model + self.pms_property_model = self.env["pms.property"] + + def test_pms_property_generate(self): + partner_a = self.env["res.partner"].create( + { + "name": "test email 1", + "email": "test1@example.com", + } + ) + + pms_property_obj = self.env["pms.property"] + + warehouse = self.env["stock.warehouse"].search( + [("company_id", "=", self.env.company.id)], limit=1 + ) + + pms_property_vals = { + "name": "Test Pms Property-1", + "owner_id": partner_a.id, + "stock_location_id": self.env.ref("stock.stock_location_stock").id, + } + pms_property_record = pms_property_obj.create(pms_property_vals) + + PurchaseOrder = self.env["purchase.order"].with_context(tracking_disable=True) + company = self.env.user.company_id + + picking_type = self.env["stock.picking.type"].create( + { + "name": "new_picking_type", + "code": "outgoing", + "sequence_code": "NPT", + "default_location_src_id": self.env.ref( + "stock.stock_location_suppliers" + ).id, + "default_location_dest_id": self.env.ref( + "stock.stock_location_stock" + ).id, + "warehouse_id": warehouse.id, + } + ) + + vals = { + "partner_id": partner_a.id, + "company_id": company.id, + "currency_id": company.currency_id.id, + "picking_type_id": picking_type.id, + "date_order": "2019-01-01", + "order_line": [ + ( + 0, + 0, + { + "product_id": self.env.ref("product.product_delivery_01").id, + "pms_property_id": pms_property_record.id, + }, + ) + ], + } + purchase_order = PurchaseOrder.create(vals) + purchase_order.order_line._onchange_pms_property_id() + + pms_property_record._compute_po_line_count() + pms_property_record.action_open_po_line() + + self.env["stock.putaway.rule"].create( + { + "product_id": self.env.ref("product.product_delivery_02").id, + "location_in_id": self.env.ref("stock.stock_location_stock").id, + "method": "move_to_property", + "location_out_id": self.env.ref("stock.stock_location_suppliers").id, + } + ) + + purchase_order.write( + { + "order_line": [ + ( + 0, + 0, + { + "product_id": self.env.ref( + "product.product_delivery_02" + ).id, + "pms_property_id": pms_property_record.id, + }, + ) + ] + } + ) + pms_property_record.action_open_po_line() + purchase_order.button_confirm() diff --git a/pms_purchase/tests/test_purchase.py b/pms_purchase/tests/test_purchase.py new file mode 100644 index 000000000..2729b467d --- /dev/null +++ b/pms_purchase/tests/test_purchase.py @@ -0,0 +1,57 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + + +from odoo.tests import common + + +class TestPurchase(common.TransactionCase): + def test_purchase_order_generate(self): + PurchaseOrder = self.env["purchase.order"].with_context(tracking_disable=True) + + partner_a = self.env["res.partner"].create( + { + "name": "test email 1", + "email": "test1@example.com", + } + ) + + company = self.env.user.company_id + + self.env["ir.sequence"].search([("code", "=", "purchase.order")]).write( + { + "use_date_range": True, + "prefix": "PO/%(range_year)s/", + } + ) + + warehouse = self.env["stock.warehouse"].search( + [("company_id", "=", self.env.company.id)], limit=1 + ) + + location_1 = self.env["stock.location"].create( + {"name": "loc1", "location_id": warehouse.id} + ) + + picking_type = self.env["stock.picking.type"].create( + { + "name": "new_picking_type", + "code": "outgoing", + "sequence_code": "NPT", + "default_location_src_id": self.env.ref( + "stock.stock_location_stock" + ).id, + "default_location_dest_id": location_1.id, + "warehouse_id": warehouse.id, + } + ) + + vals = { + "partner_id": partner_a.id, + "company_id": company.id, + "currency_id": company.currency_id.id, + "picking_type_id": picking_type.id, + "date_order": "2019-01-01", + } + purchase_order = PurchaseOrder.create(vals.copy()) + self.assertTrue(purchase_order.name.startswith("PO/2019/")) + vals["date_order"] = "2020-01-01" diff --git a/pms_purchase/tests/test_putaway_method.py b/pms_purchase/tests/test_putaway_method.py new file mode 100644 index 000000000..d22aac4b8 --- /dev/null +++ b/pms_purchase/tests/test_putaway_method.py @@ -0,0 +1,12 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + + +from odoo.tests.common import TransactionCase + + +class TestPutawayMethod(TransactionCase): + + # Check if "fixed" is a valid putaway method + def test_02_putaway_methods(self): + field_method = self.env["stock.putaway.rule"]._fields.get("method") + self.assertIn("move_to_property", field_method.get_values(self.env)) diff --git a/pms_purchase/views/pms_property.xml b/pms_purchase/views/pms_property.xml new file mode 100644 index 000000000..cd228c2df --- /dev/null +++ b/pms_purchase/views/pms_property.xml @@ -0,0 +1,22 @@ + + + + pms.property.form.inherit.po.lines.view + pms.property + + + + + + + + + diff --git a/pms_purchase/views/purchase_order.xml b/pms_purchase/views/purchase_order.xml new file mode 100644 index 000000000..d58244d34 --- /dev/null +++ b/pms_purchase/views/purchase_order.xml @@ -0,0 +1,23 @@ + + + + purchase.order.form.view.inherit + purchase.order + + + + + + + + + + + + diff --git a/pms_purchase/views/stock_putaway_views.xml b/pms_purchase/views/stock_putaway_views.xml new file mode 100644 index 000000000..fe2cca6cf --- /dev/null +++ b/pms_purchase/views/stock_putaway_views.xml @@ -0,0 +1,21 @@ + + + + stock.putaway.rule.form.method + stock.putaway.rule + + + + {'invisible': [('method', 'not in', ['fixed','move_to_property'])]} + + + {'invisible': [('method', 'not in', ['fixed','move_to_property'])]} + + + + + diff --git a/setup/pms_purchase/odoo/addons/pms_purchase b/setup/pms_purchase/odoo/addons/pms_purchase new file mode 120000 index 000000000..24b7ea20f --- /dev/null +++ b/setup/pms_purchase/odoo/addons/pms_purchase @@ -0,0 +1 @@ +../../../../pms_purchase \ No newline at end of file diff --git a/setup/pms_purchase/setup.py b/setup/pms_purchase/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/pms_purchase/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)