-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[14.0][ADD] sale_production_state #2459
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
35935ad
[14][ADD] module sale_production_state to display production state on…
bguillot 15e5cdc
move production - sale link to mrp_sale_info module
bguillot 4ff85d7
add readme
bguillot 078c85c
add index
bguillot a1281e7
sale_production_state: hide by default the field production_state
sebastienbeau 5b1f1dd
fix lint
bguillot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| from . import models | ||
| from . import tests |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # Copyright 2021 Akretion (http://www.akretion.com). | ||
| # @author Benoît GUILLOT <benoit.guillot@akretion.com> | ||
| # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
|
||
| { | ||
| "name": "Sale production State", | ||
| "summary": "Show the production state on the sale order", | ||
| "version": "14.0.1.0.0", | ||
| "category": "Product", | ||
| "website": "https://github.com/OCA/sale-workflow", | ||
| "author": "Akretion, Odoo Community Association (OCA)", | ||
| "license": "AGPL-3", | ||
| "installable": True, | ||
| "depends": ["mrp_sale_info"], | ||
| "data": [ | ||
| "views/sale_order.xml", | ||
| ], | ||
| "demo": [], | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| from . import sale_order | ||
| from . import sale_order_line |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # Copyright 2021 Akretion (http://www.akretion.com). | ||
| # @author Benoît GUILLOT <benoit.guillot@akretion.com> | ||
| # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
|
||
| from odoo import api, fields, models | ||
|
|
||
|
|
||
| class SaleOrder(models.Model): | ||
| _inherit = "sale.order" | ||
|
|
||
| production_state = fields.Selection( | ||
| selection=[ | ||
| ("no", "No manufacturing"), | ||
| ("unprocessed", "Unprocessed"), | ||
| ("partially", "Partially processed"), | ||
| ("done", "Done"), | ||
| ], | ||
| string="Manufacturing state", | ||
| compute="_compute_production_state", | ||
| store=True, | ||
| index=True, | ||
| ) | ||
|
|
||
| @api.depends("order_line.production_state") | ||
| def _compute_production_state(self): | ||
| for order in self: | ||
| production_states = [x.production_state for x in order.order_line] | ||
| if all(x == "no" for x in production_states): | ||
| order.production_state = "no" | ||
| elif all(x in ["done", "no"] for x in production_states): | ||
| order.production_state = "done" | ||
| elif all(x in ["unprocessed", "no"] for x in production_states): | ||
| order.production_state = "unprocessed" | ||
| else: | ||
| order.production_state = "partially" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # Copyright 2021 Akretion (http://www.akretion.com). | ||
| # @author Benoît GUILLOT <benoit.guillot@akretion.com> | ||
| # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
|
||
| from odoo import api, fields, models | ||
|
|
||
|
|
||
| class SaleOrderLine(models.Model): | ||
| _inherit = "sale.order.line" | ||
|
|
||
| production_state = fields.Selection( | ||
| selection=[ | ||
| ("no", "No manufacturing"), | ||
| ("unprocessed", "Unprocessed"), | ||
| ("partially", "Partially processed"), | ||
| ("done", "Done"), | ||
| ], | ||
| string="Manufacturing state", | ||
| compute="_compute_production_state", | ||
| store=True, | ||
|
sebastienbeau marked this conversation as resolved.
|
||
| index=True, | ||
| ) | ||
|
|
||
| @api.depends("production_ids", "production_ids.state") | ||
| def _compute_production_state(self): | ||
| for line in self: | ||
| if not line.production_ids: | ||
| line.production_state = "no" | ||
| elif all(x.state in ["done", "cancel"] for x in line.production_ids): | ||
| line.production_state = "done" | ||
| elif any(x.state == "done" for x in line.production_ids): | ||
| line.production_state = "partially" | ||
| else: | ||
| line.production_state = "unprocessed" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| * Benoît Guillot <benoit.guillot@akretion.com> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| This module adds production state on the sale order. | ||
|
|
||
| It is computed from the state of the manufactruring orders related to the sale order. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from . import test_production_state |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| # Copyright 2018 Akretion (http://www.akretion.com). | ||
| # @author Benoît GUILLOT <benoit.guillot@akretion.com> | ||
| # Copyright 2018 Camptocamp | ||
| # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
|
||
| from odoo.tests import Form, SavepointCase | ||
|
|
||
|
|
||
| class TestSaleProductionState(SavepointCase): | ||
| @classmethod | ||
| def setUpClass(cls): | ||
| super().setUpClass() | ||
| route_manufacture_1 = cls.env.ref("mrp.route_warehouse0_manufacture") | ||
| route_manufacture_2 = cls.env.ref("stock.route_warehouse0_mto") | ||
| route_manufacture_2.active = True | ||
| cls.product_1 = cls.env["product.product"].create( | ||
| { | ||
| "name": "Test sale production state product 1", | ||
| "type": "product", | ||
| "route_ids": [ | ||
| (4, route_manufacture_1.id), | ||
| (4, route_manufacture_2.id), | ||
| ], | ||
| } | ||
| ) | ||
| cls.product = cls.env["product.product"].create( | ||
| { | ||
| "name": "Test sale production state product", | ||
| "type": "product", | ||
| } | ||
| ) | ||
| cls.bom_1 = cls.env["mrp.bom"].create( | ||
| { | ||
| "product_tmpl_id": cls.product_1.product_tmpl_id.id, | ||
| } | ||
| ) | ||
| cls.env["mrp.bom.line"].create( | ||
| {"bom_id": cls.bom_1.id, "product_id": cls.product.id, "product_qty": 1} | ||
| ) | ||
| cls.product_2 = cls.env["product.product"].create( | ||
| { | ||
| "name": "Test sale production state product 2", | ||
| "type": "product", | ||
| "route_ids": [ | ||
| (4, route_manufacture_1.id), | ||
| (4, route_manufacture_2.id), | ||
| ], | ||
| } | ||
| ) | ||
| cls.bom_2 = cls.env["mrp.bom"].create( | ||
| { | ||
| "product_tmpl_id": cls.product_2.product_tmpl_id.id, | ||
| } | ||
| ) | ||
| cls.env["mrp.bom.line"].create( | ||
| {"bom_id": cls.bom_2.id, "product_id": cls.product.id, "product_qty": 1} | ||
| ) | ||
| cls.partner = cls.env["res.partner"].create({"name": "Test client"}) | ||
| cls.order = cls.env["sale.order"].create( | ||
| { | ||
| "partner_id": cls.partner.id, | ||
| "client_order_ref": "SO1", | ||
| "order_line": [ | ||
| ( | ||
| 0, | ||
| 0, | ||
| { | ||
| "product_id": cls.product_1.id, | ||
| "product_uom_qty": 1, | ||
| "price_unit": 1, | ||
| }, | ||
| ), | ||
| ( | ||
| 0, | ||
| 0, | ||
| { | ||
| "product_id": cls.product_2.id, | ||
| "product_uom_qty": 1, | ||
| "price_unit": 1, | ||
| }, | ||
| ), | ||
| ], | ||
| } | ||
| ) | ||
|
|
||
| def test_no_production(self): | ||
| self.assertEqual(self.order.order_line[0].production_state, "no") | ||
| self.assertEqual(self.order.production_state, "no") | ||
|
|
||
| def test_unprocessed_production(self): | ||
| self.order.action_confirm() | ||
| self.assertEqual(self.order.order_line[0].production_state, "unprocessed") | ||
| self.assertEqual(self.order.production_state, "unprocessed") | ||
| self.assertTrue(self.order.order_line[0].production_ids) | ||
|
|
||
| def test_partially(self): | ||
| self.order.action_confirm() | ||
| mrp = self.order.order_line[0].production_ids | ||
| mrp.action_confirm() | ||
| mo_form = Form(mrp) | ||
| mo_form.qty_producing = 1 | ||
| mrp = mo_form.save() | ||
| mrp.button_mark_done() | ||
| self.assertEqual(self.order.order_line[0].production_state, "done") | ||
| self.assertEqual(self.order.production_state, "partially") | ||
|
|
||
| def test_production_done(self): | ||
| self.order.action_confirm() | ||
| for line in self.order.order_line: | ||
| mrp = line.production_ids | ||
| mrp.action_confirm() | ||
| mo_form = Form(mrp) | ||
| mo_form.qty_producing = 1 | ||
| mrp = mo_form.save() | ||
| mrp.button_mark_done() | ||
| self.assertEqual(self.order.production_state, "done") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| <?xml version="1.0" encoding="UTF-8" ?> | ||
| <odoo> | ||
| <record id="view_order_form_inherit_production_state" model="ir.ui.view"> | ||
| <field name="name">sale.order.form.sale.stock</field> | ||
| <field name="model">sale.order</field> | ||
| <field name="inherit_id" ref="sale.view_order_form" /> | ||
| <field name="arch" type="xml"> | ||
| <field name='date_order' position="after"> | ||
| <field name="production_state" readonly="True" /> | ||
| </field> | ||
| </field> | ||
| </record> | ||
|
|
||
| <record id="view_order_tree_inherit_production_state" model="ir.ui.view"> | ||
| <field name="name">sale.order.tree</field> | ||
| <field name="inherit_id" ref="sale.view_order_tree" /> | ||
| <field name="model">sale.order</field> | ||
| <field name="arch" type="xml"> | ||
| <field name="invoice_status" position="after"> | ||
| <field name="production_state" optional="hide" /> | ||
| </field> | ||
| </field> | ||
| </record> | ||
| </odoo> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../../sale_production_state |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, | ||
| ) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.