mirror of
https://github.com/bringout/oca-ocb-core.git
synced 2026-04-23 12:32:02 +02:00
Initial commit: Core packages
This commit is contained in:
commit
12c29a983b
9512 changed files with 8379910 additions and 0 deletions
4
odoo-bringout-oca-ocb-loyalty/loyalty/wizard/__init__.py
Normal file
4
odoo-bringout-oca-ocb-loyalty/loyalty/wizard/__init__.py
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import loyalty_generate_wizard
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo.osv import expression
|
||||
|
||||
class LoyaltyGenerateWizard(models.TransientModel):
|
||||
_name = 'loyalty.generate.wizard'
|
||||
_description = 'Generate Coupons'
|
||||
|
||||
program_id = fields.Many2one('loyalty.program', required=True, default=lambda self: self.env.context.get('active_id', False) or self.env.context.get('default_program_id', False))
|
||||
program_type = fields.Selection(related='program_id.program_type')
|
||||
|
||||
mode = fields.Selection([
|
||||
('anonymous', 'Anonymous Customers'),
|
||||
('selected', 'Selected Customers')],
|
||||
string='For', required=True, default='anonymous'
|
||||
)
|
||||
|
||||
customer_ids = fields.Many2many('res.partner', string='Customers')
|
||||
customer_tag_ids = fields.Many2many('res.partner.category', string='Customer Tags')
|
||||
|
||||
coupon_qty = fields.Integer('Quantity',
|
||||
compute='_compute_coupon_qty', readonly=False, store=True)
|
||||
points_granted = fields.Float('Grant', required=True, default=1)
|
||||
points_name = fields.Char(related='program_id.portal_point_name', readonly=True)
|
||||
valid_until = fields.Date()
|
||||
will_send_mail = fields.Boolean(compute='_compute_will_send_mail')
|
||||
|
||||
def _get_partners(self):
|
||||
self.ensure_one()
|
||||
if self.mode != 'selected':
|
||||
return self.env['res.partner']
|
||||
domain = []
|
||||
if self.customer_ids:
|
||||
domain = [('id', 'in', self.customer_ids.ids)]
|
||||
if self.customer_tag_ids:
|
||||
domain = expression.OR([domain, [('category_id', 'in', self.customer_tag_ids.ids)]])
|
||||
return self.env['res.partner'].search(domain)
|
||||
|
||||
@api.depends('customer_ids', 'customer_tag_ids', 'mode')
|
||||
def _compute_coupon_qty(self):
|
||||
for wizard in self:
|
||||
if wizard.mode == 'selected':
|
||||
wizard.coupon_qty = len(wizard._get_partners())
|
||||
else:
|
||||
wizard.coupon_qty = wizard.coupon_qty or 0
|
||||
|
||||
@api.depends("mode", "program_id")
|
||||
def _compute_will_send_mail(self):
|
||||
for wizard in self:
|
||||
wizard.will_send_mail = wizard.mode == 'selected' and 'create' in wizard.program_id.mapped('communication_plan_ids.trigger')
|
||||
|
||||
def _get_coupon_values(self, partner):
|
||||
self.ensure_one()
|
||||
return {
|
||||
'program_id': self.program_id.id,
|
||||
'points': self.points_granted,
|
||||
'expiration_date': self.valid_until,
|
||||
'partner_id': partner.id if self.mode == 'selected' else False,
|
||||
}
|
||||
|
||||
def generate_coupons(self):
|
||||
if any(not wizard.program_id for wizard in self):
|
||||
raise ValidationError(_("Can not generate coupon, no program is set."))
|
||||
if any(wizard.coupon_qty <= 0 for wizard in self):
|
||||
raise ValidationError(_("Invalid quantity."))
|
||||
coupon_create_vals = []
|
||||
for wizard in self:
|
||||
customers = wizard._get_partners() or range(wizard.coupon_qty)
|
||||
for partner in customers:
|
||||
coupon_create_vals.append(wizard._get_coupon_values(partner))
|
||||
self.env['loyalty.card'].create(coupon_create_vals)
|
||||
return True
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<record id="loyalty_generate_wizard_view_form" model="ir.ui.view">
|
||||
<field name="name">loyalty.generate.wizard.view.form</field>
|
||||
<field name="model">loyalty.generate.wizard</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Generate">
|
||||
<sheet>
|
||||
<group>
|
||||
<group>
|
||||
<field name="program_id" invisible="1"/>
|
||||
<field name="will_send_mail" invisible="1"/>
|
||||
<field name="program_type" invisible="1"/>
|
||||
<field name="mode" widget="radio" attrs="{'invisible': [('program_type', '=', 'ewallet')]}"/>
|
||||
<field name="customer_ids" widget="many2many_tags" attrs="{'invisible': [('mode', '=', 'anonymous')]}"/>
|
||||
<field name="customer_tag_ids" widget="many2many_tags" attrs="{'invisible': [('mode', '=', 'anonymous')]}" options="{'color_field': 'color'}"/>
|
||||
<field name="coupon_qty" string="Quantity to generate" attrs="{'readonly': [('mode', '=', 'selected')], 'required': [('mode', '=', 'anonymous')]}"/>
|
||||
<label string="Coupon value" for="points_granted" groups="base.group_no_one" attrs="{'invisible': [('program_type', '!=', 'coupons')]}"/>
|
||||
<span class="d-inline-block" groups="base.group_no_one" attrs="{'invisible': [('program_type', '!=', 'coupons')]}">
|
||||
<field name="points_granted" class="oe_inline"/>
|
||||
<field name="points_name" class="oe_inline"/>
|
||||
</span>
|
||||
<label string="Gift Card value" for="points_granted" attrs="{'invisible': [('program_type', '!=', 'gift_card')]}"/>
|
||||
<span class="d-inline-block" attrs="{'invisible': [('program_type', '!=', 'gift_card')]}">
|
||||
<field name="points_granted" class="w-auto oe_inline me-1"/>
|
||||
<field name="points_name" class="d-inline" no_label="1"/>
|
||||
</span>
|
||||
<label string="eWallet value" for="points_granted" attrs="{'invisible': [('program_type', '!=', 'ewallet')]}"/>
|
||||
<span class="d-inline-block" attrs="{'invisible': [('program_type', '!=', 'ewallet')]}">
|
||||
<field name="points_granted" class="w-auto oe_inline me-1"/>
|
||||
<field name="points_name" class="d-inline" no_label="1"/>
|
||||
</span>
|
||||
<field name="valid_until"/>
|
||||
</group>
|
||||
</group>
|
||||
</sheet>
|
||||
<footer>
|
||||
<button name="generate_coupons" type="object" class="btn-primary" data-hotkey="q">
|
||||
<span attrs="{'invisible': [('will_send_mail', '=', False)]}">
|
||||
Generate and Send
|
||||
</span>
|
||||
<span attrs="{'invisible': [('will_send_mail', '=', True)]}">
|
||||
Generate
|
||||
</span>
|
||||
<field name="program_type" nolabel="1"/>
|
||||
</button>
|
||||
<button special="cancel" data-hotkey="z" string="Cancel"/>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="loyalty_generate_wizard_action" model="ir.actions.act_window">
|
||||
<field name="name">Generate</field>
|
||||
<field name="res_model">loyalty.generate.wizard</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
</odoo>
|
||||
Loading…
Add table
Add a link
Reference in a new issue