Commit e82254eb by Low

initial load

parents
from . import models
\ No newline at end of file
# -*- coding: utf-8 -*-
{
'name': "Pet Shop",
'summary': """Pet Shop Management""",
'description': """
Pet Shop Management:
- Pet Shop
- Pet Transaction
""",
'author': "ITS Mart, DickSin",
# Categories can be used to filter modules in modules listing
# Check https://github.com/odoo/odoo/blob/master/odoo/addons/base/module/module_data.xml
# for the full list
'category': 'Pet Shop',
'version': '11.0.0',
# any module necessary for this one to work correctly
'depends': ['base'],
# always loaded
'data': [
# 'security/ir.model.access.csv',
'views/pet_shop.xml',
'views/pet.xml',
'views/services.xml',
'views/customer.xml',
'views/transaction.xml',
'views/staff.xml',
'reports/reports.xml',
'reports/pet_transaction.xml',
],
}
\ No newline at end of file
from . import pet_shop
from . import pet
from . import services
from . import customer
from . import transaction
from . import staff
\ No newline at end of file
from odoo.exceptions import ValidationError
import re
from odoo import api,models,fields
class Customer(models.Model):
_name = "customer"
name = fields.Char(string="Customer Name", required=True)
phone_no = fields.Char(string="Phone No", required=True)
email = fields.Char(string="Email", required=True)
@api.constrains('email')
def check_email(self):
if self.email:
match = re.match("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$", self.email)
if match == None:
raise ValidationError('Incorrect Email Format')
@api.constrains('phone_no')
def check_phone(self):
if self.phone_no:
match = re.match("^(01)[0-46-9]*[0-9]{7,8}$", self.phone_no)
if match == None:
raise ValidationError('Incorrect Phone Number Format')
\ No newline at end of file
from odoo import api,models,fields
import pendulum #calander
class Pet(models.Model):
_name = "pet.info"
name = fields.Char(string="Pet Name", required=1)
ptype = fields.Char(string="Pet Type", required=1)
age = fields.Integer(string="Age", compute="_compute_pet_age", store=1) #age = fields.Integer(string="Age", required=1)
pet_shop_id = fields.Many2one("pet.shop", string="Pet's Shop")
price = fields.Float(string="Price (RM)", default=0, required=1)
dob = fields.Date(string="Date of Birth", required=1)
pet_status = fields.Selection([
('available', 'Available'),
('sold', 'Sold'),
], string="Status", default="available", required=1)
@api.depends('dob')
@api.multi
def _compute_pet_age(self):
for record in self:
if record.dob:
now = pendulum.now()
dob = pendulum.parse(record.dob)
age = (now - dob).years + 1
record.age = age
else:
record.age = 0
\ No newline at end of file
from odoo.exceptions import ValidationError
import re
from odoo import api,models,fields
class PetShop(models.Model):
_name = "pet.shop"
_rec_name = ""
name = fields.Char(string="Pet Shop Name", required=True)
address = fields.Char(string="Adress", required=True)
launch_date = fields.Date(string="Launch Date", required=True)
email = fields.Char(string="Email", required=True)
phone_no = fields.Char(string="Phone No", required=True)
@api.constrains('phone_no')
def check_phone(self):
if self.phone_no:
match = re.match("^(01)[0-46-9]*[0-9]{7,8}$", self.phone_no)
if match == None:
raise ValidationError('Incorrect Phone Number Format')
from odoo import api,models,fields
import pendulum
class Services(models.Model):
_name = "services.pet"
_rec_name = "services"
services = fields.Char(default='/', string="Services ID")
staff_id = fields.Many2one("staff", string="Staff Name", required=1)
pet_shop_id = fields.Many2one("pet.shop", string="Pet's Shop", required=1)
pet_id = fields.Many2one("pet.info", string="Pets")
#pet_shop_ids = fields.Many2many("pet.shop", string="Pet's Shop", required=True) ==> for select many shop
grooming = fields.Char(string="Grooming", required=True)
training = fields.Char(string="Training", required=True)
price = fields.Float(string="Price (RM)", default=0, required=True)
created_date = fields.Date(string="Created Date", required=True, default=fields.Date.today())
@api.onchange('pet_shop_id')
def onchange_pet_shop_id(self) :
for record in self :
return {'domain':
{'pet_id': [('pet_shop_id', '=', record.pet_shop_id.id)]}
}
@api.model
def create(self, vals):
if vals.get('services', False) == '/':
vals['services'] = self.env['ir.sequence'].next_by_code('services.pet.seq')
#print(vals)
return super(Services, self).create(vals)
\ No newline at end of file
from odoo.exceptions import ValidationError
import re
from odoo import api,models,fields
class Staff(models.Model):
_name = "staff"
name = fields.Char(string="Staff Name", required=True)
phone_no = fields.Char(string="Phone No", required=True)
email = fields.Char(string="Email", required=True)
@api.constrains('email')
def check_email(self):
if self.email:
match = re.match("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$", self.email)
if match == None:
raise ValidationError('Incorrect Email Format')
@api.constrains('phone_no')
def check_phone(self):
if self.phone_no:
match = re.match("^(01)[0-46-9]*[0-9]{7,8}$", self.phone_no)
if match == None:
raise ValidationError('Incorrect Phone Number Format')
\ No newline at end of file
from odoo.exceptions import ValidationError
import re
from odoo import api,models,fields
class Transaction(models.Model):
_name = "transaction.info"
_rec_name = "transaction"
transaction = fields.Char(default='/', string="Transaction ID")
customer_id = fields.Many2one("customer", string="Customer Name", required=1)
pet_shop_id = fields.Many2one("pet.shop", string="Pet's Shop", required=1)
pet_ids = fields.Many2many("pet.info", string="Pets", required=1)
status = fields.Selection([
('pending', 'Pending'),
('complete', 'Complete'),
], string="Status", default="pending", required=1)
created_date = fields.Date(string="Created Date", required=True, default=fields.Date.today())
total_amount = fields.Float(string="Total Amount (RM)", compute='_compute_total_amount', store=1)
#payment_amount = fields.Float(string="Payment Amount (RM)")
#payment_change = fields.Float(string='Payment Change (RM)', compute='_compute_payment_change', store=1)
# Compute total amount
@api.depends('pet_ids')
@api.multi
def _compute_total_amount(self):
for record in self:
if record.pet_ids:
record.total_amount = sum(price.price for price in record.pet_ids)
else:
record.total_amount = 0
# Compute payment change & payment amount
#@api.depends('payment_amount', 'total_amount')
#@api.multi
#def _compute_payment_change(self):
#for record in self:
#if record.pet_ids:
#record.payment_change = record.payment_amount - record.total_amount
#else:
#record.payment_change = 0
# when user select pet_shop_id, pet_ids will show only that the pet_hop_ids have
@api.onchange('pet_shop_id')
def onchange_pet_shop_id(self):
for record in self:
return {'domain': {'pet_ids': [('pet_shop_id', '=', record.pet_shop_id.id), ('pet_status', '=', 'available')]}}
# For many2many, if transaction status & pet status is complete OR sold, it will change to pending & available
@api.multi
def action_pending(self):
for record in self:
record.status = 'pending' #change transaction status to pending & run transaction status first
for s1 in record.pet_ids:
s1.pet_status = 'available' #change pet status from pet.py to pending & run pet status
@api.multi
def action_complete(self):
for record in self:
record.status = 'complete' #change transaction status to complete
for s2 in record.pet_ids:
s2.pet_status = 'sold' #change pet status from pet.py to sold & run pet status
# Auto-generate transaction ID
@api.model
def create(self, vals):
if vals.get('transaction', False) == '/':
vals['transaction'] = self.env['ir.sequence'].next_by_code('transaction.info.seq')
#print(vals)
return super(Transaction, self).create(vals)
# Validation Error, validate the transaction status
@api.constrains('status')
def validate_status(self):
for pet in self.pet_ids:
if pet.pet_status == 'sold':
raise ValidationError('Pet is sold')
\ No newline at end of file
<odoo>
<template id="report_transaction">
<t t-call="web.html_container">
<t t-foreach="docs" t-as="doc">
<t t-call="web.external_layout">
<div class="page">
<h2 style="text-align: center;">Pet Transaction</h2><br/>
<record id="report_pet_transaction" model="report.paperformat">
<field name="transaction_id">Transaction ID : <t t-esc="doc.transaction"/></field>
<br/>
<field name="customer_name">Customer Name : <t t-esc="doc.customer_id.name"/></field>
<br/>
<field name="tran_status">Transaction Status : <t t-esc="doc.status"/></field>
<br/>
<field name="created_date">Created Date : <t t-esc="doc.created_date"/></field>
<br/>
</record>
</div>
</t>
</t>
</t>
</template>
</odoo>
\ No newline at end of file
<odoo>
<report
id="report_pet_transaction"
string="Pet Transaction"
model="transaction.info"
report_type="qweb-pdf"
name="pet_shop.report_transaction"
file="pet_shop.report_transaction"/> <!-- model = transaction id variable name-->
</odoo>
\ No newline at end of file
<odoo>
<!-- View customer tree view -->
<record id="customer_tree_view" model="ir.ui.view">
<field name="name">Customer Tree</field>
<field name="model">customer</field>
<field name="arch" type="xml">
<tree string="Customer Info">
<field name="name"/>
<field name="phone_no"/>
<field name="email"/>
</tree>
</field>
</record>
<!-- View customer form view -->
<record id="customer_form_view" model="ir.ui.view">
<field name="name">Customer Form</field>
<field name="model">customer</field>
<field name="arch" type="xml">
<form string="Customer">
<group string="Customer Info">
<field name="name"/>
<field name="phone_no" placeholder="01XXXXXXXX"/>
<field name="email" placeholder="xxxxx@xxx.com"/>
</group>
</form>
</field>
</record>
<!-- Create customer -->
<record id="customer_action" model="ir.actions.act_window">
<field name="name">Customer</field>
<field name="res_model">customer</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">Create the first Customer
</p>
</field>
</record>
<menuitem id="customer_menu_act" name="Customer" parent="pet_shop_menu_catalog"
action="customer_action" />
</odoo>
\ No newline at end of file
<odoo>
<!-- View pet tree view-->
<record id="pet_tree" model="ir.ui.view">
<field name="name">Pet Tree</field>
<field name="model">pet.info</field>
<field name="arch" type="xml">
<tree string="Pet Info">
<field name="name"/>
<field name="ptype"/>
<field name="age" readonly="1"/>
<field name="pet_shop_id"/>
<field name="price"/>
<field name="dob"/>
<field name="pet_status"/>
</tree>
</field>
</record>
<!-- View pet form view -->
<record id="pet_form" model="ir.ui.view">
<field name="name">Pet Form</field>
<field name="model">pet.info</field>
<field name="arch" type="xml">
<form string="Pet">
<group>
<group string="General Info">
<field name="name"/>
<field name="ptype"/>
<field name="age"/>
<field name="pet_shop_id"/>
<field name="price"/>
<field name="dob"/>
<field name="pet_status"/>
</group>
</group>
</form>
</field>
</record>
<record model="ir.actions.act_window" id="pet_action">
<field name="name">Pet</field>
<field name="res_model">pet.info</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">Create the first Pet
</p>
</field>
</record>
<menuitem id="pet_menu_act" name="Pets" parent="pet_shop_menu_catalog" action="pet_action" />
</odoo>
\ No newline at end of file
<odoo>
<!-- View pet shop tree view -->
<record id="petshop_tree_view" model="ir.ui.view">
<field name="name">Pet Shop Tree</field>
<field name="model">pet.shop</field>
<field name="arch" type="xml">
<tree string="Pet Shop Info">
<field name="name"/>
<field name="address"/>
<field name="launch_date"/>
<field name="email"/>
<field name="phone_no"/>
</tree>
</field>
</record>
<!-- View pet shop form view -->
<record id="petshop_form_view" model="ir.ui.view">
<field name="name">Pet Shop Form</field>
<field name="model">pet.shop</field>
<field name="arch" type="xml">
<form string="Pet Shop">
<group string="Pet Shop Info">
<field name="name"/>
<field name="address"/>
<field name="launch_date"/>
<field name="email"/>
<field name="phone_no" placeholder="01XXXXXXXX"/>
</group>
</form>
</field>
</record>
<!-- Create petshop -->
<record id="petshop_action" model="ir.actions.act_window">
<field name="name">Pet Shop</field>
<field name="res_model">pet.shop</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">Create the first Pet Shop
</p>
</field>
</record>
<menuitem id="pet_shop_menu_root" name="Pet Shop" sequence="1" />
<menuitem id="pet_shop_menu_catalog" name="Shop Management" parent="pet_shop_menu_root" sequence="1" />
<menuitem id="pet_shop_menu_act" name="Shops" parent="pet_shop_menu_catalog"
action="petshop_action" sequence="1" />
</odoo>
\ No newline at end of file
<odoo>
<!-- View pet services tree view -->
<record id="petservices_tree" model="ir.ui.view">
<field name="name">Pet Services Tree</field>
<field name="model">services.pet</field>
<field name="arch" type="xml">
<tree string="Pet Services Info">
<field name="services"/>
<field name="staff_id"/>
<field name="pet_shop_id"/>
<field name="pet_id"/>
<field name="grooming"/>
<field name="training"/>
<field name="price"/>
<!--<field name="pet_shop_ids"/>-->
<field name="created_date"/>
</tree>
</field>
</record>
<!-- Auto-generate services ID -->
<record id="pet_services_PetServices" model="ir.sequence">
<field name="name">Services ID</field>
<field name="code">services.pet.seq</field>
<field name="prefix">S</field>
<field name="padding">4</field>
</record>
<!-- View pet services form view -->
<record id="petservices_form" model="ir.ui.view">
<field name="name">Pet Services Form</field>
<field name="model">services.pet</field>
<field name="arch" type="xml">
<form string="Pet Services">
<group string="Services Info">
<field name="services" readonly="1" force_save="1"/>
<field name="staff_id"/>
<field name="pet_shop_id"/>
<field name="pet_id"/>
<field name="grooming"/>
<field name="training"/>
<field name="price"/>
<!--<field name="pet_shop_ids" widget="many2many_tags"/>-->
<field name="created_date" readonly="1"/>
</group>
</form>
</field>
</record>
<record id="services_action" model="ir.actions.act_window">
<field name="name">Services</field>
<field name="res_model">services.pet</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">Create the first Services
</p>
</field>
</record>
<menuitem id="services_menu_act" name="Services" parent="pet_shop_menu_catalog"
action="services_action" />
</odoo>
\ No newline at end of file
<odoo>
<!-- View staff tree view -->
<record id="staff_tree_view" model="ir.ui.view">
<field name="name">Staff Tree</field>
<field name="model">staff</field>
<field name="arch" type="xml">
<tree string="Staff Info">
<field name="name"/>
<field name="phone_no"/>
<field name="email"/>
</tree>
</field>
</record>
<!-- View staff form view -->
<record id="staff_form_view" model="ir.ui.view">
<field name="name">Staff Form</field>
<field name="model">staff</field>
<field name="arch" type="xml">
<form string="Staff">
<group string="Staff Info">
<field name="name"/>
<field name="phone_no" placeholder="01XXXXXXXX"/>
<field name="email" placeholder="xxxxx@xxx.com"/>
</group>
</form>
</field>
</record>
<!-- Create staff -->
<record id="staff_action" model="ir.actions.act_window">
<field name="name">Staff</field>
<field name="res_model">staff</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">Create the first Staff
</p>
</field>
</record>
<menuitem id="staff_menu_act" name="Staff" parent="pet_shop_menu_catalog"
action="staff_action" />
</odoo>
\ No newline at end of file
<odoo>
<!-- View transaction tree view -->
<record id="transaction_tree" model="ir.ui.view">
<field name="name">Transaction Tree</field>
<field name="model">transaction.info</field>
<field name="arch" type="xml">
<tree string="Transaction Info">
<field name="transaction"/>
<field name="customer_id"/>
<field name="pet_shop_id"/>
<field name="pet_ids"/>
<field name="status"/>
<field name="created_date"/>
<field name="total_amount"/>
</tree>
</field>
</record>
<!-- Auto-generate transaction ID -->
<record id="pet_transaction_PetTransaction" model="ir.sequence">
<field name="name">Transaction ID</field>
<field name="code">transaction.info.seq</field>
<field name="prefix">PT</field>
<field name="padding">4</field>
</record>
<!-- View transaction form view -->
<record id="transaction_form" model="ir.ui.view">
<field name="name">Transaction Form</field>
<field name="model">transaction.info</field>
<field name="arch" type="xml">
<form string="Transaction">
<header>
<button name="action_pending" type="object" string="Pending" class="oe_highlight"
attrs="{'invisible': [('status','=','pending')]}" />
<button name="action_complete" type="object" string="Complete" class="oe_highlight"
attrs="{'invisible': [('status','=','complete')]}"/>
<field name="status" widget="statusbar" statusbar_visible="pending,complete"/>
</header>
<group string="Transaction Info">
<field name="transaction" readonly="1" force_save="1"/>
<field name="customer_id"/>
<field name="pet_shop_id"/>
<field name="pet_ids"/> <!--domain="[('pet_shop_id', '=', 'pet_shop_id'), ('pet_ids', '=', 'pet_ids')]"-->
<field name="created_date" readonly="1"/>
<field name="total_amount" readonly="1"/>
</group>
</form>
</field>
</record>
<record id="transaction_action" model="ir.actions.act_window">
<field name="name">Transaction</field>
<field name="res_model">transaction.info</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">Create the first transaction
</p>
</field>
</record>
<menuitem id="transaction_menu_act" name="Transaction" parent="pet_shop_menu_catalog"
action="transaction_action" />
</odoo>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment