From 02cba94015bb2274c0c29ba16d59480a87abe3e9 Mon Sep 17 00:00:00 2001 From: Nikul-OSI Date: Wed, 21 Aug 2024 14:42:52 +0530 Subject: [PATCH] [FIX] Fixed commented code --- .../models/product_product.py | 35 ++++++++++++------- sale_product_approval/models/sale_order.py | 17 +++++---- .../tests/test_product_approval.py | 33 +++++++---------- sale_product_approval/views/sale_order.xml | 7 ++-- 4 files changed, 46 insertions(+), 46 deletions(-) diff --git a/sale_product_approval/models/product_product.py b/sale_product_approval/models/product_product.py index f4955ab05fbb..48cb08c4c3a5 100644 --- a/sale_product_approval/models/product_product.py +++ b/sale_product_approval/models/product_product.py @@ -22,26 +22,35 @@ class ProductTemplate(models.Model): ) candidate_sale_confirm = fields.Boolean( string="Candidate to be Sold", + compute="_compute_candidate_sale_confirm", + store=True, + readonly=False, ) can_edit_candidate = fields.Boolean(compute="_compute_can_edit_candidate") def _compute_can_edit_candidate(self): - for product in self: - product.can_edit_candidate = self.env.user.has_group( - "sale_product_approval.group_product_administrator" - ) + self.update( + { + "can_edit_candidate": self.env.user.has_group( + "sale_product_approval.group_product_administrator" + ) + } + ) - @api.onchange("candidate_sale_confirm") - def _onchange_candidate_sale_confirm(self): + @api.depends("candidate_sale_confirm") + def _compute_candidate_sale_confirm(self): for product in self: - if product.candidate_sale_confirm and not product.candidate_sale: - product.candidate_sale = True + product.candidate_sale = ( + True + if product.candidate_sale_confirm and not product.candidate_sale + else False + ) - @api.model - def create(self, vals): - new = super().create(vals) - new._set_sale_ok_product() - return new + @api.model_create_multi + def create(self, vals_list): + templates = super().create(vals_list) + templates._set_sale_ok_product() + return templates def write(self, vals): res = super().write(vals) diff --git a/sale_product_approval/models/sale_order.py b/sale_product_approval/models/sale_order.py index 22e7a8887f27..5b8ab781580e 100644 --- a/sale_product_approval/models/sale_order.py +++ b/sale_product_approval/models/sale_order.py @@ -1,8 +1,5 @@ # Copyright 2021 Open Source Integrators # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). - -from datetime import date - from odoo import SUPERUSER_ID, _, api, fields, models from odoo.exceptions import UserError @@ -11,12 +8,14 @@ class SaleOrder(models.Model): _inherit = "sale.order" exceptions_sale_approval_confirm = fields.Boolean( - compute="_compute_exceptions", string="Exception", default=False + compute="_compute_exceptions_sale_approval_confirm", + string="Exception", + default=False, ) - override_exception = fields.Boolean(default=False) + override_exception = fields.Boolean() @api.depends("order_line.approved_sale_confirm") - def _compute_exceptions(self): + def _compute_exceptions_sale_approval_confirm(self): for so in self: so.exceptions_sale_approval_confirm = any( not line.approved_sale_confirm @@ -25,15 +24,15 @@ def _compute_exceptions(self): def _log_exception_activity_sale(self, product_id): for order in self: - note = self._render_product_state_excep(order, product_id) + note = self._render_product_approval_exception(order, product_id) order.activity_schedule( "mail.mail_activity_data_warning", - date.today(), + fields.Date.today(), note=note, user_id=order.user_id.id or SUPERUSER_ID, ) - def _render_product_state_excep(self, order, product_id): + def _render_product_approval_exception(self, order, product_id): values = {"sale_order_ref": order, "product_ref": product_id} return self.env["ir.ui.view"]._render_template( template=self.env.ref("sale_product_approval.exception_on_product").id, diff --git a/sale_product_approval/tests/test_product_approval.py b/sale_product_approval/tests/test_product_approval.py index 08903b38a133..8159d7dd95c7 100644 --- a/sale_product_approval/tests/test_product_approval.py +++ b/sale_product_approval/tests/test_product_approval.py @@ -1,36 +1,30 @@ # Copyright 2021 Open Source Integrators # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). - - from odoo.exceptions import UserError +from odoo.tests import tagged from odoo.tests.common import TransactionCase -class TestSaleOrderLineDates(TransactionCase): - def setUp(self): - super().setUp() - self.customer = self.env.ref("base.res_partner_12") - self.product_id = self.test_create_product_template() - self.sale_id = self.test_sale_order() - self.product_state_sale = self.env.ref("product_state.product_state_sellable") - self.product_state_end = self.env.ref("product_state.product_state_end") - - def test_create_product_template(self): - product = self.env["product.product"].create( +@tagged("post_install", "-at_install") +class TestSaleProductApproval(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.customer = cls.env.ref("base.res_partner_12") + cls.product_state_sale = cls.env.ref("product_state.product_state_sellable") + cls.product_state_end = cls.env.ref("product_state.product_state_end") + cls.product_id = cls.env["product.product"].create( {"name": "Test Product", "type": "product"} ) - return product - - def test_sale_order(self): - sale = self.env["sale.order"].create( + cls.sale_id = cls.env["sale.order"].create( { - "partner_id": self.customer.id, + "partner_id": cls.customer.id, "order_line": [ ( 0, 0, { - "product_id": self.product_id.id, + "product_id": cls.product_id.id, "product_uom_qty": 2.0, "price_unit": 10.0, }, @@ -38,7 +32,6 @@ def test_sale_order(self): ], } ) - return sale def test_write_product_state(self): self.product_id.write({"product_state_id": self.product_state_sale.id}) diff --git a/sale_product_approval/views/sale_order.xml b/sale_product_approval/views/sale_order.xml index dc8db0396764..c90289dd61c2 100644 --- a/sale_product_approval/views/sale_order.xml +++ b/sale_product_approval/views/sale_order.xml @@ -25,14 +25,13 @@ role="alert" >Exception: A product on this sale order has been marked as not saleable. - + - - + +