diff --git a/estate/controllers/main.py b/estate/controllers/main.py index b875dc1962..f67222f500 100644 --- a/estate/controllers/main.py +++ b/estate/controllers/main.py @@ -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() diff --git a/estate/controllers/postreq.py b/estate/controllers/postreq.py index 23218c1c80..dc5a52dc1e 100644 --- a/estate/controllers/postreq.py +++ b/estate/controllers/postreq.py @@ -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}") diff --git a/estate/views/website_properties_templates.xml b/estate/views/website_properties_templates.xml index ada1adf056..e2df59b72e 100644 --- a/estate/views/website_properties_templates.xml +++ b/estate/views/website_properties_templates.xml @@ -8,11 +8,20 @@
- Property Image + + Property Image + + + Property Image +
@@ -51,4 +60,4 @@
- + \ No newline at end of file diff --git a/estate_account/__manifest__.py b/estate_account/__manifest__.py index 70d0e90cad..05e9cf89d0 100644 --- a/estate_account/__manifest__.py +++ b/estate_account/__manifest__.py @@ -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", diff --git a/estate_account/views/estate_property_views.xml b/estate_account/views/estate_property_views.xml index fd50fb5c31..7bd74fb6f4 100644 --- a/estate_account/views/estate_property_views.xml +++ b/estate_account/views/estate_property_views.xml @@ -12,6 +12,7 @@ icon="fa-bars" string="offers" invisible="invoice_count == 0" + groups="base.group_system" >
diff --git a/warranty_configuration/__manifest__.py b/warranty_configuration/__manifest__.py index 8dc236b5d0..d5dc0c54f5 100644 --- a/warranty_configuration/__manifest__.py +++ b/warranty_configuration/__manifest__.py @@ -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 @@ -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, diff --git a/warranty_configuration/demo/product_demo.xml b/warranty_configuration/demo/product_demo.xml new file mode 100644 index 0000000000..9a525df9a9 --- /dev/null +++ b/warranty_configuration/demo/product_demo.xml @@ -0,0 +1,29 @@ + + + + Basic Warranty Service + service + WARRANTY_BASIC + 50.0 + 30.0 + + + + + Premium Warranty Service + service + WARRANTY_PREMIUM + 100.0 + 70.0 + + + + + Extended Warranty Service + service + WARRANTY_EXTENDED + 150.0 + 100.0 + + + diff --git a/warranty_configuration/demo/warranty_configuration_demo.xml b/warranty_configuration/demo/warranty_configuration_demo.xml new file mode 100644 index 0000000000..2515bcffc3 --- /dev/null +++ b/warranty_configuration/demo/warranty_configuration_demo.xml @@ -0,0 +1,23 @@ + + + + Warranty - 1 year + + 1 + 10.0 + + + + Warranty - 2 year + + 2 + 15.0 + + + + Warranty - 3 year + + 3 + 20.0 + + diff --git a/warranty_configuration/models/__init__.py b/warranty_configuration/models/__init__.py index 545174b8d5..7ce3493c7b 100644 --- a/warranty_configuration/models/__init__.py +++ b/warranty_configuration/models/__init__.py @@ -1,4 +1,3 @@ from . import warranty_configuration from . import product_template -from . import sale_order from . import sale_order_line diff --git a/warranty_configuration/models/sale_order.py b/warranty_configuration/models/sale_order.py deleted file mode 100644 index f9d85e85dc..0000000000 --- a/warranty_configuration/models/sale_order.py +++ /dev/null @@ -1,7 +0,0 @@ -from odoo import models, api, fields -from datetime import date -from dateutil.relativedelta import relativedelta - - -class SaleOrder(models.Model): - _inherit = "sale.order" diff --git a/warranty_configuration/models/sale_order_line.py b/warranty_configuration/models/sale_order_line.py index 0c4aefe7b2..126521c703 100644 --- a/warranty_configuration/models/sale_order_line.py +++ b/warranty_configuration/models/sale_order_line.py @@ -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 = - \ No newline at end of file + parent_sale_order_line_id = fields.Many2one( + comodel_name="sale.order.line", + readonly=True, + ondelete="cascade", + string="parent sale order line id", + ) diff --git a/warranty_configuration/views/so_add_warranty_button_view.xml b/warranty_configuration/views/sale_order_views.xml similarity index 86% rename from warranty_configuration/views/so_add_warranty_button_view.xml rename to warranty_configuration/views/sale_order_views.xml index 51d03efbb1..58b61ad561 100644 --- a/warranty_configuration/views/so_add_warranty_button_view.xml +++ b/warranty_configuration/views/sale_order_views.xml @@ -1,5 +1,5 @@ - + sale.order.form.add.warranty sale.order diff --git a/warranty_configuration/wizards/add_warranty_line_wizard.py b/warranty_configuration/wizards/add_warranty_line_wizard.py index 9604578561..0176b75d4e 100644 --- a/warranty_configuration/wizards/add_warranty_line_wizard.py +++ b/warranty_configuration/wizards/add_warranty_line_wizard.py @@ -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() @@ -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 diff --git a/warranty_configuration/wizards/add_warranty_wizard.py b/warranty_configuration/wizards/add_warranty_wizard.py index 7c20598ce3..e1be7d9cf4 100644 --- a/warranty_configuration/wizards/add_warranty_wizard.py +++ b/warranty_configuration/wizards/add_warranty_wizard.py @@ -1,4 +1,4 @@ -from odoo import models, fields, api, Command +from odoo import models, fields, api class AddWarrantyWizard(models.TransientModel): @@ -6,54 +6,49 @@ class AddWarrantyWizard(models.TransientModel): _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) diff --git a/warranty_configuration/wizards/add_warranty_wizard_view.xml b/warranty_configuration/wizards/add_warranty_wizard_view.xml index 59b6817d78..655f4712af 100644 --- a/warranty_configuration/wizards/add_warranty_wizard_view.xml +++ b/warranty_configuration/wizards/add_warranty_wizard_view.xml @@ -7,6 +7,7 @@ +