Merge pull request #3206 from expsa/ENS-3085
[IMP] ensan_donation_request: new requirements
This commit is contained in:
commit
bed92f9d87
|
|
@ -5,7 +5,7 @@
|
|||
'category': 'Nonprofit',
|
||||
'author': 'Expert Co.',
|
||||
'license': 'LGPL-3',
|
||||
'depends': ['base', 'mail', 'website', 'stock', 'account', 'sms', 'payment', 'ensan_sale_management'],
|
||||
'depends': ['base', 'mail', 'website_sale', 'stock', 'account', 'sms', 'payment', 'ensan_sale_management'],
|
||||
'data': [
|
||||
'security/security.xml',
|
||||
'security/ir.model.access.csv',
|
||||
|
|
@ -18,6 +18,7 @@
|
|||
'views/product_template_views.xml',
|
||||
'views/res_config_settings_views.xml',
|
||||
'report/campaign_report.xml',
|
||||
'views/product_public_category.xml',
|
||||
'views/menus.xml',
|
||||
],
|
||||
'application': True,
|
||||
|
|
|
|||
|
|
@ -24,3 +24,8 @@ class DonationRequestsApi(http.Controller):
|
|||
return {
|
||||
'error': str(e)
|
||||
}
|
||||
|
||||
@route('/campaigns/request', auth='user', type='http', website=True, methods=['GET'])
|
||||
def campaign_request(self):
|
||||
categories = request.env['product.public.category'].sudo().search_read([('available_in_donation_request', '=', True)], fields=['id', 'name', 'minimum_request_amount'])
|
||||
return request.render('template_to_be_implemented.', {'categories': categories})
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
from odoo import http, _
|
||||
from odoo.http import route, request
|
||||
from odoo.addons.website_sale.controllers.main import WebsiteSale
|
||||
from odoo.osv import expression
|
||||
|
||||
|
||||
class WebsiteSaleExtended(WebsiteSale):
|
||||
|
||||
def _get_search_domain(self, search, category, attrib_values, search_in_description=True, **kwargs):
|
||||
domain = super()._get_search_domain(search, category, attrib_values, search_in_description, **kwargs)
|
||||
domain = expression.AND([domain, [('hide_from_shop_front', '=', False)]])
|
||||
return domain
|
||||
@route('/campaigns', auth='public', type='http', website=True, methods=['GET'])
|
||||
def donation_campaigns_shop(self):
|
||||
return self.shop()
|
||||
|
||||
|
|
|
|||
|
|
@ -3,3 +3,5 @@ from . import donation_stage
|
|||
from . import donation_priority
|
||||
from . import product_template
|
||||
from . import res_config_settings
|
||||
from . import product_category
|
||||
from . import website
|
||||
|
|
@ -6,12 +6,11 @@ class DonationRequest(models.Model):
|
|||
_name = "donation.request"
|
||||
_description = "Donation Request"
|
||||
_rec_name = "request_number"
|
||||
_inherit = ['mail.thread', 'image.mixin', 'mail.activity.mixin']
|
||||
_inherit = ['mail.thread', 'mail.activity.mixin']
|
||||
|
||||
name = fields.Char(string="Donation Name", required=True, tracking=True, copy=False, default=_('New'))
|
||||
request_number = fields.Char(string="Request Number", readonly=True, default=lambda self: _('New'), copy=False)
|
||||
user_id = fields.Many2one('res.users', string="Responsible/Submitter", default=lambda self: self.env.user)
|
||||
|
||||
partner_id = fields.Many2one('res.partner', related='user_id.partner_id', store=True)
|
||||
|
||||
partner_name = fields.Char(string="Beneficiary Name", related='partner_id.name')
|
||||
|
|
@ -20,13 +19,12 @@ class DonationRequest(models.Model):
|
|||
partner_country_id = fields.Many2one('res.country', string='Nationality', related='partner_id.country_id')
|
||||
partner_region_id = fields.Many2one('res.country.state', string="Region", related='partner_id.state_id')
|
||||
total_amount = fields.Float(string="Total Amount", )
|
||||
description = fields.Text(required=True)
|
||||
attachment_ids = fields.Many2many('ir.attachment', string="Attachments")
|
||||
|
||||
priority_id = fields.Many2one('donation.priority', string="Priority", required=True, default=lambda self: self.env.ref('ensan_donation_request.priority_regular'))
|
||||
stage_id = fields.Many2one('donation.stage', string="Stage", default=lambda self: self.env.ref(
|
||||
'ensan_donation_request.stage_draft').id, copy=False, index=True, group_expand='_read_group_stage_ids', store=True, compute='_compute_stage_id')
|
||||
category_id = fields.Many2one('product.category', string="Category", required=True)
|
||||
category_id = fields.Many2one('product.public.category', string="Category", required=True, domain="[('available_in_donation_request', '=', True), ('parent_id', '=', False)]")
|
||||
stage_type = fields.Selection(related='stage_id.stage_type', store=True)
|
||||
stage_name = fields.Char(related='stage_id.name')
|
||||
remaining_amount = fields.Float(string="Remaining Amount", related='product_id.remaining_amount')
|
||||
|
|
@ -34,7 +32,7 @@ class DonationRequest(models.Model):
|
|||
active = fields.Boolean(default=True)
|
||||
product_id = fields.Many2one('product.template', readonly=True)
|
||||
website_url = fields.Char(related='product_id.website_url')
|
||||
is_private_request = fields.Boolean()
|
||||
show_in_most_active_page = fields.Boolean()
|
||||
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
|
|
@ -53,8 +51,8 @@ class DonationRequest(models.Model):
|
|||
@api.constrains('total_amount')
|
||||
def _check_total_amount(self):
|
||||
for rec in self:
|
||||
if rec.total_amount <= 0:
|
||||
raise ValidationError(_('Total Amount must be greater than 0!'))
|
||||
if rec.total_amount < rec.category_id.minimum_request_amount:
|
||||
raise ValidationError(_('Total Amount must be greater than or equal %.2f!') % rec.category_id.minimum_request_amount)
|
||||
|
||||
def action_approve(self):
|
||||
sms_template_id = self.env.company.donation_request_confirmation_sms_template_id
|
||||
|
|
@ -70,14 +68,16 @@ class DonationRequest(models.Model):
|
|||
'name': record.name,
|
||||
'type': 'service',
|
||||
'default_code': record.request_number,
|
||||
'categ_id': record.category_id.id,
|
||||
'public_categ_ids': [(6, 0, record.category_id.ids)],
|
||||
'target_amount': record.total_amount,
|
||||
'remaining_amount': record.total_amount,
|
||||
'sale_ok': True,
|
||||
'website_published': True,
|
||||
'is_published': True,
|
||||
'image_1920': record.image_1920,
|
||||
'donation_request_id': record.id
|
||||
'image_1920': record.category_id.image_1920,
|
||||
'donation_request_id': record.id,
|
||||
'website_description': record.category_id.website_description,
|
||||
'hide_from_shop_front': True
|
||||
})
|
||||
record.product_id = product
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
from odoo import models, fields, api
|
||||
|
||||
class ProductCategory(models.Model):
|
||||
_inherit = 'product.public.category'
|
||||
|
||||
available_in_donation_request = fields.Boolean()
|
||||
minimum_request_amount = fields.Float()
|
||||
|
|
@ -4,4 +4,4 @@ class ProductTemplate(models.Model):
|
|||
_inherit = 'product.template'
|
||||
|
||||
donation_request_id = fields.Many2one('donation.request', ondelete='restrict')
|
||||
hide_from_shop_front = fields.Boolean(related="donation_request_id.is_private_request", store=True)
|
||||
hide_from_shop_front = fields.Boolean()
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
from odoo import models, fields, api
|
||||
from odoo.http import request
|
||||
from odoo.osv import expression
|
||||
|
||||
|
||||
class Website(models.Model):
|
||||
_inherit = 'website'
|
||||
|
||||
def sale_product_domain(self):
|
||||
domain = super().sale_product_domain()
|
||||
if '/shop' in request.httprequest.full_path:
|
||||
domain = expression.AND([domain, [('hide_from_shop_front', '=', False)]])
|
||||
if '/campaigns' in request.httprequest.full_path:
|
||||
products = request.env['donation.request'].search([('stage_type', '=', 'approve'), ('show_in_most_active_page', '=', True)]).product_id
|
||||
domain = expression.AND([domain, [('id', 'in', products.ids)]])
|
||||
|
||||
return domain
|
||||
|
||||
|
|
@ -59,8 +59,8 @@
|
|||
</div>
|
||||
<widget name="web_ribbon" title="Archived" bg_color="bg-danger"
|
||||
attrs="{'invisible': [('active', '=', True)]}" />
|
||||
<field name="image_1920" required="1" widget="image" class="oe_avatar"
|
||||
options="{'preview_image': 'image_128'}" />
|
||||
<!-- <field name="image_1920" readonly="1" widget="image" class="oe_avatar"
|
||||
options="{'preview_image': 'image_128'}" /> -->
|
||||
|
||||
<div class="oe_title">
|
||||
<h3>
|
||||
|
|
@ -92,16 +92,16 @@
|
|||
<field name="category_id" />
|
||||
<field name="priority_id" />
|
||||
<field name="user_id" />
|
||||
<field name="is_private_request" />
|
||||
<field name="show_in_most_active_page" />
|
||||
<field name="attachment_ids" widget="many2many_binary" />
|
||||
</group>
|
||||
<group name="stats" string="Statistics">
|
||||
<field name="total_amount" />
|
||||
<field name="total_amount" string="Requested Amount"/>
|
||||
<field name="remaining_amount" readonly="1" />
|
||||
<!-- <field name="current_amount" readonly="1" /> -->
|
||||
</group>
|
||||
</group>
|
||||
<notebook>
|
||||
<!-- <notebook> -->
|
||||
<!-- <page string="Conditions"
|
||||
attrs="{'invisible': [('donation_type_id', '=', False)]}">
|
||||
<group>
|
||||
|
|
@ -113,9 +113,9 @@
|
|||
</group>
|
||||
</group>
|
||||
</page> -->
|
||||
<page string="Description">
|
||||
<!-- <page string="Description">
|
||||
<field name="description" />
|
||||
</page>
|
||||
</page> -->
|
||||
<!-- <page string="SEO">
|
||||
<group name="name" string="string">
|
||||
<field name="seo_name" />
|
||||
|
|
@ -124,7 +124,7 @@
|
|||
<field name="website_meta_keywords" string="Meta Keywords" help="Separate every keyword with a comma"/>
|
||||
</group>
|
||||
</page> -->
|
||||
</notebook>
|
||||
<!-- </notebook> -->
|
||||
</sheet>
|
||||
<div class="oe_chatter">
|
||||
<field name="message_follower_ids" />
|
||||
|
|
@ -146,14 +146,14 @@
|
|||
<field name="request_number"/>
|
||||
<!-- <field name="beneficiary_name"/> -->
|
||||
<field name="total_amount"/>
|
||||
<!-- <field name="remaining_amount"/> -->
|
||||
<field name="image_128"/>
|
||||
<field name="remaining_amount"/>
|
||||
<!-- <field name="image_128"/> -->
|
||||
<templates>
|
||||
<t t-name="kanban-box">
|
||||
<div class="oe_kanban_global_click">
|
||||
<div class="o_kanban_image">
|
||||
<!-- <div class="o_kanban_image">
|
||||
<img t-att-src="kanban_image('donation.request', 'image_128', record.raw_value)" alt="Donation Request"/>
|
||||
</div>
|
||||
</div> -->
|
||||
<div class="oe_kanban_details">
|
||||
<strong class="o_kanban_record_title">
|
||||
<field name="name"/>
|
||||
|
|
@ -168,9 +168,9 @@
|
|||
<div class="text-muted">
|
||||
Amount: <field name="total_amount"/>
|
||||
</div>
|
||||
<!-- <div class="text-muted" t-if="record.remaining_amount.value > 0">
|
||||
<div class="text-muted" t-if="record.remaining_amount.value > 0">
|
||||
Remaining: <field name="remaining_amount"/>
|
||||
</div> -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</t>
|
||||
|
|
@ -189,7 +189,7 @@
|
|||
<field name="stage_id" />
|
||||
<field name="priority_id" />
|
||||
<field name="total_amount" />
|
||||
<!-- <field name="remaining_amount" /> -->
|
||||
<field name="remaining_amount" />
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
|
|
|||
|
|
@ -1,25 +1,32 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<menuitem id="menu_donation_root"
|
||||
name="Donation Requests"
|
||||
web_icon="ensan_donation_request,static/description/icon.png"
|
||||
groups="ensan_donation_request.group_donations_user"
|
||||
sequence="10">
|
||||
name="Donation Requests"
|
||||
web_icon="ensan_donation_request,static/description/icon.png"
|
||||
groups="ensan_donation_request.group_donations_user"
|
||||
sequence="10">
|
||||
<menuitem
|
||||
id="menu_donation_request"
|
||||
name="Requests"
|
||||
action="action_donation_request"
|
||||
sequence="10"/>
|
||||
id="menu_donation_request"
|
||||
name="Requests"
|
||||
action="action_donation_request"
|
||||
sequence="10" />
|
||||
<menuitem
|
||||
id="menu_donation_configuration"
|
||||
name="Configuration"
|
||||
groups="ensan_donation_request.group_donations_manager"
|
||||
sequence="30">
|
||||
<menuitem id="menu_donation_config" name="Settings" action="action_donation_request_config" sequence="0"/>
|
||||
id="menu_donation_configuration"
|
||||
name="Configuration"
|
||||
groups="ensan_donation_request.group_donations_manager"
|
||||
sequence="30">
|
||||
<menuitem id="menu_donation_config" name="Settings"
|
||||
action="action_donation_request_config" sequence="0" />
|
||||
<menuitem id="menu_donation_stage" name="Donation Stages"
|
||||
action="action_donation_stage" sequence="10"/>
|
||||
action="action_donation_stage" sequence="10" />
|
||||
<menuitem id="menu_donation_priority" name="Donation Priorities"
|
||||
action="action_donation_priority" sequence="30"/>
|
||||
action="action_donation_priority" sequence="30" />
|
||||
<menuitem
|
||||
id="public_category_donation_menu"
|
||||
name="Categories"
|
||||
action="product_public_category_donation_action"
|
||||
sequence="40" />
|
||||
|
||||
</menuitem>
|
||||
</menuitem>
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,34 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
|
||||
<record id="view_public_category_from_inherit" model="ir.ui.view">
|
||||
<field name="name">view.public.category.from.inherit</field>
|
||||
<field name="model">product.public.category</field>
|
||||
<field name="inherit_id" ref="website_sale.product_public_category_form_view"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="sequence" position="after">
|
||||
<field name="available_in_donation_request" />
|
||||
<field name="minimum_request_amount" attrs="{'required': [('available_in_donation_request', '=', True)], 'invisible': [('available_in_donation_request', '=', False)]}"/>
|
||||
<field name="website_description" attrs="{'required': [('available_in_donation_request', '=', True)], 'invisible': [('available_in_donation_request', '=', False)]}"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="product_public_category_donation_action" model="ir.actions.act_window">
|
||||
<field name="name">Categories</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">product.public.category</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
<field name="view_id" eval="False"/>
|
||||
<field name="domain">[('available_in_donation_request', '=', True)]</field>
|
||||
<field name="context">{'default_available_in_donation_request': True}</field>
|
||||
<field name="help" type="html">
|
||||
<p class="o_view_nocontent_smiling_face">
|
||||
Define a new category
|
||||
</p><p>
|
||||
Categories are used to browse your products through the
|
||||
touchscreen interface.
|
||||
</p>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
Loading…
Reference in New Issue