[NEW] Addons creation - product_rental_leads
This commit is contained in:
4
product_rental_leads/models/__init__.py
Normal file
4
product_rental_leads/models/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from . import crm_lead
|
||||
from . import product_order
|
42
product_rental_leads/models/crm_lead.py
Executable file
42
product_rental_leads/models/crm_lead.py
Executable file
@@ -0,0 +1,42 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from odoo import models, fields, api
|
||||
|
||||
|
||||
class CrmLead(models.Model):
|
||||
_inherit = "crm.lead"
|
||||
|
||||
product_model = fields.Many2one("product.product", string="Product Model")
|
||||
from_date = fields.Datetime("From Date")
|
||||
to_date = fields.Datetime("To Date")
|
||||
sale_number = fields.Integer(
|
||||
compute="_compute_sale_amount_total", string="Number of Quotations", default="5"
|
||||
)
|
||||
order_ids = fields.One2many(
|
||||
"rental.product.order", "opportunity_id", string="Orders"
|
||||
)
|
||||
company_id = fields.Many2one(
|
||||
"res.company", string="Company", default=lambda self: self.env.user.company_id
|
||||
)
|
||||
|
||||
@api.depends("order_ids")
|
||||
def _compute_sale_amount_total(self):
|
||||
for lead in self:
|
||||
total = 0.0
|
||||
nbr = 0
|
||||
company_currency = (
|
||||
lead.company_currency or self.env.user.company_id.currency_id
|
||||
)
|
||||
for order in lead.order_ids:
|
||||
if order.state in (
|
||||
"draft",
|
||||
"confirm",
|
||||
):
|
||||
nbr += 1
|
||||
if order.state not in ("draft", "sent", "cancel"):
|
||||
total += order.currency_id.compute(
|
||||
order.untaxed_amount, company_currency
|
||||
)
|
||||
lead.sale_amount_total = total
|
||||
lead.sale_number = nbr
|
||||
return True
|
9
product_rental_leads/models/product_order.py
Normal file
9
product_rental_leads/models/product_order.py
Normal file
@@ -0,0 +1,9 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from odoo import models, fields, _
|
||||
|
||||
|
||||
class RentalProductOrder(models.Model):
|
||||
_inherit = "rental.product.order"
|
||||
|
||||
opportunity_id = fields.Many2one("crm.lead", string=_("Opportunity"))
|
Reference in New Issue
Block a user