diff --git a/odex25_donation/ensan_donation_request/__manifest__.py b/odex25_donation/ensan_donation_request/__manifest__.py index 85d567ea0..4c8407814 100644 --- a/odex25_donation/ensan_donation_request/__manifest__.py +++ b/odex25_donation/ensan_donation_request/__manifest__.py @@ -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, diff --git a/odex25_donation/ensan_donation_request/controllers/main.py b/odex25_donation/ensan_donation_request/controllers/main.py index 0d50873b4..8b103b6e0 100644 --- a/odex25_donation/ensan_donation_request/controllers/main.py +++ b/odex25_donation/ensan_donation_request/controllers/main.py @@ -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}) diff --git a/odex25_donation/ensan_donation_request/controllers/website_sale.py b/odex25_donation/ensan_donation_request/controllers/website_sale.py index f8ec57310..5841c0f38 100644 --- a/odex25_donation/ensan_donation_request/controllers/website_sale.py +++ b/odex25_donation/ensan_donation_request/controllers/website_sale.py @@ -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() + diff --git a/odex25_donation/ensan_donation_request/models/__init__.py b/odex25_donation/ensan_donation_request/models/__init__.py index db703136a..751ef34c6 100644 --- a/odex25_donation/ensan_donation_request/models/__init__.py +++ b/odex25_donation/ensan_donation_request/models/__init__.py @@ -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 \ No newline at end of file diff --git a/odex25_donation/ensan_donation_request/models/donation_request.py b/odex25_donation/ensan_donation_request/models/donation_request.py index c7fbf1680..c834a4ba4 100644 --- a/odex25_donation/ensan_donation_request/models/donation_request.py +++ b/odex25_donation/ensan_donation_request/models/donation_request.py @@ -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 diff --git a/odex25_donation/ensan_donation_request/models/product_category.py b/odex25_donation/ensan_donation_request/models/product_category.py new file mode 100644 index 000000000..6ebf46561 --- /dev/null +++ b/odex25_donation/ensan_donation_request/models/product_category.py @@ -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() diff --git a/odex25_donation/ensan_donation_request/models/product_template.py b/odex25_donation/ensan_donation_request/models/product_template.py index bdac6c0d3..4f537cb22 100644 --- a/odex25_donation/ensan_donation_request/models/product_template.py +++ b/odex25_donation/ensan_donation_request/models/product_template.py @@ -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() diff --git a/odex25_donation/ensan_donation_request/models/website.py b/odex25_donation/ensan_donation_request/models/website.py new file mode 100644 index 000000000..595e62768 --- /dev/null +++ b/odex25_donation/ensan_donation_request/models/website.py @@ -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 + diff --git a/odex25_donation/ensan_donation_request/views/donation_request_views.xml b/odex25_donation/ensan_donation_request/views/donation_request_views.xml index dd9644a47..5f937ac02 100644 --- a/odex25_donation/ensan_donation_request/views/donation_request_views.xml +++ b/odex25_donation/ensan_donation_request/views/donation_request_views.xml @@ -59,8 +59,8 @@ - +

@@ -92,16 +92,16 @@ - + - + - + - + - +
@@ -146,14 +146,14 @@ - - + +
-
+
@@ -168,9 +168,9 @@
Amount:
- +
@@ -189,7 +189,7 @@ - + diff --git a/odex25_donation/ensan_donation_request/views/menus.xml b/odex25_donation/ensan_donation_request/views/menus.xml index d92abf550..61b2fad2b 100644 --- a/odex25_donation/ensan_donation_request/views/menus.xml +++ b/odex25_donation/ensan_donation_request/views/menus.xml @@ -1,25 +1,32 @@ + name="Donation Requests" + web_icon="ensan_donation_request,static/description/icon.png" + groups="ensan_donation_request.group_donations_user" + sequence="10"> + id="menu_donation_request" + name="Requests" + action="action_donation_request" + sequence="10" /> - + id="menu_donation_configuration" + name="Configuration" + groups="ensan_donation_request.group_donations_manager" + sequence="30"> + + action="action_donation_stage" sequence="10" /> + action="action_donation_priority" sequence="30" /> + + diff --git a/odex25_donation/ensan_donation_request/views/product_public_category.xml b/odex25_donation/ensan_donation_request/views/product_public_category.xml new file mode 100644 index 000000000..66fa48e96 --- /dev/null +++ b/odex25_donation/ensan_donation_request/views/product_public_category.xml @@ -0,0 +1,34 @@ + + + + + view.public.category.from.inherit + product.public.category + + + + + + + + + + + + Categories + ir.actions.act_window + product.public.category + tree,form + + [('available_in_donation_request', '=', True)] + {'default_available_in_donation_request': True} + +

+ Define a new category +

+ Categories are used to browse your products through the + touchscreen interface. +

+
+
+