Skip to content

Commit

Permalink
[FIX] Fixed commented code
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikul-OSI committed Aug 21, 2024
1 parent 530e79e commit 6526638
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 47 deletions.
35 changes: 22 additions & 13 deletions sale_product_approval/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 8 additions & 9 deletions sale_product_approval/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand All @@ -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,
Expand Down
33 changes: 13 additions & 20 deletions sale_product_approval/tests/test_product_approval.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,37 @@
# 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,
},
)
],
}
)
return sale

def test_write_product_state(self):
self.product_id.write({"product_state_id": self.product_state_sale.id})
Expand Down
9 changes: 4 additions & 5 deletions sale_product_approval/views/sale_order.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<odoo>

<record id="sale_order_line_inherit_form" model="ir.ui.view">
<field name="name">sale_order_line_form_view_inherit</field>
<record id="sale_order_inherit_form" model="ir.ui.view">
<field name="name">sale_order_form_view_inherit</field>
<field name="model">sale.order</field>
<field name="priority">99</field>
<field name="inherit_id" ref="sale.view_order_form" />
Expand All @@ -25,14 +25,13 @@
role="alert"
>Exception: A product on this sale order has been marked as not saleable.</div>
</div>
<field name="tag_ids" position="after">
<field name="client_order_ref" position="after">
<field
name="override_exception"
groups="sales_team.group_sale_manager"
/>
</field>
<button id="action_confirm" position="replace">
</button>
<button id="action_confirm" position="replace" />
<button name="action_confirm" position="attributes">
<attribute name="context">{'override_ex': True}</attribute>
</button>
Expand Down

0 comments on commit 6526638

Please sign in to comment.