Skip to content

Commit

Permalink
[IMP] warranty_configuration: wizard view and action updated
Browse files Browse the repository at this point in the history
Solved all error faced yesterday and completed wizard view properly.
Configured it such that it adding order line. updated views as well as Transient
models.
Added new field in sale order line model to assign functionality such that it
product get removed from order line than its warranty product also get removed.
Demo data added for warranty configuration
State button file path uncommented from estate_account solved error
occured for agent and manger group.
Image not displayed other than admin issue solved in website page of
properties.
  • Loading branch information
djip-odoo committed Dec 5, 2024
1 parent 4f7cd6c commit 0a3d337
Show file tree
Hide file tree
Showing 15 changed files with 144 additions and 75 deletions.
3 changes: 2 additions & 1 deletion estate/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ def list_active_properties(self, page=1):
("active", "=", True),
("state", "in", ["new", "offer_received"]),
],
fields=["name", "expected_price", "description"],
fields=["name", "expected_price", "description", "image"],
limit=limit,
offset=offset,
)
)

total_properties = (
request.env["estate.property"]
.sudo()
Expand Down
3 changes: 2 additions & 1 deletion estate/controllers/postreq.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ def submit_contact_form(self, **post):
cors="*",
)
def submit_contact_form_ext(self, **post):
print("post:", post)
# print("post:", post)
if not post:
try:
## request.httprequest.data is raw data format (binary data)
post = json.loads(request.httprequest.data.decode("utf-8"))
except Exception as e:
_logger.error(f"Fallback JSON Parsing Error: {e}")
Expand Down
21 changes: 15 additions & 6 deletions estate/views/website_properties_templates.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,20 @@
<div class="col-md-4 mb-4 d-flex">
<div class="card flex-fill">
<div class="card-body d-flex flex-column">
<img
t-att-src="'/web/image/estate.property/' + str(property.get('id')) + '/image'"
class="card-img-top"
style="height: 300px; width: 100%; object-fit: cover;"
alt="Property Image" />
<t t-if="property.get('image')">
<img
t-att-src="image_data_uri(property.get('image'))"
class="card-img-top"
style="height: 300px; width: 100%; object-fit: cover;"
alt="Property Image" />
</t>
<t t-else="">
<img
t-att-src="'/web/image/estate.property/' + str(property.get('id')) + '/image'"
class="card-img-top"
style="height: 300px; width: 100%; object-fit: cover;"
alt="Property Image" />
</t>
<h5 class="card-title">
<t t-esc="property.get('name')" />
</h5>
Expand Down Expand Up @@ -51,4 +60,4 @@
</div>
</t>
</template>
</odoo>
</odoo>
4 changes: 2 additions & 2 deletions estate_account/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"data": [
"report/estate_estate_property_templates.xml",
"security/ir.model.access.csv",
# "views/actions_smart_button.xml",
# "views/estate_property_views.xml",
"views/actions_smart_button.xml",
"views/estate_property_views.xml",
],
"demo": [
"demo/demo_invoice_data_property.xml",
Expand Down
1 change: 1 addition & 0 deletions estate_account/views/estate_property_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
icon="fa-bars"
string="offers"
invisible="invoice_count == 0"
groups="base.group_system"
>
<div class="o_stat_info">
<span class="o_stat_value">
Expand Down
8 changes: 6 additions & 2 deletions warranty_configuration/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Warranty Configuration",
"version": "1.0",
"depends": ["base", "sale_management", "stock"],
"depends": ["base", "sale_management", "spreadsheet"],
"author": "djip-odoo",
"description": """
Part of technical training
Expand All @@ -13,7 +13,11 @@
"views/sales_management_menu.xml",
"views/warranty_configuration_views.xml",
"views/product_views.xml",
"views/so_add_warranty_button_view.xml",
"views/sale_order_views.xml",
],
'demo':[
'demo/product_demo.xml',
'demo/warranty_configuration_demo.xml',
],
"installable": True,
"application": False,
Expand Down
29 changes: 29 additions & 0 deletions warranty_configuration/demo/product_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<record id="product_warranty_basic" model="product.product">
<field name="name">Basic Warranty Service</field>
<field name="type">service</field>
<field name="default_code">WARRANTY_BASIC</field>
<field name="list_price">50.0</field>
<field name="standard_price">30.0</field>
<field name="categ_id" ref="product.product_category_1" />
</record>

<record id="product_warranty_premium" model="product.product">
<field name="name">Premium Warranty Service</field>
<field name="type">service</field>
<field name="default_code">WARRANTY_PREMIUM</field>
<field name="list_price">100.0</field>
<field name="standard_price">70.0</field>
<field name="categ_id" ref="product.product_category_1" />
</record>

<record id="product_warranty_extended" model="product.product">
<field name="name">Extended Warranty Service</field>
<field name="type">service</field>
<field name="default_code">WARRANTY_EXTENDED</field>
<field name="list_price">150.0</field>
<field name="standard_price">100.0</field>
<field name="categ_id" ref="product.product_category_1" />
</record>
</odoo>
23 changes: 23 additions & 0 deletions warranty_configuration/demo/warranty_configuration_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<record id="warranty_configuration_product1" model="warranty.configuration">
<field name="name">Warranty - 1 year</field>
<field name="product_id" ref="warranty_configuration.product_warranty_basic" />
<field name="year">1</field>
<field name="percentage">10.0</field>
</record>

<record id="warranty_configuration_product2" model="warranty.configuration">
<field name="name">Warranty - 2 year</field>
<field name="product_id" ref="warranty_configuration.product_warranty_premium" />
<field name="year">2</field>
<field name="percentage">15.0</field>
</record>

<record id="warranty_configuration_product3" model="warranty.configuration">
<field name="name">Warranty - 3 year</field>
<field name="product_id" ref="warranty_configuration.product_warranty_extended" />
<field name="year">3</field>
<field name="percentage">20.0</field>
</record>
</odoo>
1 change: 0 additions & 1 deletion warranty_configuration/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from . import warranty_configuration
from . import product_template
from . import sale_order
from . import sale_order_line
7 changes: 0 additions & 7 deletions warranty_configuration/models/sale_order.py

This file was deleted.

13 changes: 9 additions & 4 deletions warranty_configuration/models/sale_order_line.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
from odoo import models,api,fields
from odoo import models, fields, api


class SaleOrderLine(models.Model):
_inherit = "sale.order.line"
_inherit = "sale.order.line"

# warranty_id =

parent_sale_order_line_id = fields.Many2one(
comodel_name="sale.order.line",
readonly=True,
ondelete="cascade",
string="parent sale order line id",
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<odoo>
<record id="view_order_form_inherited_for_add_warranty_button" model="ir.ui.view">
<record id="view_so_form_inherited_for_add_warranty_button" model="ir.ui.view">
<field name="name">sale.order.form.add.warranty</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form" />
Expand Down
30 changes: 19 additions & 11 deletions warranty_configuration/wizards/add_warranty_line_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,32 @@ class AddWarrantyLineWizard(models.TransientModel):
_name = "add.warranty.line.wizard"
_description = "Temporary line model for warranty in wizard"

wizard_id = fields.Many2one(
warranty_id = fields.Many2one(
"add.warranty.wizard",
string="Wizard Reference",
readonly=True,
required=True,
ondelete='cascade',
)

sale_order_line_id = fields.Many2one(
"sale.order.line",
string="SaleOrderLine",
)

product_id = fields.Many2one(
"product.product",
string="Product",
readonly=True,
ondelete='cascade',
"product.template", compute="_compute_product_name", string="Product"
)

warranty_config_id = fields.Many2one("warranty.configuration", string="Year")
end_date = fields.Date(string="End Date", compute="_compute_end_date", store=True)


end_date = fields.Date(string="End Date", compute="_compute_end_date")

@api.depends("sale_order_line_id")
def _compute_product_name(self):
for record in self:
if record.sale_order_line_id:
record.product_id = record.sale_order_line_id.product_template_id
else:
record.product_id = False

@api.depends("warranty_config_id")
def _compute_end_date(self):
today = date.today()
Expand All @@ -33,5 +42,4 @@ def _compute_end_date(self):
years=int(record.warranty_config_id.year)
)
else:
record.product_id = record.product_id
record.end_date = False
73 changes: 34 additions & 39 deletions warranty_configuration/wizards/add_warranty_wizard.py
Original file line number Diff line number Diff line change
@@ -1,59 +1,54 @@
from odoo import models, fields, api, Command
from odoo import models, fields, api


class AddWarrantyWizard(models.TransientModel):
_name = "add.warranty.wizard"
_description = "Wizard to Add Warranty"

order_id = fields.Many2one("sale.order", string="Sale Order")
product_ids = fields.Many2many("product.product")

warranty_lines_ids = fields.One2many(
comodel_name="add.warranty.line.wizard",
inverse_name="wizard_id",
store=True,
inverse_name="warranty_id",
string="Warranty Lines",
)

def action_add_warranty(self):
print("-*- " * 100)

new_order_line_list = []
# Iterate through the warranty lines in the wizard
for record in self:
print(record.order_id)
warranty_product_ids = record.warranty_lines_ids.mapped("product_id.id")
print("Warranty product IDs:", warranty_product_ids)

# # Iterate over order lines to find matching products
# for ol in record.order_id.order_line:
# new_order_line_list.append(ol)
# print(
# f"Checking Order Line Product: {ol.product_id.id} in Warranty Lines"
# )

# if ol.product_id.id in warranty_product_ids:
# print(f"Match found: {ol}")

print(new_order_line_list)
print("hello from warranty !")
print("-*- " * 100)

return new_order_line_list

@api.model
def default_get(self, fields):
res = super(AddWarrantyWizard, self).default_get(fields)
order_id = self.env.context.get("active_id")
sale_order = self.env["sale.order"].browse(order_id)

warranty_products = sale_order.order_line.mapped("product_id").filtered(
lambda p: p.warranty
)
sale_order = self.env["sale.order"].browse(order_id)

warranty_line_vals = []
for product in warranty_products:
warranty_line_vals.append(Command.create({"product_id": product.id}))
print(warranty_products)
res["product_ids"] = [Command.set(warranty_products)]
res["warranty_lines_ids"] = [
[
0,
0,
{
"sale_order_line_id": line.id,
},
]
for line in sale_order.order_line.filtered(
lambda x: x.product_template_id.warranty
)
]
res["order_id"] = order_id

return res

def action_add_warranty(self):
new_order_line_list = [
{
"order_id": line.sale_order_line_id.order_id.id,
"name": str(line.warranty_config_id.name) + "/" + str(line.end_date),
"price_unit": line.sale_order_line_id.price_subtotal
* (line.warranty_config_id.percentage / 100),
"product_id": line.warranty_config_id.product_id.id,
"parent_sale_order_line_id": line.sale_order_line_id.id,
"sequence": line.sale_order_line_id.sequence,
}
for line in self.warranty_lines_ids.filtered(
lambda x: x.warranty_config_id.name
)
]
self.env["sale.order.line"].create(new_order_line_list)
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<sheet>
<field name="warranty_lines_ids">
<list create="false" no_open="1" editable="top" >
<field name="sale_order_line_id" optional="hide" />
<field name="product_id" readonly="1" />
<field name="warranty_config_id" />
<field name="end_date" readonly="1" />
Expand Down

0 comments on commit 0a3d337

Please sign in to comment.