mirror of
https://gitlab.com/sonalarora/tra_backend.git
synced 2025-12-17 10:19:09 +02:00
add gym module
This commit is contained in:
24
gym/models/__init__.py
Normal file
24
gym/models/__init__.py
Normal file
@@ -0,0 +1,24 @@
|
||||
# See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import member
|
||||
from . import trainer
|
||||
from . import product_template
|
||||
from . import membership
|
||||
from . import diet
|
||||
from . import workout
|
||||
from . import lead
|
||||
from . import company
|
||||
from . import gym_skills
|
||||
from . import project_task
|
||||
from . import sale
|
||||
from . import calendar_event
|
||||
from . import project_document
|
||||
from . import project_document_case
|
||||
from . import project_document_category
|
||||
from . import project_document_group
|
||||
from . import project_document_name
|
||||
from . import project_document_opposite
|
||||
from . import project_other
|
||||
from . import account_analytic_account
|
||||
from . import res_partner_credit_card
|
||||
from . import res_partner_credit_card_type
|
||||
BIN
gym/models/__pycache__/__init__.cpython-36.pyc
Normal file
BIN
gym/models/__pycache__/__init__.cpython-36.pyc
Normal file
Binary file not shown.
BIN
gym/models/__pycache__/__init__.cpython-37.pyc
Normal file
BIN
gym/models/__pycache__/__init__.cpython-37.pyc
Normal file
Binary file not shown.
BIN
gym/models/__pycache__/account_analytic_account.cpython-36.pyc
Normal file
BIN
gym/models/__pycache__/account_analytic_account.cpython-36.pyc
Normal file
Binary file not shown.
BIN
gym/models/__pycache__/account_analytic_account.cpython-37.pyc
Normal file
BIN
gym/models/__pycache__/account_analytic_account.cpython-37.pyc
Normal file
Binary file not shown.
BIN
gym/models/__pycache__/calendar_event.cpython-36.pyc
Normal file
BIN
gym/models/__pycache__/calendar_event.cpython-36.pyc
Normal file
Binary file not shown.
BIN
gym/models/__pycache__/calendar_event.cpython-37.pyc
Normal file
BIN
gym/models/__pycache__/calendar_event.cpython-37.pyc
Normal file
Binary file not shown.
BIN
gym/models/__pycache__/company.cpython-36.pyc
Normal file
BIN
gym/models/__pycache__/company.cpython-36.pyc
Normal file
Binary file not shown.
BIN
gym/models/__pycache__/company.cpython-37.pyc
Normal file
BIN
gym/models/__pycache__/company.cpython-37.pyc
Normal file
Binary file not shown.
BIN
gym/models/__pycache__/diet.cpython-36.pyc
Normal file
BIN
gym/models/__pycache__/diet.cpython-36.pyc
Normal file
Binary file not shown.
BIN
gym/models/__pycache__/diet.cpython-37.pyc
Normal file
BIN
gym/models/__pycache__/diet.cpython-37.pyc
Normal file
Binary file not shown.
BIN
gym/models/__pycache__/gym_skills.cpython-36.pyc
Normal file
BIN
gym/models/__pycache__/gym_skills.cpython-36.pyc
Normal file
Binary file not shown.
BIN
gym/models/__pycache__/gym_skills.cpython-37.pyc
Normal file
BIN
gym/models/__pycache__/gym_skills.cpython-37.pyc
Normal file
Binary file not shown.
BIN
gym/models/__pycache__/lead.cpython-36.pyc
Normal file
BIN
gym/models/__pycache__/lead.cpython-36.pyc
Normal file
Binary file not shown.
BIN
gym/models/__pycache__/lead.cpython-37.pyc
Normal file
BIN
gym/models/__pycache__/lead.cpython-37.pyc
Normal file
Binary file not shown.
BIN
gym/models/__pycache__/member.cpython-36.pyc
Normal file
BIN
gym/models/__pycache__/member.cpython-36.pyc
Normal file
Binary file not shown.
BIN
gym/models/__pycache__/member.cpython-37.pyc
Normal file
BIN
gym/models/__pycache__/member.cpython-37.pyc
Normal file
Binary file not shown.
BIN
gym/models/__pycache__/membership.cpython-36.pyc
Normal file
BIN
gym/models/__pycache__/membership.cpython-36.pyc
Normal file
Binary file not shown.
BIN
gym/models/__pycache__/membership.cpython-37.pyc
Normal file
BIN
gym/models/__pycache__/membership.cpython-37.pyc
Normal file
Binary file not shown.
BIN
gym/models/__pycache__/product_template.cpython-36.pyc
Normal file
BIN
gym/models/__pycache__/product_template.cpython-36.pyc
Normal file
Binary file not shown.
BIN
gym/models/__pycache__/product_template.cpython-37.pyc
Normal file
BIN
gym/models/__pycache__/product_template.cpython-37.pyc
Normal file
Binary file not shown.
BIN
gym/models/__pycache__/project_document.cpython-36.pyc
Normal file
BIN
gym/models/__pycache__/project_document.cpython-36.pyc
Normal file
Binary file not shown.
BIN
gym/models/__pycache__/project_document.cpython-37.pyc
Normal file
BIN
gym/models/__pycache__/project_document.cpython-37.pyc
Normal file
Binary file not shown.
BIN
gym/models/__pycache__/project_document_case.cpython-36.pyc
Normal file
BIN
gym/models/__pycache__/project_document_case.cpython-36.pyc
Normal file
Binary file not shown.
BIN
gym/models/__pycache__/project_document_case.cpython-37.pyc
Normal file
BIN
gym/models/__pycache__/project_document_case.cpython-37.pyc
Normal file
Binary file not shown.
BIN
gym/models/__pycache__/project_document_category.cpython-36.pyc
Normal file
BIN
gym/models/__pycache__/project_document_category.cpython-36.pyc
Normal file
Binary file not shown.
BIN
gym/models/__pycache__/project_document_category.cpython-37.pyc
Normal file
BIN
gym/models/__pycache__/project_document_category.cpython-37.pyc
Normal file
Binary file not shown.
BIN
gym/models/__pycache__/project_document_group.cpython-36.pyc
Normal file
BIN
gym/models/__pycache__/project_document_group.cpython-36.pyc
Normal file
Binary file not shown.
BIN
gym/models/__pycache__/project_document_group.cpython-37.pyc
Normal file
BIN
gym/models/__pycache__/project_document_group.cpython-37.pyc
Normal file
Binary file not shown.
BIN
gym/models/__pycache__/project_document_name.cpython-36.pyc
Normal file
BIN
gym/models/__pycache__/project_document_name.cpython-36.pyc
Normal file
Binary file not shown.
BIN
gym/models/__pycache__/project_document_name.cpython-37.pyc
Normal file
BIN
gym/models/__pycache__/project_document_name.cpython-37.pyc
Normal file
Binary file not shown.
BIN
gym/models/__pycache__/project_document_opposite.cpython-36.pyc
Normal file
BIN
gym/models/__pycache__/project_document_opposite.cpython-36.pyc
Normal file
Binary file not shown.
BIN
gym/models/__pycache__/project_document_opposite.cpython-37.pyc
Normal file
BIN
gym/models/__pycache__/project_document_opposite.cpython-37.pyc
Normal file
Binary file not shown.
BIN
gym/models/__pycache__/project_other.cpython-36.pyc
Normal file
BIN
gym/models/__pycache__/project_other.cpython-36.pyc
Normal file
Binary file not shown.
BIN
gym/models/__pycache__/project_other.cpython-37.pyc
Normal file
BIN
gym/models/__pycache__/project_other.cpython-37.pyc
Normal file
Binary file not shown.
BIN
gym/models/__pycache__/project_task.cpython-36.pyc
Normal file
BIN
gym/models/__pycache__/project_task.cpython-36.pyc
Normal file
Binary file not shown.
BIN
gym/models/__pycache__/project_task.cpython-37.pyc
Normal file
BIN
gym/models/__pycache__/project_task.cpython-37.pyc
Normal file
Binary file not shown.
BIN
gym/models/__pycache__/res_partner_credit_card.cpython-36.pyc
Normal file
BIN
gym/models/__pycache__/res_partner_credit_card.cpython-36.pyc
Normal file
Binary file not shown.
BIN
gym/models/__pycache__/res_partner_credit_card.cpython-37.pyc
Normal file
BIN
gym/models/__pycache__/res_partner_credit_card.cpython-37.pyc
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
gym/models/__pycache__/sale.cpython-36.pyc
Normal file
BIN
gym/models/__pycache__/sale.cpython-36.pyc
Normal file
Binary file not shown.
BIN
gym/models/__pycache__/sale.cpython-37.pyc
Normal file
BIN
gym/models/__pycache__/sale.cpython-37.pyc
Normal file
Binary file not shown.
BIN
gym/models/__pycache__/trainer.cpython-36.pyc
Normal file
BIN
gym/models/__pycache__/trainer.cpython-36.pyc
Normal file
Binary file not shown.
BIN
gym/models/__pycache__/trainer.cpython-37.pyc
Normal file
BIN
gym/models/__pycache__/trainer.cpython-37.pyc
Normal file
Binary file not shown.
BIN
gym/models/__pycache__/workout.cpython-36.pyc
Normal file
BIN
gym/models/__pycache__/workout.cpython-36.pyc
Normal file
Binary file not shown.
BIN
gym/models/__pycache__/workout.cpython-37.pyc
Normal file
BIN
gym/models/__pycache__/workout.cpython-37.pyc
Normal file
Binary file not shown.
23
gym/models/account_analytic_account.py
Normal file
23
gym/models/account_analytic_account.py
Normal file
@@ -0,0 +1,23 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from odoo import fields, models,api
|
||||
|
||||
|
||||
class AccountAnalyticAccount(models.Model):
|
||||
_inherit = 'account.analytic.account'
|
||||
|
||||
|
||||
is_location = fields.Boolean(
|
||||
string='Is Location',
|
||||
compute='compute_is_location',
|
||||
store=True
|
||||
)
|
||||
|
||||
|
||||
@api.depends('group_id')
|
||||
def compute_is_location(self):
|
||||
for record in self:
|
||||
if record.group_id.name=='Location':
|
||||
record.is_location=True
|
||||
else:
|
||||
record.is_location=False
|
||||
15
gym/models/calendar_event.py
Normal file
15
gym/models/calendar_event.py
Normal file
@@ -0,0 +1,15 @@
|
||||
# See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, models
|
||||
|
||||
|
||||
class CalendarEvent(models.Model):
|
||||
|
||||
_inherit = 'calendar.event'
|
||||
|
||||
@api.model
|
||||
def inactive_rule(self):
|
||||
rule_rec = self.env.ref('calendar.calendar_event_rule_employee',
|
||||
raise_if_not_found=False)
|
||||
if rule_rec and rule_rec.active:
|
||||
rule_rec.active = False
|
||||
20
gym/models/company.py
Normal file
20
gym/models/company.py
Normal file
@@ -0,0 +1,20 @@
|
||||
# See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class ResCompany(models.Model):
|
||||
_inherit = 'res.company'
|
||||
|
||||
default_password = fields.Char('Password', default='gym',
|
||||
help="""This will be used as a
|
||||
default password when a
|
||||
user gets automatically created
|
||||
when an employee is created!""")
|
||||
default_umo_of_height_id = fields.Many2one('uom.uom',
|
||||
string='Unit of Height')
|
||||
default_umo_of_weight_id = fields.Many2one('uom.uom',
|
||||
string='Unit of Weight')
|
||||
default_umo_of_measure_id = fields.Many2one('uom.uom',
|
||||
string='Unit of Body Part '
|
||||
'Measurement')
|
||||
46
gym/models/diet.py
Normal file
46
gym/models/diet.py
Normal file
@@ -0,0 +1,46 @@
|
||||
# See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class DietPlan(models.Model):
|
||||
"""Model for creating diet plan."""
|
||||
|
||||
_name = 'diet.plan'
|
||||
_description = "Model for creating diet plan"
|
||||
|
||||
name = fields.Char('Name')
|
||||
diet_plans_ids = fields.One2many('diet.plan.lines', 'plan_id', 'Plans')
|
||||
|
||||
|
||||
class DietPlanLines(models.Model):
|
||||
"""Model for add interval and food item in diet plan."""
|
||||
|
||||
_name = 'diet.plan.lines'
|
||||
_description = "Diet Plan Lines"
|
||||
|
||||
interval = fields.Selection([('early_morning', 'Early Morning'),
|
||||
('breakfast', 'Breakfast'),
|
||||
('pre_lunch', 'Pre Lunch'),
|
||||
('lunch', 'Lunch'),
|
||||
('snack', 'Snack'),
|
||||
('dinner', 'Dinner')],
|
||||
'Interval',
|
||||
help='Interval for Eating the food')
|
||||
plan_id = fields.Many2one('diet.plan', 'Plans')
|
||||
food_item_ids = fields.One2many('food.item', 'food_id', 'Food Items',
|
||||
help='Foods and interval')
|
||||
|
||||
|
||||
class FoodItem(models.Model):
|
||||
"""Model for adding food item in diet plan."""
|
||||
|
||||
_name = 'food.item'
|
||||
_description = "Food Item"
|
||||
|
||||
food_name_id = fields.Many2one('product.template', 'Food Item')
|
||||
quantity = fields.Integer(string='Qty', help='Quantity of Food Items')
|
||||
food_id = fields.Many2one('diet.plan.lines', 'Food Items',
|
||||
help='Select Food Items')
|
||||
measure_unit_id = fields.Many2one('uom.uom', string='Measurement Unit',
|
||||
help='Measurement Unit for Food item')
|
||||
11
gym/models/gym_skills.py
Normal file
11
gym/models/gym_skills.py
Normal file
@@ -0,0 +1,11 @@
|
||||
# See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class GymSkills(models.Model):
|
||||
_name = 'gym.skills'
|
||||
_description = "Gym Skills"
|
||||
|
||||
name = fields.Char('Skill', required=True)
|
||||
code = fields.Char('Code')
|
||||
15
gym/models/lead.py
Normal file
15
gym/models/lead.py
Normal file
@@ -0,0 +1,15 @@
|
||||
# See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import models
|
||||
|
||||
|
||||
class CrmLead(models.Model):
|
||||
_inherit = 'crm.lead'
|
||||
|
||||
def _lead_create_contact(self, name, is_company, parent_id=False):
|
||||
res = super(CrmLead, self)._lead_create_contact(name, is_company,
|
||||
parent_id=parent_id)
|
||||
for lead in res:
|
||||
lead.customer = True
|
||||
lead.is_member = True
|
||||
return res
|
||||
325
gym/models/member.py
Normal file
325
gym/models/member.py
Normal file
@@ -0,0 +1,325 @@
|
||||
# See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from datetime import date
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class ResUsers(models.Model):
|
||||
"""Users's detail."""
|
||||
|
||||
_inherit = 'res.users'
|
||||
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
return super(ResUsers,
|
||||
self.with_context(is_create_user=True)).create(vals)
|
||||
|
||||
|
||||
class MemberDetail(models.Model):
|
||||
"""Member's detail."""
|
||||
|
||||
_inherit = 'res.partner'
|
||||
|
||||
is_member = fields.Boolean(string='Is member ?',
|
||||
default=lambda self: self.env.context.
|
||||
get('member_default', False))
|
||||
is_operator = fields.Boolean(string='Operator')
|
||||
gender = fields.Selection([('male', 'Male'), ('female', 'Female')],
|
||||
string='Gender', default='male')
|
||||
occupation = fields.Char('Occupation')
|
||||
reg_no = fields.Char('Member ID', copy=False,
|
||||
help='Registration Number of Member')
|
||||
member_measurement_ids = fields.One2many('body.measurement', 'partner_id',
|
||||
'Measurement History',
|
||||
help='Body Measurement History '
|
||||
'of the Member')
|
||||
birthdate = fields.Date('Date of Birth')
|
||||
age = fields.Float(compute='_compute_calculate_age', string='Age',store=True)
|
||||
measurements = fields.Integer(compute="_compute_cal_total_measurement",
|
||||
string="Total measurement")
|
||||
membership = fields.Integer(compute="_compute_cal_total_membership",
|
||||
string="Total membership")
|
||||
user_id = fields.Many2one('res.users', copy=False, string='User',
|
||||
ondelete="cascade")
|
||||
email = fields.Char(copy=False)
|
||||
|
||||
document_ids = fields.One2many(
|
||||
comodel_name='project.document',
|
||||
inverse_name="partner_id",
|
||||
string='Documents',
|
||||
)
|
||||
|
||||
document_opposite_ids = fields.One2many(
|
||||
comodel_name='project.document.opposite',
|
||||
inverse_name='partner_id',
|
||||
string='Opposite Party Documents',
|
||||
)
|
||||
|
||||
document_case_ids = fields.One2many(
|
||||
comodel_name='project.document.case',
|
||||
inverse_name='partner_id',
|
||||
string='Case Related Documents',
|
||||
)
|
||||
|
||||
docuemnt_other_ids = fields.One2many(
|
||||
comodel_name='project.document.other',
|
||||
inverse_name='partner_id',
|
||||
string='Other Documents',
|
||||
)
|
||||
|
||||
membership_number = fields.Char(
|
||||
string='Membership No',
|
||||
default='New'
|
||||
)
|
||||
|
||||
account_manager_id = fields.Many2one(
|
||||
comodel_name='res.users',
|
||||
string='Account Manager',
|
||||
)
|
||||
|
||||
analytic_id = fields.Many2one(
|
||||
comodel_name='account.analytic.account',
|
||||
string="Home Club"
|
||||
)
|
||||
|
||||
home_club = fields.Char(
|
||||
string='Home Clubs',
|
||||
)
|
||||
|
||||
nationality_id = fields.Many2one(
|
||||
comodel_name='res.country',
|
||||
string='Nationality',
|
||||
)
|
||||
|
||||
marketing_source = fields.Char(
|
||||
string='Marketing Source',
|
||||
)
|
||||
|
||||
referred_by_id = fields.Many2one(
|
||||
comodel_name='res.users',
|
||||
string='Referred By',
|
||||
)
|
||||
|
||||
emirate_number = fields.Char(
|
||||
string='Emirates ID',
|
||||
)
|
||||
|
||||
passport_number = fields.Char(
|
||||
string='Passport Number',
|
||||
)
|
||||
|
||||
credit_card_ids = fields.One2many(
|
||||
comodel_name='res.partner.credit.card',
|
||||
inverse_name='partner_id',
|
||||
string='Credit Cards',
|
||||
)
|
||||
|
||||
def unlink(self):
|
||||
for rec in self:
|
||||
user_id = rec.user_id
|
||||
rec.user_id = False
|
||||
user_id.unlink()
|
||||
return super(MemberDetail, self).unlink()
|
||||
|
||||
@api.model
|
||||
def inactive_rule(self):
|
||||
rule_rec = self.env.ref('base.res_partner_rule_private_employee',
|
||||
raise_if_not_found=False)
|
||||
if rule_rec and rule_rec.active:
|
||||
rule_rec.active = False
|
||||
|
||||
@api.constrains('birthdate')
|
||||
def _check_birthdate(self):
|
||||
"""Check birth date of Member."""
|
||||
if self.birthdate and self.birthdate >= date.today():
|
||||
raise ValidationError(_("Birth date must be less than today's"
|
||||
" date."))
|
||||
|
||||
def _compute_cal_total_measurement(self):
|
||||
"""Measurement history count."""
|
||||
for partner_rec in self:
|
||||
partner_rec.measurements = \
|
||||
partner_rec.member_measurement_ids and len(
|
||||
partner_rec.member_measurement_ids.ids)
|
||||
|
||||
def _compute_cal_total_membership(self):
|
||||
"""Count no of membership of the member."""
|
||||
for partner_rec in self:
|
||||
partner_rec.membership = \
|
||||
partner_rec.member_lines and len(
|
||||
partner_rec.member_lines.ids)
|
||||
|
||||
@api.depends('birthdate')
|
||||
def _compute_calculate_age(self):
|
||||
"""Age calculation of member."""
|
||||
for partner_rec in self:
|
||||
partner_rec.age = \
|
||||
partner_rec.birthdate and \
|
||||
date.today().year - partner_rec.birthdate.year
|
||||
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
"""Create sequence of member."""
|
||||
rec = super(MemberDetail, self).create(vals)
|
||||
if vals.get('name'):
|
||||
vals['reg_no'] = self.env[
|
||||
'ir.sequence'].next_by_code('res.partner')
|
||||
if vals.get('is_member'):
|
||||
if rec.membership_number=='New':
|
||||
rec.membership_number= self.env[
|
||||
'ir.sequence'].next_by_code('membership.number')
|
||||
if not self.env['res.users']._context.get('is_create_user'):
|
||||
rec.user_id = self.env['res.users'].sudo().create({
|
||||
'name': rec.name,
|
||||
'login': rec.email,
|
||||
'partner_id': rec.id,
|
||||
'password': rec.company_id.default_password or '',
|
||||
'groups_id': [(6, 0, [self.env.ref(
|
||||
'gym.group_gym_member').id])]
|
||||
}).id
|
||||
return rec
|
||||
|
||||
def open_user(self):
|
||||
"""
|
||||
This Method is used to Open User from member record.
|
||||
@param self: The object pointer
|
||||
"""
|
||||
# Created res users in open
|
||||
return {
|
||||
'view_type': 'form',
|
||||
'view_id': self.env.ref('base.view_users_form').id,
|
||||
'view_mode': 'form',
|
||||
'res_model': 'res.users',
|
||||
'res_id': self.user_id.id,
|
||||
'type': 'ir.actions.act_window'
|
||||
}
|
||||
|
||||
|
||||
class BodyMeasurement(models.Model):
|
||||
"""Body Measurement of the Member."""
|
||||
|
||||
_name = 'body.measurement'
|
||||
_description = "Body Measurement"
|
||||
_rec_name = 'partner_id'
|
||||
|
||||
partner_id = fields.Many2one('res.partner', 'Member')
|
||||
date = fields.Date('Date', required=True)
|
||||
neck = fields.Float('Neck')
|
||||
umo_neck_id = fields.Many2one(
|
||||
'uom.uom', string='Measurement Unit',
|
||||
domain=lambda self: [('category_id', '=',
|
||||
self.env.ref('uom.uom_categ_length').id)])
|
||||
chest = fields.Float('Chest')
|
||||
umo_chest_id = fields.Many2one(
|
||||
'uom.uom', string='Measurement Unit for Chest',
|
||||
domain=lambda self: [('category_id', '=',
|
||||
self.env.ref('uom.uom_categ_length').id)])
|
||||
biceps = fields.Float('Biceps')
|
||||
umo_biceps_id = fields.Many2one(
|
||||
'uom.uom', string='Measurement Unit Biceps',
|
||||
domain=lambda self: [('category_id', '=',
|
||||
self.env.ref('uom.uom_categ_length').id)])
|
||||
waist = fields.Float('Waist')
|
||||
umo_waist_id = fields.Many2one(
|
||||
'uom.uom', string='Measurement Unit Waist',
|
||||
domain=lambda self: [('category_id', '=',
|
||||
self.env.ref('uom.uom_categ_length').id)])
|
||||
hips = fields.Float('Hips')
|
||||
umo_hips_id = fields.Many2one(
|
||||
'uom.uom', string='Measurement Unit Hips',
|
||||
domain=lambda self: [('category_id', '=',
|
||||
self.env.ref('uom.uom_categ_length').id)])
|
||||
thigh = fields.Float('Thighs')
|
||||
umo_thigh_id = fields.Many2one(
|
||||
'uom.uom', string='Measurement Unit Thigh',
|
||||
domain=lambda self: [('category_id', '=',
|
||||
self.env.ref('uom.uom_categ_length').id)])
|
||||
calf = fields.Float('Calf')
|
||||
umo_calf_id = fields.Many2one(
|
||||
'uom.uom', string='Measurement Unit Calf',
|
||||
domain=lambda self: [('category_id', '=',
|
||||
self.env.ref('uom.uom_categ_length').id)])
|
||||
weight = fields.Float('Weight')
|
||||
umo_weight_id = fields.Many2one(
|
||||
'uom.uom', string='Measurement Unit Weight',
|
||||
domain=lambda self: [('category_id', '=',
|
||||
self.env.ref('uom.product_uom_categ_kgm').id)])
|
||||
height = fields.Float('Height')
|
||||
umo_height_id = fields.Many2one(
|
||||
'uom.uom', string='Measurement Unit Height',
|
||||
domain=lambda self: [('category_id', '=',
|
||||
self.env.ref('uom.uom_categ_length').id)])
|
||||
bmi = fields.Float(
|
||||
compute='_compute_bmi',
|
||||
string='BMI',
|
||||
default=0.0,
|
||||
help='Used for Body mass index Calculation')
|
||||
bmr = fields.Float(string='BMR', compute='_compute_bmr',
|
||||
help='Used for Body Metabolic rate Calculation')
|
||||
|
||||
image_128 = fields.Binary(
|
||||
related='partner_id.image_128',
|
||||
)
|
||||
|
||||
@api.model
|
||||
def default_get(self, fields):
|
||||
res = super(BodyMeasurement, self).default_get(fields)
|
||||
height_uom = self.env.user.company_id and\
|
||||
self.env.user.company_id.default_umo_of_height_id
|
||||
weight_uom = self.env.user.company_id and\
|
||||
self.env.user.company_id.default_umo_of_weight_id
|
||||
body_pary_uom = self.env.user.company_id and\
|
||||
self.env.user.company_id.default_umo_of_measure_id
|
||||
|
||||
res.update({
|
||||
'umo_weight_id': weight_uom.id,
|
||||
'umo_height_id': height_uom.id,
|
||||
'umo_calf_id': body_pary_uom.id,
|
||||
'umo_thigh_id': body_pary_uom.id,
|
||||
'umo_hips_id': body_pary_uom.id,
|
||||
'umo_waist_id': body_pary_uom.id,
|
||||
'umo_biceps_id': body_pary_uom.id,
|
||||
'umo_chest_id': body_pary_uom.id,
|
||||
'umo_neck_id': body_pary_uom.id,
|
||||
})
|
||||
return res
|
||||
|
||||
@api.depends('height', 'weight')
|
||||
def _compute_bmi(self):
|
||||
"""Calculation of the Body mass index."""
|
||||
bmi = 0
|
||||
for rec in self.filtered(
|
||||
lambda rec: rec.height and rec.weight):
|
||||
bmi = rec.weight / (rec.height * rec.height)
|
||||
self.bmi = bmi
|
||||
|
||||
@api.depends('height', 'weight', 'partner_id.age')
|
||||
def _compute_bmr(self):
|
||||
"""Calculation of the Basal metabolic rate."""
|
||||
bmr = 0
|
||||
for measurement_rec in self.filtered(
|
||||
lambda measurement_rec: measurement_rec.height and
|
||||
measurement_rec.weight):
|
||||
bmr = 66.47 + (13.75 * measurement_rec.weight) \
|
||||
+ (5.0 * measurement_rec.height) \
|
||||
- (6.75 * measurement_rec.partner_id.age)
|
||||
self.bmr = bmr
|
||||
|
||||
|
||||
class BodyPart(models.Model):
|
||||
_name = 'body.part'
|
||||
_description = "Body Part"
|
||||
|
||||
name = fields.Char('Body part')
|
||||
|
||||
|
||||
class PedoMeter(models.Model):
|
||||
"""Model for pedo meter."""
|
||||
|
||||
_name = 'pedo.meter'
|
||||
_description = "Pedo Meter"
|
||||
|
||||
partner_id = fields.Many2one('res.partner', 'Pedometer')
|
||||
date = fields.Date('Date', required=True)
|
||||
steps = fields.Integer('Steps', required=True)
|
||||
207
gym/models/membership.py
Normal file
207
gym/models/membership.py
Normal file
@@ -0,0 +1,207 @@
|
||||
# See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from datetime import date
|
||||
from dateutil.relativedelta import relativedelta
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class MembershipInvoice(models.TransientModel):
|
||||
"""Membership Invoice Wizard."""
|
||||
|
||||
_inherit = 'membership.invoice'
|
||||
|
||||
product_id = fields.Many2one('product.product',
|
||||
string='Membership', help='Membership plan')
|
||||
membership_plan_id = fields.Many2one('product.template', 'Membership Plan',
|
||||
help='Selection of membership plan '
|
||||
'in membership invoice')
|
||||
|
||||
|
||||
class MembershipPlanMain(models.Model):
|
||||
"""Inherited Membership line object for membership records."""
|
||||
|
||||
_inherit = 'membership.membership_line'
|
||||
|
||||
membership_id = fields.Many2one('product.product',
|
||||
string="Membership Scheme",
|
||||
required=True)
|
||||
end_date = fields.Date('End Date', help='End date of the Membership')
|
||||
states = fields.Selection([('draft', 'Draft'),
|
||||
('confirm', 'Confirmed'),
|
||||
('expire', 'Expired'),
|
||||
('cancel', 'Cancelled')],
|
||||
string='Status',
|
||||
default='draft')
|
||||
plan_sequence = fields.Char('Plan ID',
|
||||
help='Sequence of the Membership Plan')
|
||||
sale_order_id = fields.Many2one('sale.order', 'Order',
|
||||
readonly=True, copy=False,
|
||||
help='Store the Reference of the sale'
|
||||
' order')
|
||||
paid_amount = fields.Float('Paid Amount', store=True,
|
||||
compute='_compute_get_paid_amount')
|
||||
|
||||
@api.depends('sale_order_id.invoice_ids.amount_residual')
|
||||
def _compute_get_paid_amount(self):
|
||||
for rec in self:
|
||||
amount_total = 0
|
||||
for inv in rec.sale_order_id.invoice_ids.filtered(
|
||||
lambda inv: inv.state != 'draft'):
|
||||
amount_total += (inv.amount_total - inv.amount_residual)
|
||||
rec.paid_amount = amount_total
|
||||
|
||||
@api.onchange('membership_id')
|
||||
def _onchange_membership_id(self):
|
||||
self.member_price = self.membership_id.list_price
|
||||
|
||||
@api.constrains('date', 'end_date', 'partner', 'membership_id')
|
||||
def _check_time(self):
|
||||
"""Start and End date validation."""
|
||||
if self.date and self.end_date and self.date >= self.end_date:
|
||||
raise ValidationError(_("End date must be greater "
|
||||
"than the start date."))
|
||||
membership_ids = self.search([
|
||||
('partner', '=', self.partner.id),
|
||||
('membership_id', '=', self.membership_id.id),
|
||||
'|', '&',
|
||||
('date', '<=', self.date),
|
||||
'&', ('end_date', '>=', self.date),
|
||||
('date', '<', self.end_date),
|
||||
'&', ('date', '<', self.end_date),
|
||||
('end_date', '>', self.date),
|
||||
('id', '!=', self.id)])
|
||||
if membership_ids:
|
||||
raise ValidationError(_("You can not create membership, This "
|
||||
"membership is already created."))
|
||||
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
"""Sequence of Membership record."""
|
||||
if vals.get('partner'):
|
||||
vals['plan_sequence'] = self.env[
|
||||
'ir.sequence'].next_by_code('membership.membership_line')
|
||||
return super(MembershipPlanMain, self).create(vals)
|
||||
|
||||
def unlink(self):
|
||||
for mem_rec in self:
|
||||
if mem_rec.states == 'confirm':
|
||||
raise ValidationError(
|
||||
_("Sorry, you can't delete a confirmed membership."))
|
||||
return super(MembershipPlanMain, self).unlink()
|
||||
|
||||
def copy(self, default=None):
|
||||
for mem_rec in self:
|
||||
if mem_rec.states == 'confirm':
|
||||
raise ValidationError(
|
||||
_("Sorry, you can't duplicate a confirmed membership."))
|
||||
return super(MembershipPlanMain, self).copy(default)
|
||||
|
||||
def action_draft(self):
|
||||
"""Set the Membership to draft."""
|
||||
for mem_rec in self:
|
||||
mem_rec.states = "draft"
|
||||
|
||||
def action_cancel(self):
|
||||
"""Set the Membership to cancelled."""
|
||||
for mem_rec in self:
|
||||
mem_rec.states = "cancel"
|
||||
|
||||
def action_confirm(self):
|
||||
"""Set the Membership to confirmed."""
|
||||
for mem_rec in self:
|
||||
sale_order_id = self.env['sale.order'].with_context(
|
||||
is_membership_created=True).create(
|
||||
{'partner_id': mem_rec.partner.id,
|
||||
'membership': True,
|
||||
'start_date': mem_rec.date,
|
||||
'end_date': mem_rec.end_date,
|
||||
'order_line': [(0, 0,
|
||||
{'product_id': mem_rec.membership_id.id,
|
||||
'price_unit': mem_rec.member_price})]})
|
||||
sale_order_id.action_confirm()
|
||||
mem_rec.write({'states': 'confirm',
|
||||
'sale_order_id': sale_order_id.id})
|
||||
|
||||
def action_expire(self):
|
||||
"""Set the Membership to expired."""
|
||||
for mem_rec in self:
|
||||
mem_rec.states = "expire"
|
||||
|
||||
@api.model
|
||||
def check_membership_validity(self):
|
||||
"""Method for calculating the remaining days of Membership and gives
|
||||
notification of membership Expiration.
|
||||
"""
|
||||
user_rec = self.env.user
|
||||
curr_day = date.today()
|
||||
# searching on membership.membership_line
|
||||
membership_line = self.search(
|
||||
['|', ('end_date', '<', curr_day), '&',
|
||||
('end_date', '>=', curr_day),
|
||||
'&',
|
||||
('end_date', '<=', curr_day + relativedelta(days=7)),
|
||||
('states', 'in', ['confirm'])])
|
||||
# loop on membership.membership_line
|
||||
for membership_rec in membership_line:
|
||||
# fetching email of member.
|
||||
if membership_rec.partner.email:
|
||||
# template for email
|
||||
template = self.env.ref('gym.membership_expiration')
|
||||
end_dt = membership_rec.end_date
|
||||
remain_days = end_dt - curr_day
|
||||
due_days = str(max(0, remain_days.days))
|
||||
# Setting the membership state to expire if days are 0
|
||||
if remain_days.days <= 0:
|
||||
membership_rec.action_expire()
|
||||
# Email content
|
||||
if template:
|
||||
body = ''
|
||||
body += "<p>Hello <b>" + membership_rec.partner.name + \
|
||||
"</b>,</p></br>"
|
||||
body += "<p>This email is to inform you that your " \
|
||||
"membership will be expiring in " \
|
||||
+ due_days + " days." "</p></br>"
|
||||
body += "<p>For renewal, please contact the " \
|
||||
"manager." "</p></br>"
|
||||
body += "<p>Thank You." "</p></br>"
|
||||
body += "<p>" + user_rec.company_id.name + "," " </p></br>"
|
||||
body += "<p>" + user_rec.name + "." " </p></br>"
|
||||
template.write({'body_html': body})
|
||||
template.send_mail(membership_rec.partner.id,
|
||||
force_send=True)
|
||||
|
||||
@api.depends('account_invoice_id.state',
|
||||
'account_invoice_id.amount_residual',
|
||||
'account_invoice_id.invoice_payment_state')
|
||||
def _compute_state(self):
|
||||
"""Compute the state lines """
|
||||
if not self:
|
||||
return
|
||||
if self.account_invoice_id:
|
||||
self._cr.execute('''
|
||||
SELECT reversed_entry_id, COUNT(id)
|
||||
FROM account_move
|
||||
WHERE reversed_entry_id IN %s
|
||||
GROUP BY reversed_entry_id
|
||||
''', [tuple(self.mapped('account_invoice_id.id'))])
|
||||
reverse_map = dict(self._cr.fetchall())
|
||||
for line in self:
|
||||
move_state = line.account_invoice_id.state
|
||||
payment_state = line.account_invoice_id.invoice_payment_state
|
||||
|
||||
line.state = 'none'
|
||||
if move_state == 'draft':
|
||||
line.state = 'waiting'
|
||||
elif move_state == 'posted':
|
||||
if payment_state == 'paid':
|
||||
if reverse_map.get(line.account_invoice_id.id):
|
||||
line.state = 'canceled'
|
||||
else:
|
||||
line.state = 'paid'
|
||||
elif payment_state == 'in_payment':
|
||||
line.state = 'paid'
|
||||
elif payment_state == 'not_paid':
|
||||
line.state = 'invoiced'
|
||||
elif move_state == 'cancel':
|
||||
line.state = 'canceled'
|
||||
147
gym/models/product_template.py
Normal file
147
gym/models/product_template.py
Normal file
@@ -0,0 +1,147 @@
|
||||
# See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class GymEquipments(models.Model):
|
||||
"""Inherited product model for creating Equipment."""
|
||||
|
||||
_inherit = 'product.template'
|
||||
|
||||
is_equipment = fields.Boolean(string='Is Equipment',
|
||||
default=lambda self: self.env.context.
|
||||
get('equipments_default', False))
|
||||
exercise_ids = fields.Many2many('exercise.type',
|
||||
string='Exercise Type',
|
||||
help='This Equipment is For which '
|
||||
'Type of Exercise')
|
||||
state = fields.Selection([('working', 'Working'),
|
||||
('maintenance', 'Maintenance'),
|
||||
('repair', 'Repair'),
|
||||
('out_of_service', 'Out Of Service')], 'State',
|
||||
help='States of the Equipment', default='working')
|
||||
note = fields.Text('Note')
|
||||
company = fields.Char('Company Name')
|
||||
purchase_date = fields.Date('Purchase Date')
|
||||
is_service = fields.Boolean(string='Is Service',
|
||||
default=lambda self: self.env.context.
|
||||
get('service_default', False))
|
||||
is_food = fields.Boolean(string='Is Food?')
|
||||
unit_id = fields.Many2one('uom.uom', string="Unit of Measure",
|
||||
help='Measurement Unit for Food item')
|
||||
quantity = fields.Char('Quantity')
|
||||
calorie = fields.Float('Calories')
|
||||
protein = fields.Float('Protein')
|
||||
carbohydrates = fields.Float('Carbohydrates')
|
||||
fat = fields.Float(string='Fat')
|
||||
fibres = fields.Float('Fibres')
|
||||
sodium = fields.Float('Sodium')
|
||||
is_membership = fields.Boolean(string='Is Membership ?',
|
||||
help='Check if the product is eligible '
|
||||
'for membership.')
|
||||
|
||||
def sts_work(self):
|
||||
for equipment_rec in self:
|
||||
equipment_rec.state = 'working'
|
||||
cr, uid, context, su = self.env.args
|
||||
context = dict(context)
|
||||
template_id = self.env.ref('gym.equipement_repair_template')
|
||||
to_mail_id = []
|
||||
employee_ids = self.env['hr.employee'].search(
|
||||
[('active', '=', True)])
|
||||
for employee_id in employee_ids:
|
||||
if employee_id.user_id and \
|
||||
employee_id.user_id.partner_id.email:
|
||||
to_mail_id.append(
|
||||
employee_id.user_id.email)
|
||||
|
||||
to_mail_ids = ','.join(to_mail_id)
|
||||
body_html = """<![CDATA[<div style="font-family: 'Lucica Grande',
|
||||
Ubuntu, Arial, Verdana, sans-serif; font-size: 14px;
|
||||
color: rgb(34, 34, 34); background-color: #FFF; ">
|
||||
<p>Hello <b>Trainer</b>,</p>
|
||||
<p>It is to be informed that <b>${object.name}</b>
|
||||
is working.<p/>
|
||||
"""
|
||||
user_id = self.env['res.users'].browse(uid)
|
||||
if to_mail_ids:
|
||||
template_id.write(
|
||||
{'body_html': body_html,
|
||||
'subject': 'Equipment is Working.',
|
||||
'email_from': str(user_id.email),
|
||||
'email_to': to_mail_ids,
|
||||
'lang': 'lang' in context and
|
||||
context.get('lang', 'en_US')})
|
||||
template_id.send_mail(self.id, force_send=True)
|
||||
|
||||
def sts_maintan(self):
|
||||
for equipment_rec in self:
|
||||
equipment_rec.state = 'maintenance'
|
||||
cr, uid, context, su = self.env.args
|
||||
context = dict(context)
|
||||
template_id = self.env.ref('gym.equipement_repair_template')
|
||||
to_mail_id = []
|
||||
employee_ids = self.env['hr.employee'].search(
|
||||
[('active', '=', True)])
|
||||
for employee_id in employee_ids:
|
||||
if employee_id.user_id and \
|
||||
employee_id.user_id.partner_id.email:
|
||||
to_mail_id.append(
|
||||
employee_id.user_id.email)
|
||||
|
||||
to_mail_ids = ','.join(to_mail_id)
|
||||
body_html = """<![CDATA[<div style="font-family: 'Lucica Grande',
|
||||
Ubuntu, Arial, Verdana, sans-serif; font-size: 14px;
|
||||
color: rgb(34, 34, 34); background-color: #FFF; ">
|
||||
<p>Hello <b>Trainer</b>,</p>
|
||||
<p>It is to be informed that <b>${object.name}</b>
|
||||
is under maintenance.<p/>
|
||||
"""
|
||||
user_id = self.env['res.users'].browse(uid)
|
||||
if to_mail_ids:
|
||||
template_id.write(
|
||||
{'body_html': body_html,
|
||||
'subject': 'Equipment is under maintenance.',
|
||||
'email_from': str(user_id.email),
|
||||
'email_to': to_mail_ids,
|
||||
'lang': 'lang' in context and
|
||||
context.get('lang', 'en_US')})
|
||||
template_id.send_mail(self.id, force_send=True)
|
||||
|
||||
def sts_rpr(self):
|
||||
for equipment_rec in self:
|
||||
equipment_rec.state = 'repair'
|
||||
cr, uid, context, su = self.env.args
|
||||
context = dict(context)
|
||||
template_id = self.env.ref('gym.equipement_repair_template')
|
||||
to_mail_id = []
|
||||
employee_ids = self.env['hr.employee'].search(
|
||||
[('active', '=', True)])
|
||||
for employee_id in employee_ids:
|
||||
if employee_id.user_id and \
|
||||
employee_id.user_id.partner_id.email:
|
||||
to_mail_id.append(
|
||||
employee_id.user_id.email)
|
||||
|
||||
to_mail_ids = ','.join(to_mail_id)
|
||||
body_html = """<![CDATA[<div style="font-family: 'Lucica Grande',
|
||||
Ubuntu, Arial, Verdana, sans-serif; font-size: 14px;
|
||||
color: rgb(34, 34, 34); background-color: #FFF; ">
|
||||
<p>Hello <b>Trainer</b>,</p>
|
||||
<p>It is to be informed that<b>${object.name}</b>
|
||||
is under repair.<p/>
|
||||
"""
|
||||
user_id = self.env['res.users'].browse(uid)
|
||||
if to_mail_ids:
|
||||
template_id.write(
|
||||
{'body_html': body_html,
|
||||
'subject': 'Equipment is under repairing.',
|
||||
'email_from': str(user_id.email),
|
||||
'email_to': to_mail_ids,
|
||||
'lang': 'lang' in context and
|
||||
context.get('lang', 'en_US')})
|
||||
template_id.send_mail(self.id, force_send=True)
|
||||
|
||||
def sts_out(self):
|
||||
for equipment_rec in self:
|
||||
equipment_rec.state = 'out_of_service'
|
||||
73
gym/models/project_document.py
Normal file
73
gym/models/project_document.py
Normal file
@@ -0,0 +1,73 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from datetime import date,datetime
|
||||
|
||||
class ProjectDocument(models.Model):
|
||||
|
||||
_name = 'project.document'
|
||||
_description = "Documents"
|
||||
_rec_name = "document_name_id"
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# FIELDS
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
document_name_id = fields.Many2one(
|
||||
comodel_name="project.document.name",
|
||||
string='Document Name',
|
||||
)
|
||||
|
||||
partner_id = fields.Many2one(
|
||||
comodel_name='res.partner',
|
||||
string='Partner',
|
||||
)
|
||||
|
||||
datas = fields.Binary(
|
||||
string='Document',
|
||||
)
|
||||
|
||||
datas_fname = fields.Char('Filename')
|
||||
|
||||
is_document_set = fields.Boolean(
|
||||
string='Is Document Set',
|
||||
compute='_compute_document_set',
|
||||
store=True,
|
||||
)
|
||||
|
||||
user_id = fields.Many2one(
|
||||
comodel_name='res.users',
|
||||
string='Uploaded By',
|
||||
readonly=True,
|
||||
)
|
||||
|
||||
date = fields.Datetime(
|
||||
string='Date',
|
||||
readonly=True,
|
||||
)
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# METHODS
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
@api.depends('datas')
|
||||
def _compute_document_set(self):
|
||||
for doc in self:
|
||||
if doc.datas:
|
||||
doc.is_document_set = True
|
||||
else:
|
||||
doc.is_document_set = False
|
||||
|
||||
@api.model
|
||||
def create(self,vals):
|
||||
if vals.get('datas'):
|
||||
vals['user_id'] = self.env.user.id
|
||||
vals['date'] = datetime.now()
|
||||
res = super(ProjectDocument,self).create(vals)
|
||||
return res
|
||||
|
||||
def write(self, values):
|
||||
if values.get('datas'):
|
||||
values['user_id'] = self.env.user.id
|
||||
values['date'] = datetime.now()
|
||||
return super(ProjectDocument,self).write(values)
|
||||
72
gym/models/project_document_case.py
Normal file
72
gym/models/project_document_case.py
Normal file
@@ -0,0 +1,72 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from datetime import date,datetime
|
||||
|
||||
class ProjectDocumentCase(models.Model):
|
||||
|
||||
_name = 'project.document.case'
|
||||
_description = "Case Related Documents"
|
||||
_rec_name = "document_name_id"
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# FIELDS
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
document_name_id = fields.Many2one(
|
||||
comodel_name="project.document.name",
|
||||
string='Document Name',
|
||||
)
|
||||
|
||||
partner_id = fields.Many2one(
|
||||
comodel_name='res.partner',
|
||||
string='Partner',
|
||||
)
|
||||
|
||||
datas = fields.Binary(
|
||||
string='Document',
|
||||
)
|
||||
|
||||
datas_fname = fields.Char('Filename')
|
||||
|
||||
is_document_set = fields.Boolean(
|
||||
string='Is Document Set',
|
||||
compute='_compute_document_set',
|
||||
store=True,
|
||||
)
|
||||
|
||||
user_id = fields.Many2one(
|
||||
comodel_name='res.users',
|
||||
string='Uploaded By',
|
||||
readonly=True,
|
||||
)
|
||||
|
||||
date = fields.Datetime(
|
||||
string='Date',
|
||||
readonly=True,
|
||||
)
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# METHODS
|
||||
# --------------------------------------------------------------------
|
||||
@api.depends('datas')
|
||||
def _compute_document_set(self):
|
||||
for doc in self:
|
||||
if doc.datas:
|
||||
doc.is_document_set = True
|
||||
else:
|
||||
doc.is_document_set = False
|
||||
|
||||
@api.model
|
||||
def create(self,vals):
|
||||
if vals.get('datas'):
|
||||
vals['user_id'] = self.env.user.id
|
||||
vals['date'] = datetime.now()
|
||||
res = super(ProjectDocumentCase,self).create(vals)
|
||||
return res
|
||||
|
||||
def write(self, values):
|
||||
if values.get('datas'):
|
||||
values['user_id'] = self.env.user.id
|
||||
values['date'] = datetime.now()
|
||||
return super(ProjectDocumentCase,self).write(values)
|
||||
16
gym/models/project_document_category.py
Normal file
16
gym/models/project_document_category.py
Normal file
@@ -0,0 +1,16 @@
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
|
||||
class ProjectDocumentCategory(models.Model):
|
||||
|
||||
_name = 'project.document.category'
|
||||
_description = "Documents Categories"
|
||||
_rec_name = "name"
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# FIELDS
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
name = fields.Char(
|
||||
string='Name',
|
||||
)
|
||||
23
gym/models/project_document_group.py
Normal file
23
gym/models/project_document_group.py
Normal file
@@ -0,0 +1,23 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
|
||||
class ProjectDocumentGroup(models.Model):
|
||||
|
||||
_name = 'project.document.group'
|
||||
_description = "Documents Group"
|
||||
_rec_name = "category_id"
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# FIELDS
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
category_id = fields.Many2one(
|
||||
comodel_name="project.document.category",
|
||||
string='Category',
|
||||
)
|
||||
|
||||
document_name_ids = fields.Many2many(
|
||||
comodel_name="project.document.name",
|
||||
string='Documents',
|
||||
)
|
||||
17
gym/models/project_document_name.py
Normal file
17
gym/models/project_document_name.py
Normal file
@@ -0,0 +1,17 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
|
||||
class ProjectDocumentName(models.Model):
|
||||
|
||||
_name = 'project.document.name'
|
||||
_description = "Documents Name"
|
||||
_rec_name = "name"
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# FIELDS
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
name = fields.Char(
|
||||
string='Name',
|
||||
)
|
||||
72
gym/models/project_document_opposite.py
Normal file
72
gym/models/project_document_opposite.py
Normal file
@@ -0,0 +1,72 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from datetime import date,datetime
|
||||
|
||||
class ProjectDocumentOpposite(models.Model):
|
||||
|
||||
_name = 'project.document.opposite'
|
||||
_description = "Opposite Party Documents"
|
||||
_rec_name = "document_name_id"
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# FIELDS
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
document_name_id = fields.Many2one(
|
||||
comodel_name="project.document.name",
|
||||
string='Document Name',
|
||||
)
|
||||
|
||||
partner_id = fields.Many2one(
|
||||
comodel_name='res.partner',
|
||||
string='Partner',
|
||||
)
|
||||
|
||||
datas = fields.Binary(
|
||||
string='Document',
|
||||
)
|
||||
|
||||
datas_fname = fields.Char('Filename')
|
||||
|
||||
is_document_set = fields.Boolean(
|
||||
string='Is Document Set',
|
||||
compute='_compute_document_set',
|
||||
store=True,
|
||||
)
|
||||
|
||||
user_id = fields.Many2one(
|
||||
comodel_name='res.users',
|
||||
string='Uploaded By',
|
||||
readonly=True,
|
||||
)
|
||||
|
||||
date = fields.Datetime(
|
||||
string='Date',
|
||||
readonly=True,
|
||||
)
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# METHODS
|
||||
# --------------------------------------------------------------------
|
||||
@api.depends('datas')
|
||||
def _compute_document_set(self):
|
||||
for doc in self:
|
||||
if doc.datas:
|
||||
doc.is_document_set = True
|
||||
else:
|
||||
doc.is_document_set = False
|
||||
|
||||
@api.model
|
||||
def create(self,vals):
|
||||
if vals.get('datas'):
|
||||
vals['user_id'] = self.env.user.id
|
||||
vals['date'] = datetime.now()
|
||||
res = super(ProjectDocumentOpposite,self).create(vals)
|
||||
return res
|
||||
|
||||
def write(self, values):
|
||||
if values.get('datas'):
|
||||
values['user_id'] = self.env.user.id
|
||||
values['date'] = datetime.now()
|
||||
return super(ProjectDocumentOpposite,self).write(values)
|
||||
73
gym/models/project_other.py
Normal file
73
gym/models/project_other.py
Normal file
@@ -0,0 +1,73 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from datetime import date,datetime
|
||||
|
||||
class ProjectDocumentOther(models.Model):
|
||||
|
||||
_name = 'project.document.other'
|
||||
_description = "Other Documents"
|
||||
_rec_name = "document_name_id"
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# FIELDS
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
document_name_id = fields.Many2one(
|
||||
comodel_name="project.document.name",
|
||||
string='Document Name',
|
||||
)
|
||||
|
||||
partner_id = fields.Many2one(
|
||||
comodel_name='res.partner',
|
||||
string='Partner',
|
||||
)
|
||||
|
||||
datas = fields.Binary(
|
||||
string='Document',
|
||||
)
|
||||
|
||||
datas_fname = fields.Char('Filename')
|
||||
|
||||
is_document_set = fields.Boolean(
|
||||
string='Is Document Set',
|
||||
compute='_compute_document_set',
|
||||
store=True,
|
||||
)
|
||||
|
||||
user_id = fields.Many2one(
|
||||
comodel_name='res.users',
|
||||
string='Uploaded By',
|
||||
readonly=True,
|
||||
)
|
||||
|
||||
date = fields.Datetime(
|
||||
string='Date',
|
||||
readonly=True,
|
||||
)
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# METHODS
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
@api.depends('datas')
|
||||
def _compute_document_set(self):
|
||||
for doc in self:
|
||||
if doc.datas:
|
||||
doc.is_document_set = True
|
||||
else:
|
||||
doc.is_document_set = False
|
||||
|
||||
@api.model
|
||||
def create(self,vals):
|
||||
if vals.get('datas'):
|
||||
vals['user_id'] = self.env.user.id
|
||||
vals['date'] = datetime.now()
|
||||
res = super(ProjectDocumentOther,self).create(vals)
|
||||
return res
|
||||
|
||||
def write(self, values):
|
||||
if values.get('datas'):
|
||||
values['user_id'] = self.env.user.id
|
||||
values['date'] = datetime.now()
|
||||
return super(ProjectDocumentOther,self).write(values)
|
||||
34
gym/models/project_task.py
Normal file
34
gym/models/project_task.py
Normal file
@@ -0,0 +1,34 @@
|
||||
# See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class ProjectTask(models.Model):
|
||||
"""Inherited project task model for giving the task type whether the task
|
||||
is of workout or Diet."""
|
||||
|
||||
_inherit = "project.task"
|
||||
_order = 'schedule_date asc'
|
||||
|
||||
schedule_date = fields.Date('Schedule Date',
|
||||
help='Start date and Stop date of the Task')
|
||||
reviewer_id = fields.Many2one('res.users', 'Specialist',
|
||||
help='Reviewer of the Task')
|
||||
task_type = fields.Selection([('workout', 'Workout'), ('diet', 'Diet')],
|
||||
string='Type',
|
||||
help='Type of the Task [workout]-If task is '
|
||||
'of Workout Plan [diet]-If task is of '
|
||||
'Diet Plan')
|
||||
|
||||
|
||||
class ProjectProject(models.Model):
|
||||
"""Inherited project model for giving the project type whether the task
|
||||
is of workout or Diet."""
|
||||
_inherit = 'project.project'
|
||||
|
||||
type = fields.Selection([('workout', 'Workout'), ('diet', 'Diet')], 'Type',
|
||||
default=lambda self: self.env.context.
|
||||
get('workout_default', False) or False,
|
||||
help='Type of the Project [workout] '
|
||||
'-If project is of Workout Plan [diet]-If '
|
||||
'project is of Diet Plan')
|
||||
40
gym/models/res_partner_credit_card.py
Normal file
40
gym/models/res_partner_credit_card.py
Normal file
@@ -0,0 +1,40 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from datetime import date
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
class ResPartnerCreditCard(models.Model):
|
||||
|
||||
_name = 'res.partner.credit.card'
|
||||
_rec_name = 'name'
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# FIELDS
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
name = fields.Char(
|
||||
string='Name',
|
||||
)
|
||||
|
||||
type_id = fields.Many2one(
|
||||
comodel_name='res.partner.credit.card.type',
|
||||
string='Type',
|
||||
)
|
||||
|
||||
number = fields.Integer(
|
||||
string='Number',
|
||||
)
|
||||
|
||||
expiry_date = fields.Date(
|
||||
string='Expiry Date'
|
||||
)
|
||||
|
||||
ccb_number = fields.Char(
|
||||
string='CCB Number',
|
||||
)
|
||||
|
||||
partner_id = fields.Many2one(
|
||||
comodel_name='res.partner',
|
||||
string='Partner',
|
||||
)
|
||||
18
gym/models/res_partner_credit_card_type.py
Normal file
18
gym/models/res_partner_credit_card_type.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from datetime import date
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
class ResPartnerCreditCardType(models.Model):
|
||||
|
||||
_name = 'res.partner.credit.card.type'
|
||||
_rec_name = 'name'
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# FIELDS
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
name = fields.Char(
|
||||
string='Name',
|
||||
)
|
||||
73
gym/models/sale.py
Normal file
73
gym/models/sale.py
Normal file
@@ -0,0 +1,73 @@
|
||||
# See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class SaleOrder(models.Model):
|
||||
"""Imported sale order model."""
|
||||
|
||||
_inherit = 'sale.order'
|
||||
|
||||
start_date = fields.Date('Start Date')
|
||||
end_date = fields.Date('End Date')
|
||||
membership = fields.Boolean(string='Membership',
|
||||
help='Check if the Customer Wants to Buy '
|
||||
'membership.')
|
||||
|
||||
@api.model
|
||||
def create(self, values):
|
||||
rec = super(SaleOrder, self).create(values)
|
||||
if rec.membership and not rec.partner_id.is_member:
|
||||
rec.partner_id.is_member = True
|
||||
rec.partner_id.membership_number = self.env[
|
||||
'ir.sequence'].next_by_code('membership.number')
|
||||
return rec
|
||||
|
||||
def write(self, values):
|
||||
for rec in self:
|
||||
if values.get('partner_id'):
|
||||
partner_id =\
|
||||
self.env['res.partner'].browse(values.get('partner_id'))
|
||||
else:
|
||||
partner_id = rec.partner_id
|
||||
if values.get('membership', rec.membership) and not \
|
||||
partner_id.is_member:
|
||||
partner_id.is_member = True
|
||||
return super(SaleOrder, self).write(values)
|
||||
|
||||
@api.constrains('order_line', 'membership')
|
||||
def _check_order_line_membership(self):
|
||||
"""Membership product constraint."""
|
||||
if self.membership and len([rec for rec in self.order_line.filtered(
|
||||
lambda rec:
|
||||
rec.product_id.product_tmpl_id.is_membership)]) > 1:
|
||||
raise ValidationError(
|
||||
_("You can\'t select more than one membership product."))
|
||||
|
||||
@api.constrains('start_date', 'end_date')
|
||||
def _check_date(self):
|
||||
"""Membership date constraint."""
|
||||
if self.membership and self.start_date > self.end_date:
|
||||
raise ValidationError(
|
||||
_("End date must be greater than start date"))
|
||||
|
||||
def action_confirm(self):
|
||||
"""Create membership line when confirm sale order."""
|
||||
res = super(SaleOrder, self).action_confirm()
|
||||
for order in self:
|
||||
if order.membership and order.state == 'sale' and not \
|
||||
order._context.get('is_membership_created'):
|
||||
for line_rec in order.order_line:
|
||||
if line_rec.product_id.product_tmpl_id.is_membership:
|
||||
membership_rec = \
|
||||
self.env['membership.membership_line'].create({
|
||||
'partner': order.partner_id.id,
|
||||
'date': order.start_date,
|
||||
'end_date': order.end_date,
|
||||
'member_price': line_rec.price_subtotal,
|
||||
'membership_id': line_rec.product_id.id,
|
||||
'sale_order_id': order.id,
|
||||
})
|
||||
membership_rec.action_confirm()
|
||||
return res
|
||||
66
gym/models/trainer.py
Normal file
66
gym/models/trainer.py
Normal file
@@ -0,0 +1,66 @@
|
||||
# See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class HrEmployee(models.Model):
|
||||
"""Inherited this model for trainer's information."""
|
||||
|
||||
_inherit = 'hr.employee'
|
||||
|
||||
is_trainer = fields.Boolean(string='Is Trainer ?')
|
||||
specialist_ids = fields.Many2many('gym.skills', 'trainer_skill_rel',
|
||||
'trainer_id', 'skill_id',
|
||||
string='Specialization')
|
||||
total_session = fields.Integer(
|
||||
compute='_compute_calculation_trainer_session',
|
||||
string='Total Session')
|
||||
user_id = fields.Many2one('res.users', 'User',
|
||||
related='resource_id.user_id', store=True,
|
||||
readonly=False, ondelete="cascade")
|
||||
|
||||
def unlink(self):
|
||||
for rec in self:
|
||||
user_id = rec.user_id
|
||||
rec.user_id = False
|
||||
user_id.unlink()
|
||||
return super(HrEmployee, self).unlink()
|
||||
|
||||
def _compute_calculation_trainer_session(self):
|
||||
"""Trainer session count for session smart
|
||||
button in trainer form(hr.employee)."""
|
||||
for trainer_rec in self:
|
||||
trainer_rec.total_session = \
|
||||
self.env['calendar.event'].search_count([
|
||||
('trainer_id', '=', trainer_rec.id)])
|
||||
|
||||
@api.constrains('work_email')
|
||||
def _check_work_email(self):
|
||||
rec = self.search([('work_email', '=', self.work_email),
|
||||
('id', '!=', self.id)])
|
||||
if rec:
|
||||
raise ValidationError(_("You can not have two users with the "
|
||||
"same login !"))
|
||||
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
"""Method for creating User at trainer creation."""
|
||||
res = super(HrEmployee, self).create(vals)
|
||||
if not vals.get('user_id'):
|
||||
user = self.env['res.users'].create({
|
||||
'name': vals.get('name'),
|
||||
'login': vals.get('work_email', False),
|
||||
'password': self.env.user.company_id.default_password or '',
|
||||
'groups_id': [(6, 0, [self.env.ref(
|
||||
'gym.group_gym_trainer').id])],
|
||||
})
|
||||
if user and user.partner_id:
|
||||
user.partner_id.write({'email': vals.get('work_email', False)})
|
||||
res.write({'user_id': user and user.id or False})
|
||||
return res
|
||||
|
||||
def copy(self, default=None):
|
||||
if self.is_trainer:
|
||||
raise ValidationError(_("Sorry, you can't duplicate a trainer. "))
|
||||
return super(HrEmployee, self).copy(default)
|
||||
78
gym/models/workout.py
Normal file
78
gym/models/workout.py
Normal file
@@ -0,0 +1,78 @@
|
||||
# See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class ExerciseLines(models.Model):
|
||||
"""Information about body parts and exercise."""
|
||||
|
||||
_name = 'exercise.lines'
|
||||
_description = "Exercise Lines"
|
||||
|
||||
exercise_name_id = fields.Many2one('exercise.exercise', 'Exercise name')
|
||||
sets = fields.Integer('Sets')
|
||||
reps_ids = fields.Many2many('repeat.repeat', 'exercise_repeat_rel',
|
||||
string="Repetition")
|
||||
sequence = fields.Integer('Sequence')
|
||||
|
||||
|
||||
class RepeatRepeat(models.Model):
|
||||
_name = 'repeat.repeat'
|
||||
_description = "Repeated"
|
||||
|
||||
name = fields.Integer('Reps', required=1)
|
||||
|
||||
|
||||
class ExerciseExercise(models.Model):
|
||||
"""Information about Exercise and Equipment."""
|
||||
|
||||
_name = 'exercise.exercise'
|
||||
_description = "Exercise Exercise"
|
||||
|
||||
name = fields.Char('Name')
|
||||
exercise_type_ids = fields.Many2many(
|
||||
'exercise.type', string='Exercise For')
|
||||
equipment_id = fields.Many2one('product.template', 'Equipment')
|
||||
exercise_images_ids = fields.Many2many('ir.attachment', string='Images')
|
||||
exercise_images_ids = fields.One2many(
|
||||
'ir.attachment',
|
||||
'exercise_id',
|
||||
string='Attachment',
|
||||
)
|
||||
|
||||
benefits = fields.Text('Benefits of Exercise')
|
||||
steps = fields.Text('Steps To Follow')
|
||||
exercise_video_ids = fields.One2many(
|
||||
'exercise.videos', 'exercise_id', 'Videos')
|
||||
|
||||
|
||||
class Attachment(models.Model):
|
||||
_inherit = 'ir.attachment'
|
||||
_description = 'Ir Attachment'
|
||||
|
||||
exercise_id = fields.Many2one(
|
||||
'exercise.exercise',
|
||||
string='Exercise',
|
||||
)
|
||||
|
||||
# @api.onchange('datas')
|
||||
# def _onchange_datas(self):
|
||||
# self.name = self.datas
|
||||
|
||||
|
||||
class ExerciseType(models.Model):
|
||||
_name = 'exercise.type'
|
||||
_description = "Exercise Type"
|
||||
|
||||
name = fields.Char('Name', required=1)
|
||||
|
||||
|
||||
class ExerciseVideos(models.Model):
|
||||
"""Model for Exercise Videos."""
|
||||
|
||||
_name = 'exercise.videos'
|
||||
_description = "Exercise Videos"
|
||||
|
||||
name = fields.Char('Name', required=True)
|
||||
link = fields.Char('Link', required=True)
|
||||
exercise_id = fields.Many2one('exercise.exercise', 'Exercises')
|
||||
Reference in New Issue
Block a user