Skip to content

Enhance Appointment Filters: Type, Appointment Schedule, and Payment Step #692

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: 18.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions add_product_warranty/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from . import wizard
19 changes: 19 additions & 0 deletions add_product_warranty/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "Add Warranty Product",
"description": """
The Module helps to add warranty to our product
""",
"version": "1.0",
"depends": ["product", "sale_management"],
"data": [
"security/ir.model.access.csv",
"views/product_warranty.xml",
"views/warranty_menus.xml",
"views/product_template.xml",
"views/sale_order_button.xml",
"wizard/add_warranty_wizard.xml",
],
"auto-install": True,
"application": False,
"license": "LGPL-3",
}
3 changes: 3 additions & 0 deletions add_product_warranty/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import product_warranty
from . import product_template
from . import sale_order_unlink
7 changes: 7 additions & 0 deletions add_product_warranty/models/product_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from odoo import fields, models


class productTemplate(models.Model):
_inherit = "product.template"

is_warranty_available = fields.Boolean(string="Is Warranty Available")
10 changes: 10 additions & 0 deletions add_product_warranty/models/product_warranty.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from odoo import fields, models


class productWarranty(models.Model):
_name = "product.warranty"
_description = "Product Warranty"

name = fields.Char(string="Name", required=True)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In spec it is mentioned that we have to make a manyone with a product, so a warranty will also be a product.

percentage = fields.Float(string="Percentage", required=True)
validity_year = fields.Integer(string="Validity Year")
19 changes: 19 additions & 0 deletions add_product_warranty/models/sale_order_unlink.py

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to update the file name.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from odoo import fields, models


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

linked_sale_order_line_id = fields.Many2one(
"sale.order.line", string="Linked Product Line"
)

def unlink(self):
for line in self:
linked_warranty_lines = self.search(
[("linked_sale_order_line_id", "=", line.id)]
)

linked_warranty_lines.unlink()

return super(salesOrderLine, self).unlink()
Comment on lines +11 to +19

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than overriding this unlink function, can't we use the ondelete cascade property?
Or for the instant effect, we can also use onchange.

4 changes: 4 additions & 0 deletions add_product_warranty/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
add_product_warranty.access_product_warranty,access_product_warranty,add_product_warranty.model_product_warranty,base.group_user,1,1,1,1
add_product_warranty.access_warranty_wizard,access_warranty_wizard,add_product_warranty.model_warranty_wizard,base.group_user,1,1,1,1
add_product_warranty.access_warranty_wizard_line,access_warranty_wizard_line,add_product_warranty.model_warranty_wizard_line,base.group_user,1,1,1,1
15 changes: 15 additions & 0 deletions add_product_warranty/views/product_template.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="product_template_inherit_form" model="ir.ui.view">
<field name="name">product.template.inherit.form</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view" />
<field name="arch" type="xml">
<xpath expr="//page[@name='sales']/group[@name='sale']" position="inside">
<group string="Product Warranty" name="product_warranty">
<field name="is_warranty_available" />
</group>
</xpath>
Comment on lines +8 to +12

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we target with a simpler XPath?

</field>
</record>
</odoo>
20 changes: 20 additions & 0 deletions add_product_warranty/views/product_warranty.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="warranty_config_action" model="ir.actions.act_window">
<field name="name">Warranty Configuration</field>
<field name="res_model">product.warranty</field>
<field name="view_mode">list,form</field>
</record>

<record id="warranty_list_view" model="ir.ui.view">
<field name="name">product.warranty.list </field>
<field name="model">product.warranty</field>
<field name="arch" type="xml">
<list create="1">
<field name="name" />
<field name="percentage" />
<field name="validity_year" />
</list>
</field>
</record>
</odoo>
14 changes: 14 additions & 0 deletions add_product_warranty/views/sale_order_button.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="sale_order_button_wizard" model="ir.ui.view">
<field name="name">sale.order.button.wizard</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form" />
<field name="arch" type="xml">
<xpath expr="//div[@name='so_button_below_order_lines']" position="inside">
<button string="Add Warranty" type="action"
name="%(add_product_warranty.action_add_warranty)d" class="btn btn-primary" />
</xpath>
</field>
</record>
</odoo>
8 changes: 8 additions & 0 deletions add_product_warranty/views/warranty_menus.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<menuitem id="menu_warranty_config"
name="Warranty Configuration"
parent="sale.menu_sale_config"
action="warranty_config_action"
sequence="20" />
</odoo>
2 changes: 2 additions & 0 deletions add_product_warranty/wizard/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import add_warranty_wizard
from . import warranty_wizard_line
66 changes: 66 additions & 0 deletions add_product_warranty/wizard/add_warranty_wizard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
from odoo import api, fields, models


class addWarrantyWizard(models.TransientModel):
_name = "warranty.wizard"
_description = "Wizard to add Warranty for product"

sale_order_id = fields.Many2one("sale.order", string="Quotation", required=True)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there is a need for this field.

line_ids = fields.One2many("warranty.wizard.line", "wizard_id", string=" ")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why empty string attribute here?


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

for line in sale_order.order_line:
if line.product_id.is_warranty_available:
lines.append(
(
0,
0,
{
"product_id": line.product_id.id,
"sale_order_line_id": line.id,
},
)
)
Comment on lines +19 to +28

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to format it.

res["sale_order_id"] = sale_order.id
res["line_ids"] = lines
return res

def action_add_warranty_product(self):
total_price = 0
description_lines = []
linked_lines = None
warranty_product = None

for line in self.line_ids:
if line.warranty_id:
base_price = line.sale_order_line_id.price_unit
percentage = line.warranty_id.percentage
extended_price = (base_price * percentage) / 100
total_price += extended_price

description_lines.append(
f"{line.product_id.name} - Valid till {line.warranty_end_date}"
)

if not warranty_product:
warranty_product = line.product_id

linked_lines = line.sale_order_line_id.id

if total_price > 0:
self.env["sale.order.line"].create(
{
"order_id": self.sale_order_id.id,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can get the order ID from the context instead of making a separate field.

"product_id": warranty_product.id,
"name": "Extended Warranty:\n" + "\n".join(description_lines),
"price_unit": total_price,
"product_uom_qty": 1,
"product_uom": warranty_product.uom_id.id,
"linked_sale_order_line_id": linked_lines,
}
)
30 changes: 30 additions & 0 deletions add_product_warranty/wizard/add_warranty_wizard.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_warranty_wizard_form" model="ir.ui.view">
<field name="name">warranty.wizard.form</field>
<field name="model">warranty.wizard</field>
<field name="arch" type="xml">
<form string="Add Warranty">
<field name="line_ids">
<list create="false" editable="bottom">
<field name="product_id"/>
<field name="warranty_id" string="Year" options="{'no_create': True}" />
<field name="sale_order_line_id" column_invisible="1" />
<field name="warranty_end_date" readonly="1" />
</list>
</field>
<footer>
<button name="action_add_warranty_product" type="object" string="Add Warranty"
class="btn-primary" />
</footer>
</form>
</field>
</record>

<record id="action_add_warranty" model="ir.actions.act_window">
<field name="name">Add Warranty</field>
<field name="res_model">warranty.wizard</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
</odoo>
29 changes: 29 additions & 0 deletions add_product_warranty/wizard/warranty_wizard_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from odoo import api, fields, models


class warrantyWizardLine(models.TransientModel):
_name = "warranty.wizard.line"
_description = "warranty Line to Select Warranty"

wizard_id = fields.Many2one("warranty.wizard", string="Wizard")
product_id = fields.Many2one("product.product", string="Product")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this field required?

sale_order_line_id = fields.Many2one("sale.order.line", string="Sale order Line")
warranty_id = fields.Many2one("product.warranty", string="Warranty")

validity_year = fields.Integer(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of creating the field we can use directly warranty_id.validity_year.

string="Validity Year", related="warranty_id.validity_year", readonly=True
)

warranty_end_date = fields.Date(
string="End Date", compute="_compute_warranty_end_date"
)

@api.depends("validity_year")
def _compute_warranty_end_date(self):
for record in self:
if record.validity_year:
record.warranty_end_date = record.warranty_end_date or fields.Date.add(
fields.Date.today(), days=365 * record.validity_year
)
else:
record.warranty_end_date = False
2 changes: 2 additions & 0 deletions bom_modular_extension/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from . import wizard
18 changes: 18 additions & 0 deletions bom_modular_extension/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "BOM Modular Extension",
"description": "Add modular types and multiplies MO line quantity by SO values",
"version": "1.0",
"depends": ["sale_management", "mrp", "product"],
"category": "Manufacturing",
"data": [
"security/ir.model.access.csv",
"views/product_template.xml",
"views/mrp_bom_line.xml",
"wizard/sale_order_line_wizard.xml",
"views/sale_order_button.xml",
"views/mrp_production.xml",
],
"application": False,
"auto_install": False,
"license": "LGPL-3",
}
7 changes: 7 additions & 0 deletions bom_modular_extension/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from . import modular_type
from . import product_template
from . import mrp_bom_line
from . import sale_order_line
from . import sale_order_line_modular_type
from . import sale_order
from . import stock_move
8 changes: 8 additions & 0 deletions bom_modular_extension/models/modular_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from odoo import fields, models


class modularType(models.Model):
_name = "modular.type"
_description = "Help to give modular type to product"

name = fields.Char(string="Name", required=True)
26 changes: 26 additions & 0 deletions bom_modular_extension/models/mrp_bom_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from odoo import fields, models, api


class MrpBomLine(models.Model):
_inherit = "mrp.bom.line"

modular_type_id = fields.Many2one(
"modular.type",
string="Modular Type",
domain="[('id', 'in', filter_modular_type_ids)]",
help="Specify which modular type this BOM line belongs to",
)

filter_modular_type_ids = fields.Many2many(
"modular.type",
compute="_compute_available_modular_types",
string="Available Modular Types",
)

@api.depends("bom_id.product_tmpl_id")
def _compute_available_modular_types(self):
for line in self:
product_tmpl = line.bom_id.product_tmpl_id
line.filter_modular_type_ids = (
product_tmpl.modular_type_ids if product_tmpl else False
)
9 changes: 9 additions & 0 deletions bom_modular_extension/models/product_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from odoo import fields, models


class productTemplate(models.Model):
_inherit = "product.template"

modular_type_ids = fields.Many2many(
"modular.type", help="Help to give modular type to product"
)
27 changes: 27 additions & 0 deletions bom_modular_extension/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from odoo import models


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

def action_confirm(self):
res = super().action_confirm()

for production in self.mrp_production_ids:
selected_order_line = self.order_line.filtered(
lambda line: line.product_id == production.product_id
and line.product_uom_qty == production.product_qty
)

for stock_line in production.move_raw_ids.filtered(
lambda move: move.modular_type_id
):
modular_value = (
selected_order_line.mapped("modular_type_value_ids")
.filtered(lambda m: m.modular_type_id == stock_line.modular_type_id)
.value
)

stock_line.product_uom_qty *= modular_value or 0.0

return res
18 changes: 18 additions & 0 deletions bom_modular_extension/models/sale_order_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from odoo import api, fields, models


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

modular_type_value_ids = fields.One2many(
"sale.order.line.modular.type", "order_line_id", string="Modular Type Value"
)

is_modular_types = fields.Boolean(
string="Has modular type", compute="_compute_has_modular_types"
)

@api.depends("product_template_id")
def _compute_has_modular_types(self):
for record in self:
record.is_modular_types = bool(record.product_template_id.modular_type_ids)
10 changes: 10 additions & 0 deletions bom_modular_extension/models/sale_order_line_modular_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from odoo import fields, models


class saleOrderLineModularType(models.Model):
_name = "sale.order.line.modular.type"
_description = "Modular Type Value for Sale Order Line"

order_line_id = fields.Many2one("sale.order.line", string="Order Line")
modular_type_id = fields.Many2one("modular.type", string="Modular Type")
value = fields.Float(string="Value", required=True)
Loading