Skip to content

Commit 546644a

Browse files
committed
[IMP] warranty_configuration: wizard view and action updated
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.
1 parent 6058b9a commit 546644a

15 files changed

+144
-75
lines changed

estate/controllers/main.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ def list_active_properties(self, page=1):
1717
("active", "=", True),
1818
("state", "in", ["new", "offer_received"]),
1919
],
20-
fields=["name", "expected_price", "description"],
20+
fields=["name", "expected_price", "description", "image"],
2121
limit=limit,
2222
offset=offset,
2323
)
2424
)
25+
2526
total_properties = (
2627
request.env["estate.property"]
2728
.sudo()

estate/controllers/postreq.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ def submit_contact_form(self, **post):
3535
cors="*",
3636
)
3737
def submit_contact_form_ext(self, **post):
38-
print("post:", post)
38+
# print("post:", post)
3939
if not post:
4040
try:
41+
## request.httprequest.data is raw data format (binary data)
4142
post = json.loads(request.httprequest.data.decode("utf-8"))
4243
except Exception as e:
4344
_logger.error(f"Fallback JSON Parsing Error: {e}")

estate/views/website_properties_templates.xml

+15-6
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,20 @@
88
<div class="col-md-4 mb-4 d-flex">
99
<div class="card flex-fill">
1010
<div class="card-body d-flex flex-column">
11-
<img
12-
t-att-src="'/web/image/estate.property/' + str(property.get('id')) + '/image'"
13-
class="card-img-top"
14-
style="height: 300px; width: 100%; object-fit: cover;"
15-
alt="Property Image" />
11+
<t t-if="property.get('image')">
12+
<img
13+
t-att-src="image_data_uri(property.get('image'))"
14+
class="card-img-top"
15+
style="height: 300px; width: 100%; object-fit: cover;"
16+
alt="Property Image" />
17+
</t>
18+
<t t-else="">
19+
<img
20+
t-att-src="'/web/image/estate.property/' + str(property.get('id')) + '/image'"
21+
class="card-img-top"
22+
style="height: 300px; width: 100%; object-fit: cover;"
23+
alt="Property Image" />
24+
</t>
1625
<h5 class="card-title">
1726
<t t-esc="property.get('name')" />
1827
</h5>
@@ -51,4 +60,4 @@
5160
</div>
5261
</t>
5362
</template>
54-
</odoo>
63+
</odoo>

estate_account/__manifest__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
"data": [
1010
"report/estate_estate_property_templates.xml",
1111
"security/ir.model.access.csv",
12-
# "views/actions_smart_button.xml",
13-
# "views/estate_property_views.xml",
12+
"views/actions_smart_button.xml",
13+
"views/estate_property_views.xml",
1414
],
1515
"demo": [
1616
"demo/demo_invoice_data_property.xml",

estate_account/views/estate_property_views.xml

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
icon="fa-bars"
1313
string="offers"
1414
invisible="invoice_count == 0"
15+
groups="base.group_system"
1516
>
1617
<div class="o_stat_info">
1718
<span class="o_stat_value">

warranty_configuration/__manifest__.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "Warranty Configuration",
33
"version": "1.0",
4-
"depends": ["base", "sale_management", "stock"],
4+
"depends": ["base", "sale_management", "spreadsheet"],
55
"author": "djip-odoo",
66
"description": """
77
Part of technical training
@@ -13,7 +13,11 @@
1313
"views/sales_management_menu.xml",
1414
"views/warranty_configuration_views.xml",
1515
"views/product_views.xml",
16-
"views/so_add_warranty_button_view.xml",
16+
"views/sale_order_views.xml",
17+
],
18+
'demo':[
19+
'demo/product_demo.xml',
20+
'demo/warranty_configuration_demo.xml',
1721
],
1822
"installable": True,
1923
"application": False,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<odoo>
3+
<record id="product_warranty_basic" model="product.product">
4+
<field name="name">Basic Warranty Service</field>
5+
<field name="type">service</field>
6+
<field name="default_code">WARRANTY_BASIC</field>
7+
<field name="list_price">50.0</field>
8+
<field name="standard_price">30.0</field>
9+
<field name="categ_id" ref="product.product_category_1" />
10+
</record>
11+
12+
<record id="product_warranty_premium" model="product.product">
13+
<field name="name">Premium Warranty Service</field>
14+
<field name="type">service</field>
15+
<field name="default_code">WARRANTY_PREMIUM</field>
16+
<field name="list_price">100.0</field>
17+
<field name="standard_price">70.0</field>
18+
<field name="categ_id" ref="product.product_category_1" />
19+
</record>
20+
21+
<record id="product_warranty_extended" model="product.product">
22+
<field name="name">Extended Warranty Service</field>
23+
<field name="type">service</field>
24+
<field name="default_code">WARRANTY_EXTENDED</field>
25+
<field name="list_price">150.0</field>
26+
<field name="standard_price">100.0</field>
27+
<field name="categ_id" ref="product.product_category_1" />
28+
</record>
29+
</odoo>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<odoo>
3+
<record id="warranty_configuration_product1" model="warranty.configuration">
4+
<field name="name">Warranty - 1 year</field>
5+
<field name="product_id" ref="warranty_configuration.product_warranty_basic" />
6+
<field name="year">1</field>
7+
<field name="percentage">10.0</field>
8+
</record>
9+
10+
<record id="warranty_configuration_product2" model="warranty.configuration">
11+
<field name="name">Warranty - 2 year</field>
12+
<field name="product_id" ref="warranty_configuration.product_warranty_premium" />
13+
<field name="year">2</field>
14+
<field name="percentage">15.0</field>
15+
</record>
16+
17+
<record id="warranty_configuration_product3" model="warranty.configuration">
18+
<field name="name">Warranty - 3 year</field>
19+
<field name="product_id" ref="warranty_configuration.product_warranty_extended" />
20+
<field name="year">3</field>
21+
<field name="percentage">20.0</field>
22+
</record>
23+
</odoo>
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
from . import warranty_configuration
22
from . import product_template
3-
from . import sale_order
43
from . import sale_order_line

warranty_configuration/models/sale_order.py

-7
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
from odoo import models,api,fields
1+
from odoo import models, fields, api
2+
23

34
class SaleOrderLine(models.Model):
4-
_inherit = "sale.order.line"
5+
_inherit = "sale.order.line"
56

6-
# warranty_id =
7-
7+
parent_sale_order_line_id = fields.Many2one(
8+
comodel_name="sale.order.line",
9+
readonly=True,
10+
ondelete="cascade",
11+
string="parent sale order line id",
12+
)

warranty_configuration/views/so_add_warranty_button_view.xml warranty_configuration/views/sale_order_views.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<odoo>
2-
<record id="view_order_form_inherited_for_add_warranty_button" model="ir.ui.view">
2+
<record id="view_so_form_inherited_for_add_warranty_button" model="ir.ui.view">
33
<field name="name">sale.order.form.add.warranty</field>
44
<field name="model">sale.order</field>
55
<field name="inherit_id" ref="sale.view_order_form" />

warranty_configuration/wizards/add_warranty_line_wizard.py

+19-11
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,32 @@ class AddWarrantyLineWizard(models.TransientModel):
77
_name = "add.warranty.line.wizard"
88
_description = "Temporary line model for warranty in wizard"
99

10-
wizard_id = fields.Many2one(
10+
warranty_id = fields.Many2one(
1111
"add.warranty.wizard",
1212
string="Wizard Reference",
13-
readonly=True,
14-
required=True,
15-
ondelete='cascade',
13+
)
14+
15+
sale_order_line_id = fields.Many2one(
16+
"sale.order.line",
17+
string="SaleOrderLine",
1618
)
1719

1820
product_id = fields.Many2one(
19-
"product.product",
20-
string="Product",
21-
readonly=True,
22-
ondelete='cascade',
21+
"product.template", compute="_compute_product_name", string="Product"
2322
)
23+
2424
warranty_config_id = fields.Many2one("warranty.configuration", string="Year")
25-
end_date = fields.Date(string="End Date", compute="_compute_end_date", store=True)
26-
25+
26+
end_date = fields.Date(string="End Date", compute="_compute_end_date")
27+
28+
@api.depends("sale_order_line_id")
29+
def _compute_product_name(self):
30+
for record in self:
31+
if record.sale_order_line_id:
32+
record.product_id = record.sale_order_line_id.product_template_id
33+
else:
34+
record.product_id = False
35+
2736
@api.depends("warranty_config_id")
2837
def _compute_end_date(self):
2938
today = date.today()
@@ -33,5 +42,4 @@ def _compute_end_date(self):
3342
years=int(record.warranty_config_id.year)
3443
)
3544
else:
36-
record.product_id = record.product_id
3745
record.end_date = False
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,54 @@
1-
from odoo import models, fields, api, Command
1+
from odoo import models, fields, api
22

33

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

88
order_id = fields.Many2one("sale.order", string="Sale Order")
9-
product_ids = fields.Many2many("product.product")
9+
1010
warranty_lines_ids = fields.One2many(
1111
comodel_name="add.warranty.line.wizard",
12-
inverse_name="wizard_id",
13-
store=True,
12+
inverse_name="warranty_id",
1413
string="Warranty Lines",
1514
)
1615

17-
def action_add_warranty(self):
18-
print("-*- " * 100)
19-
20-
new_order_line_list = []
21-
# Iterate through the warranty lines in the wizard
22-
for record in self:
23-
print(record.order_id)
24-
warranty_product_ids = record.warranty_lines_ids.mapped("product_id.id")
25-
print("Warranty product IDs:", warranty_product_ids)
26-
27-
# # Iterate over order lines to find matching products
28-
# for ol in record.order_id.order_line:
29-
# new_order_line_list.append(ol)
30-
# print(
31-
# f"Checking Order Line Product: {ol.product_id.id} in Warranty Lines"
32-
# )
33-
34-
# if ol.product_id.id in warranty_product_ids:
35-
# print(f"Match found: {ol}")
36-
37-
print(new_order_line_list)
38-
print("hello from warranty !")
39-
print("-*- " * 100)
40-
41-
return new_order_line_list
42-
4316
@api.model
4417
def default_get(self, fields):
4518
res = super(AddWarrantyWizard, self).default_get(fields)
4619
order_id = self.env.context.get("active_id")
47-
sale_order = self.env["sale.order"].browse(order_id)
4820

49-
warranty_products = sale_order.order_line.mapped("product_id").filtered(
50-
lambda p: p.warranty
51-
)
21+
sale_order = self.env["sale.order"].browse(order_id)
5222

53-
warranty_line_vals = []
54-
for product in warranty_products:
55-
warranty_line_vals.append(Command.create({"product_id": product.id}))
56-
print(warranty_products)
57-
res["product_ids"] = [Command.set(warranty_products)]
23+
res["warranty_lines_ids"] = [
24+
[
25+
0,
26+
0,
27+
{
28+
"sale_order_line_id": line.id,
29+
},
30+
]
31+
for line in sale_order.order_line.filtered(
32+
lambda x: x.product_template_id.warranty
33+
)
34+
]
35+
res["order_id"] = order_id
5836

5937
return res
38+
39+
def action_add_warranty(self):
40+
new_order_line_list = [
41+
{
42+
"order_id": line.sale_order_line_id.order_id.id,
43+
"name": str(line.warranty_config_id.name) + "/" + str(line.end_date),
44+
"price_unit": line.sale_order_line_id.price_subtotal
45+
* (line.warranty_config_id.percentage / 100),
46+
"product_id": line.warranty_config_id.product_id.id,
47+
"parent_sale_order_line_id": line.sale_order_line_id.id,
48+
"sequence": line.sale_order_line_id.sequence,
49+
}
50+
for line in self.warranty_lines_ids.filtered(
51+
lambda x: x.warranty_config_id.name
52+
)
53+
]
54+
self.env["sale.order.line"].create(new_order_line_list)

warranty_configuration/wizards/add_warranty_wizard_view.xml

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<sheet>
88
<field name="warranty_lines_ids">
99
<list create="false" no_open="1" editable="top" >
10+
<field name="sale_order_line_id" optional="hide" />
1011
<field name="product_id" readonly="1" />
1112
<field name="warranty_config_id" />
1213
<field name="end_date" readonly="1" />

0 commit comments

Comments
 (0)