odex25_standard/odex25_takaful/odex_takaful/models/takaful_conf.py

133 lines
5.4 KiB
Python

from odoo.exceptions import UserError , ValidationError
from odoo import api, fields, models, _
class DonationsItems(models.Model):
_name = "donations.items"
_description = "Donation Items"
name = fields.Char(string="Donation Name")
donation_type = fields.Selection([('donation', 'Donation'),('waqf', 'Waqf'),('sponsorship', 'Sponsorship'),], string='Donation Type')
branch_custom_id = fields.Many2one('branch.settings', string="Branch")
show_donation_item = fields.Boolean(string='Show Donation Item')
fixed_value = fields.Boolean(string='Is Fixed Value?')
fixed_donation_amount = fields.Float(string='Donation Amount')
currency_id = fields.Many2one('res.currency', string='Currency',
default=lambda self: self.env.company.currency_id, readonly=True)
account_id = fields.Many2one('account.account', string="Account",domain="[('user_type_id.id','=',13)]")
product_id = fields.Many2one('product.product', string="Product", domain="[('type', '=', 'service')]")
_quantity = fields.Float(default=0, store=True)
donation_types = fields.Selection([('donation', 'Donation'), ('waqf', 'Waqf')],string='Donation Type')
payment_method_id = fields.Many2one('takaful.payment.method', string="Payment Method")
@api.model
def create(self, vals):
"""Automatically create a product when a donation item is created"""
donation_item = super(DonationsItems, self).create(vals)
# Create a related product
product = self.env['product.product'].create({
'name': donation_item.name,
'type': 'service',
})
# Link the created product to the donation item
donation_item.product_id = product.id
return donation_item
@api.onchange('name')
def _onchange_name(self):
"""Update the related product name when the donation item name changes"""
if self.product_id:
self.product_id.name = self.name
def add_payment_method(self):
return {
'type': 'ir.actions.act_window',
'name': _('Add Details Wizard'),
'res_model': 'add.details.wiz',
'view_mode': 'form',
'target': 'new',
}
def utilizable_cart_details(self):
"""
Utilizable Cart Details For Remove , Add And Update Operations
For Cart To Product Catelog Module To Object addcart.sales.products
"""
context = self._context.copy() or {}
cart_object = self.env["donations.details.lines"]
cart_details = dict()
total_count = cart_object.search_count(
[('donation_name', '=', self.id), ('sponsorship_id', '=', context.get('sponsorship_id'))]) # , ("cart_flag", "=", True)
cart_details["total_count"] = total_count
cart_data = cart_object.search(
[('donation_name', '=', self.id), ('sponsorship_id', '=', context.get('sponsorship_id'))]) # , ("cart_flag", "=", True)
cart_details["cart_data"] = cart_data
return cart_details
def initiate_sol(self, operation, sponsorship_id):
"""
Initiate Donation Details Lines By Cart Functionality.
"""
so_object = self.env["takaful.sponsorship"]
sale_object = so_object.search([("id", "=", sponsorship_id)])
if operation == "add":
so_object.sol_by_cart(operation, self, sale_object)
elif operation == "remove":
so_object.sol_by_cart(operation, self, sale_object)
elif operation == "update":
so_object.sol_by_cart(operation, self, sale_object)
def set_quantity_so(self, quantity, operation=None):
context = self._context.copy() or {}
cart_details = self.utilizable_cart_details()
if operation == "remove":
self._quantity -= quantity
if cart_details.get("total_count") != 0:
self.initiate_sol("remove", context.get("sponsorship_id"))
else:
if self._quantity == 0:
self._quantity += quantity
if cart_details.get("total_count") != 0:
self.initiate_sol("update", context.get("sponsorship_id"))
else:
self.initiate_sol("add", context.get("sponsorship_id"))
def remove_quantity_button_so(self):
if self._quantity == 0:
self._quantity = 0
return
return self.set_quantity_so(1, operation="remove")
def add_quantity_button_so(self):
return self.set_quantity_so(1, operation="add")
class PointsOfSaleCustom(models.Model):
_name = "points.of.sale.custom"
_description = "Points Of Sale Custom"
name = fields.Char(string="Sequence/Point Name",readonly=True)
department_name = fields.Selection([('men', 'Men'),('women', 'Women')], string='Department Name')
branch_custom_ids = fields.Many2many('branch.settings',relation='points_sale_branch_settings_rel',column1='points_sale_id', column2='branch_id',string="Branch")
journal_id = fields.Many2one('account.journal', string="Journal",domain="[('type','=','bank')]")
@api.model
def create(self, vals):
res = super(PointsOfSaleCustom, self).create(vals)
if not res.name or res.name == _('New'):
res.name = self.env['ir.sequence'].sudo().next_by_code('point.of.sale.sequence') or _('New')
return res
class RefundReason(models.Model):
_name = "refund.reasons"
_description = "Refund Reason"
name = fields.Char(string="Name")