[NEW] funding_campaign: create add-on
This commit is contained in:
5
funding_campaign/models/__init__.py
Normal file
5
funding_campaign/models/__init__.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from . import sale_order
|
||||
from . import crm_lead
|
||||
from . import account_move
|
||||
from . import funding_campaign
|
||||
from . import campaign_step
|
9
funding_campaign/models/account_move.py
Normal file
9
funding_campaign/models/account_move.py
Normal file
@@ -0,0 +1,9 @@
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
from odoo import fields, models
|
||||
|
||||
class AccountMove(models.Model):
|
||||
_inherit = "account.move"
|
||||
|
||||
funding_campaign_id = fields.Many2one('funding.campaign', string='Funding Campaign')
|
||||
|
||||
|
22
funding_campaign/models/campaign_step.py
Normal file
22
funding_campaign/models/campaign_step.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from odoo import api, fields, models
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
class CampaignStep(models.Model):
|
||||
_name = 'campaign.step'
|
||||
_description = 'Campaign Step'
|
||||
|
||||
name = fields.Char(string='Name')
|
||||
description = fields.Html(string='Description')
|
||||
active = fields.Boolean('Active', default=True)
|
||||
sequence = fields.Integer()
|
||||
funding_campaign_id = fields.Many2one('funding.campaign', string='Funding Campaign')
|
||||
step_amount = fields.Float('Step Amount')
|
||||
state = fields.Selection(
|
||||
[("locked", "Locked"), ("unlocked", "Unlocked"), ("reached", "Reached")],
|
||||
string="Status",
|
||||
index=True,
|
||||
readonly=True,
|
||||
default="locked",
|
||||
track_visibility="onchange",
|
||||
copy=False,
|
||||
)
|
19
funding_campaign/models/crm_lead.py
Normal file
19
funding_campaign/models/crm_lead.py
Normal file
@@ -0,0 +1,19 @@
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
from odoo import fields, models
|
||||
|
||||
class Lead(models.Model):
|
||||
_inherit = 'crm.lead'
|
||||
|
||||
def _compute_is_funding_campaign_lead(self):
|
||||
for lead in self:
|
||||
lead.is_funding_campaign_lead = True if lead.funding_campaign_id else False
|
||||
|
||||
|
||||
funding_campaign_id = fields.Many2one('funding.campaign', string='Funding Campaign')
|
||||
is_funding_campaign_lead = fields.Boolean('Is Funding Campaign Lead', compute="_compute_is_funding_campaign_lead")
|
||||
|
||||
def _prepare_opportunity_quotation_context(self):
|
||||
context = super(Lead,self)._prepare_opportunity_quotation_context()
|
||||
if self.funding_campaign_id:
|
||||
context["funding_campaign_id"] = self.funding_campaign_id.id
|
||||
return context
|
66
funding_campaign/models/funding_campaign.py
Normal file
66
funding_campaign/models/funding_campaign.py
Normal file
@@ -0,0 +1,66 @@
|
||||
|
||||
|
||||
from odoo import api, fields, models
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
|
||||
class FundingCampaign(models.Model):
|
||||
_name = 'funding.campaign'
|
||||
_description = 'Funding Campaign'
|
||||
|
||||
def _compute_amounts(self):
|
||||
for campaign in self:
|
||||
# Wished
|
||||
campaign.total_wished_amount = sum(campaign.campaign_step_ids.mapped("step_amount"))
|
||||
# Promised
|
||||
sale_order_ids = self.order_ids.filtered(lambda x: x.state == "sale")
|
||||
campaign.promised_amount = sum(sale_order_ids.mapped("amount_total"))
|
||||
# Paid
|
||||
invoice_ids = self.invoice_ids.filtered(lambda x: x.state == "posted")
|
||||
campaign.paid_amount = sum(invoice_ids.mapped("amount_total"))
|
||||
|
||||
|
||||
name = fields.Char(string='Name')
|
||||
description = fields.Html(string='Description')
|
||||
active = fields.Boolean('Active', default=True)
|
||||
|
||||
product_id = fields.Many2one('product.product', string='Product')
|
||||
state = fields.Selection(
|
||||
[("draft", "Draft"), ("opened", "Opened"), ("closed", "Closed")],
|
||||
string="Status",
|
||||
index=True,
|
||||
readonly=True,
|
||||
default="draft",
|
||||
track_visibility="onchange",
|
||||
copy=False,
|
||||
)
|
||||
opportunity_ids = fields.One2many('crm.lead', 'funding_campaign_id', string="Participants")
|
||||
order_ids = fields.One2many('sale.order', 'funding_campaign_id', string='Sale Orders')
|
||||
invoice_ids = fields.One2many('account.move', 'funding_campaign_id', string='Invoices')
|
||||
nb_participants = fields.Integer(
|
||||
string='Number of Potential Participants',
|
||||
store=False, readonly=True, compute='_compute_participants')
|
||||
promised_amount = fields.Float('Promised Amount', readonly=True, compute="_compute_amounts")
|
||||
paid_amount = fields.Float('Paid Amount', readonly=True, compute="_compute_amounts")
|
||||
|
||||
campaign_step_ids = fields.One2many('campaign.step', 'funding_campaign_id', string='Campaign Steps')
|
||||
total_wished_amount = fields.Float('Total Wished Amount', readonly=True, compute="_compute_amounts")
|
||||
|
||||
def action_draft_campaign(self):
|
||||
self.state = "draft"
|
||||
|
||||
def action_open_campaign(self):
|
||||
self.state = "opened"
|
||||
|
||||
def action_close_campaign(self):
|
||||
self.state = "closed"
|
||||
|
||||
def add_registration(self):
|
||||
self.ensure_one()
|
||||
if self.state != "opened":
|
||||
raise UserError("This campaign is not opened, no registration can be added.")
|
||||
|
||||
@api.depends('opportunity_ids')
|
||||
def _compute_participants(self):
|
||||
for campaign in self:
|
||||
campaign.nb_participants = len(campaign.opportunity_ids)
|
15
funding_campaign/models/sale_order.py
Normal file
15
funding_campaign/models/sale_order.py
Normal file
@@ -0,0 +1,15 @@
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
from odoo import fields, models
|
||||
|
||||
class SaleOrder(models.Model):
|
||||
_inherit = "sale.order"
|
||||
|
||||
def _compute_is_funding_campaign_order(self):
|
||||
for lead in self:
|
||||
lead.is_funding_campaign_order = True if lead.funding_campaign_id else False
|
||||
|
||||
|
||||
funding_campaign_id = fields.Many2one('funding.campaign', string='Funding Campaign')
|
||||
is_funding_campaign_order = fields.Boolean('Is Funding Campaign Order', compute="_compute_is_funding_campaign_order")
|
||||
|
||||
|
Reference in New Issue
Block a user