Commit bfabb938 by Michelle Yang

initial load

parents
from . import models
\ No newline at end of file
# -*- coding: utf-8 -*-
{
'name': "Pet Shop",
'summary': """Pet""",
'description': """
Pet:
- Sell Pets
- Sell Pet Supplies
- Train Pets
""",
'author': "ITS mart, MiiXue",
'website': "http://www.yourcompany.com",
# 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',
'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/customer.xml',
'views/product.xml',
'views/pet_transaction.xml',
'views/product_transaction.xml',
'reports/pet_transaction.xml',
'reports/report.xml',
],
}
\ No newline at end of file
from . import pet_shop
from . import pet
from . import customer
from . import product
from . import pet_transaction
from . import product_transaction
\ No newline at end of file
from odoo import api, models, fields
from odoo.exceptions import ValidationError
import re
class Customer(models.Model):
_name = "customer"
name = fields.Char(string="Name", required=1)
gender = fields.Selection([
('male', 'Male'),
('female', 'Female')
], string="Gender", default="male", required=1)
phone_no = fields.Char(string="Phone Number", required=1)
email = fields.Char(string="Email", required=1)
#Validation of email
@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')
#Validation of phone no
@api.constrains('phone_no')
def validate_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 #calender
class Pet(models.Model):
_name = "pet" # _ mean private, without _ mean public
name = fields.Char(string="Pet Name", required=1)
dob = fields.Date(string="Date Of Birth", required=1)
age = fields.Integer(string="Age", compute="_compute_pet_age", store=1) #if we use compute, we need to use store because it will store the value in the database
pet_types = fields.Char(string="Type of Pets", required=1)
behavior_types = fields.Selection([
('cute', 'Cute'),
('obedient', 'Obedient'),
('playful', 'Playful')
], string="Behavior Types", default="cute")
price = fields.Float(string="Price (RM)", required=1)
pet_status = fields.Selection([
('available', 'Available'),
('sold', 'Sold')
], string="Status")
pet_shop_id = fields.Many2one("pet.shop", string="Shop Name", required=1)
#Generate the pet's age
@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 import api, models, fields, exceptions
from odoo.exceptions import ValidationError
import re
class PetShop(models.Model):
_name = "pet.shop" # only can use .
name = fields.Char(string="Shop Name", required = 1)
launch_date = fields.Date(string="Launch Date", required = 1)
address = fields.Char(string="Address", required = 1)
opening_hour = fields.Char(string="Operating Hours", required = 1)
phone_no = fields.Char(string="Phone Number", required =1)
email = fields.Char(string="Email", required=1)
#Validation of email
@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')
#Validation of phone no
@api.constrains('phone_no')
def validate_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, fields, models
from odoo.exceptions import ValidationError
import re, time
class PetTransaction(models.Model):
_name = "pet.transaction"
_rec_name = "pet_transaction_id"
pet_transaction_id = fields.Char(string="Pet Transaction No", default="/")
customer_id = fields.Many2one("customer", string="Customer", required=1)
pet_shop_id = fields.Many2one("pet.shop", string="Pet Shop", required=1)
pet_id = fields.Many2one("pet", string="Pet", required=1)
transaction_date = fields.Date(string="Transaction Date", required=1, default=fields.Date.today())
price = fields.Float(string="Total Price (RM)", compute="_compute_price", required=1)
transaction_status = fields.Selection([
('pending', 'Pending'),
('complete', 'Complete')
], default="pending", required=1)
#Create sequence id
@api.model
def create(self, vals):
if vals.get('pet_transaction_id', False) == '/':
vals['pet_transaction_id'] = self.env['ir.sequence'].next_by_code('pet.transaction.sequence')
print(vals)
return super(PetTransaction, self).create(vals)
#once it select this B data, the other selection will based on this B data has (Give Domain For A Field Based On Another Field)
@api.onchange('pet_shop_id')
def _onchange_pet_shop_id(self):
for record in self:
if record.pet_shop_id != record.pet_shop_id:
return {'domain': {'pet_id': [('pet_shop_id', '=', record.pet_shop_id.id), ('pet_status', '=', 'available')]}} # check whether the pet_status is available or not, if not it wont show in the selection list
else:
record.pet_id = None
return {'domain': {'pet_id': [('pet_shop_id', '=', record.pet_shop_id.id), ('pet_status', '=', 'available')]}}
#Status bar for pending and complete
#Pet Shop there the available status will change to sold status
def action_pending(self):
for record in self:
record.transaction_status = 'pending'
record.pet_id.pet_status = 'available' # change in pet.py
def action_complete(self):
for record in self:
record.transaction_status = 'complete'
record.pet_id.pet_status = 'sold' # change in pet.py
#If the status in pet.py is sold, the transaction will not let them buy
@api.constrains('pet_id')
def check_status(self):
if self.pet_id.pet_status == "sold":
raise ValidationError("Sorry, this pet is already sold out")
#Auto change price when user select pet_id
@api.depends('pet_id')
@api.multi
def _compute_price(self):
for record in self:
if not record.pet_id:
record.price = 0.00
else:
record.price = record.pet_id.price
from odoo import api, fields, models
class Product (models.Model):
_name = "product"
_rec_name = "product_name" # also can straight away change product_name to name
pet_shop_id = fields.Many2one("pet.shop", string="Pet Shop", required=1)
pet_types = fields.Char(string="Pet Types", required=1)
product_types = fields.Char(string="Product / Supply Type", required=1)
product_name = fields.Char(string="Product / Supply Name", required=1)
price = fields.Float(string="Price (RM)", required=1)
description = fields.Char(string="Description")
quantity = fields.Integer(string="Quantity", required=1)
\ No newline at end of file
from odoo import api, models, fields
from odoo.exceptions import ValidationError
class ProductTransaction(models.Model):
_name="product.transaction"
_rec_name="product_transaction_id"
product_transaction_id = fields.Char(string="Product Transaction No", default="/")
customer_id = fields.Many2one("customer", string="Customer", required=1)
pet_shop_id = fields.Many2one("pet.shop", string="Pet Shop", required=1)
product_id = fields.Many2one("product", string="Product / Supply", required=1)
transaction_date = fields.Date(string="Transaction Date", required=1, default=fields.Date.today())
transaction_status = fields.Selection([
('pending', 'Pending'),
('complete', 'Complete')
], default="pending", required=1)
price = fields.Float(string="Total Price (RM)", required=1, compute="_compute_price")
quantity = fields.Integer(string="Quantity Left", required=1, compute="_compute_quantity")
purchase = fields.Integer(string="Purchase Quantity", required=1, default="1")
#Create sequence id
@api.model
def create(self, vals):
if vals.get('product_transaction_id', False) == '/':
vals['product_transaction_id'] = self.env['ir.sequence'].next_by_code('product.transaction.sequence')
print(vals)
return super(ProductTransaction, self).create(vals)
#Give Domain For A Field Based On Another Field
@api.onchange('pet_shop_id')
def _onchange_pet_shop_id(self):
for record in self:
if record.pet_shop_id != record.pet_shop_id:
return {'domain': {'product_id': [('pet_shop_id', '=', record.pet_shop_id.id)]}}
else:
record.product_id = None
return {'domain': {'product_id': [('pet_shop_id', '=', record.pet_shop_id.id)]}}
#Status bar for pending and complete
#Pet Shop there the available status will change to sold status
@api.depends('product_id')
@api.model
def action_pending(self):
for record in self:
record.transaction_status = 'pending'
def action_complete(self):
for record in self:
#If the quantity of product is 0, prompt error message
if record.product_id.quantity < record.purchase:
raise ValidationError("Sorry, this product is already sold out")
#reduce the number of quantity
else:
record.transaction_status = 'complete'
record.product_id.quantity = record.product_id.quantity - record.purchase
#Auto show price when select product
@api.depends('product_id', 'purchase')
@api.multi
def _compute_price(self):
for record in self:
if not record.product_id:
record.price = 0.00
else:
record.price = record.product_id.price
record.price = record.purchase * record.product_id.price
#Auto show quantity left when select product
@api.depends('product_id')
@api.multi
def _compute_quantity(self):
for record in self:
if not record.product_id:
record.quantity = 0
else:
record.quantity = record.product_id.quantity
\ 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">
<h2>Pet Transaction (<t t-esc="doc.pet_transaction_id"/>)</h2>
<group>
Customer name: <t t-esc="doc.customer_id.name"/>
</group>
</t>
</t>
</t>
</template>
</odoo>
\ No newline at end of file
<odoo>
<report
id="report_pet_transaction"
string="Pet Transaction"
model="pet.transaction"
report_type="qweb-pdf"
name="pet_shop.report_transaction"
file="pet_shop.report_transaction"/>
</odoo>
\ No newline at end of file
<odoo>
<!--create tree view-->
<record id="customer_tree_view" model="ir.ui.view">
<field name="name">customer.tree.view</field>
<field name="model">customer</field>
<field name="arch" type="xml">
<tree name="Customer">
<field name="name"/>
<field name="gender"/>
<field name="phone_no"/>
<field name="email"/>
</tree>
</field>
</record>
<!--create form view-->
<record id="customer_form_view" model="ir.ui.view">
<field name="name">customer.form.view</field>
<field name="model">customer</field>
<field name="arch" type="xml">
<form name="Customer">
<sheet>
<group string="Customer Info">
<field name="name"/>
<field name="gender"/>
<field name="phone_no"/>
<field name="email"/>
</group>
</sheet>
</form>
</field>
</record>
<!--create action-->
<record id="customer_action" model="ir.actions.act_window">
<field name="res_model">customer</field>
<field name="name">Customer</field>
<field name="view_type">form</field>
<field name="model_type">tree,form</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">Manage Pet Product</p>
</field>
</record>
<!--create menu-->
<menuitem name="Customers" id="customer_menu_act" parent="pet_shop_menu_catalog" action="customer_action" sequence="1"/>
</odoo>
\ No newline at end of file
<odoo>
<!--create tree view-->
<record id="pet_tree_view" model="ir.ui.view">
<field name="name">pet.tree.view</field>
<field name="model">pet</field>
<field name="arch" type="xml">
<tree name="Pets">
<field name="name"/>
<field name="dob"/>
<field name="age"/>
<field name="pet_types"/>
<field name="behavior_types"/>
<field name="price"/>
<field name="pet_status"/>
<field name="pet_shop_id"/>
<!--<field name="customer"/>-->
</tree>
</field>
</record>
<!--create form view-->
<record id="pet_form_view" model="ir.ui.view">
<field name="name">pet.form.view</field>
<field name="model">pet</field>
<field name="arch" type="xml">
<form name="Pets">
<sheet>
<group string="Pet Info">
<group>
<field name="name"/>
</group>
<group>
<field name="pet_shop_id"/>
</group>
</group>
<group>
<group> <!--right side-->
<field name="dob"/>
</group>
<group> <!--left side-->
<field name="age"/>
</group>
</group>
<group>
<group>
<field name="pet_types"/>
</group>
<group>
<field name="behavior_types"/>
</group>
</group>
<group>
<group>
<field name="price"/>
</group>
<group>
<field name="pet_status"/>
</group>
</group>
<!--<group>
<field name="customer"/>
</group>-->
</sheet>
</form>
</field>
</record>
<!--create action-->
<record model="ir.actions.act_window" id="pet_action">
<field name="res_model">pet</field>
<field name="name">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">Manage Your Pet</p>
</field>
</record>
<!--create menu-->
<menuitem name="Pets" id="pet_menu_act" parent="pet_shop_menu_catalog" action="pet_action" sequence="1"/>
</odoo>
\ No newline at end of file
<odoo>
<!--create tree view-->
<record id="pet_action_main_tree" model="ir.ui.view">
<field name="name">pet.shop.tree.view</field>
<field name="model">pet.shop</field>
<field name="arch" type="xml">
<tree name="Pet Shop">
<field name="name"/>
<field name="launch_date"/>
<field name="address"/>
<field name="opening_hour" placeholder="9.00am - 9.00pm"/>
<field name="phone_no" placeholder="0123456789"/>
<field name="email" placeholder="abc@example.com"/>
</tree>
</field>
</record>
<!--create form view-->
<record id="pet_action_main" model="ir.ui.view">
<field name="name">pet.shop.form.view</field>
<field name="model">pet.shop</field>
<field name="arch" type="xml">
<form name="Pet Shop">
<sheet>
<group string="Pet Shop Info">
<field name="name"/>
<field name="launch_date"/>
<field name="address"/>
<field name="opening_hour" placeholder="9.00am - 9.00pm"/>
<field name="phone_no" placeholder="0123456789"/>
<field name="email" placeholder="abc@example.com"/>
</group>
</sheet>
</form>
</field>
</record>
<!--create action-->
<record model="ir.actions.act_window" id="pet_shop_action">
<field name="res_model">pet.shop</field>
<field name="name">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 new Pet Shop</p>
</field>
</record>
<!--create top menu-->
<menuitem name="Pets Shop" id="pet_shop_menu_root" sequence="1"/>
<menuitem name="Shop" id="pet_shop_menu_catalog" parent="pet_shop_menu_root" sequence="1"/>
<menuitem name="Pet Shop" id="pet_shop_menu_act" parent="pet_shop_menu_catalog" action="pet_shop_action" sequence="1"/>
</odoo>
\ No newline at end of file
<odoo>
<!--create tree view-->
<record id="pet_transaction_tree_view" model="ir.ui.view">
<field name="name">pet.transaction.tree.view</field>
<field name="model">pet.transaction</field>
<field name="arch" type="xml">
<tree name="Pet Transaction">
<field name="pet_transaction_id"/>
<field name="customer_id"/>
<field name="pet_shop_id"/>
<field name="pet_id"/>
<field name="transaction_date"/>
<field name="transaction_status"/>
<field name="price"/>
</tree>
</field>
</record>
<!--create form view-->
<record id="pet_transaction_form_view" model="ir.ui.view">
<field name="name">pet.transaction.form.view</field>
<field name="model">pet.transaction</field>
<field name="arch" type="xml">
<form name="Pet Transaction">
<header>
<button name="action_pending" string="Pending" class="oe_highlight" type="object"
attrs="{'invisible': [('transaction_status','=','pending')]}"/>
<button name="action_complete" string="Complete" class="oe_highlight" type="object"
attrs="{'invisible': [('transaction_status','=','complete')]}"/>
<field name="transaction_status" widget="statusbar" statusbar_visible="pending,complete"/>
</header>
<sheet>
<group string="Pet Transaction Info">
<field name="pet_transaction_id" readonly="1" force_save="1"/> <!--force the readonly to save in database / force the readonly data to make it as value-->
<field name="customer_id"/>
<field name="pet_shop_id"/>
<field name="pet_id"/>
<field name="transaction_date" readonly="1" force_save="1"/>
<field name="price"/>
</group>
</sheet>
</form>
</field>
</record>
<!--create action-->
<record id="pet_transaction_action" model="ir.actions.act_window">
<field name="res_model">pet.transaction</field>
<field name="name">Pet Transaction</field>
<field name="view_type">form</field>
<field name="view_model">tree,model</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">Manage Your Pet Transaction</p>
</field>
</record>
<!--sequence number-->
<record id="pet_transaction_sequence" model="ir.sequence">
<field name="name">Transaction No</field>
<field name="code">pet.transaction.sequence</field>
<field name="prefix">PT</field>
<field name="padding">4</field>
</record>
<!--create menu-->
<menuitem name="Pet Transaction" id="pet_transaction_menu_act" parent="pet_shop_menu_catalog" action="pet_transaction_action" sequence="1"/>
</odoo>
\ No newline at end of file
<odoo>
<!--create tree view-->
<record id="product_tree_view" model="ir.ui.view">
<field name="name">product.tree.view</field>
<field name="model">product</field>
<field name="arch" type="xml">
<tree name="Product">
<field name="pet_shop_id"/>
<field name="pet_types"/>
<field name="product_types"/>
<field name="product_name"/>
<field name="price"/>
<field name="description"/>
<field name="quantity"/>
</tree>
</field>
</record>
<!--create form view-->
<record id="product_form_view" model="ir.ui.view">
<field name="name">product.form.view</field>
<field name="model">product</field>
<field name="arch" type="xml">
<form string="Product">
<sheet>
<group string="Product Info">
<field name="pet_shop_id"/>
<field name="pet_types" placeholder="dog, cat, etc..."/>
<field name="product_types" placeholder="supply, food, etc..."/>
<field name="product_name"/>
<field name="price"/>
<field name="description"/>
<field name="quantity"/>
</group>
</sheet>
</form>
</field>
</record>
<!--create action-->
<record id="product_action" model="ir.actions.act_window">
<field name="res_model">product</field>
<field name="name">Product</field>
<field name="view_type">form</field>
<field name="model_type">tree,form</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">Manage Pet Product</p>
</field>
</record>
<!--create menu-->
<menuitem name="Products" id="product_menu_act" parent="pet_shop_menu_catalog" action="product_action" sequence="1"/>
</odoo>
\ No newline at end of file
<odoo>
<!--create tree view-->
<record id="product_transaction_tree_view" model="ir.ui.view">
<field name="name">product.transaction.tree.view</field>
<field name="model">product.transaction</field>
<field name="arch" type="xml">
<tree name="Product Transaction">
<field name="product_transaction_id"/>
<field name="customer_id"/>
<field name="pet_shop_id"/>
<field name="product_id"/>
<field name="purchase"/>
<field name="price"/>
<field name="transaction_date"/>
<field name="transaction_status"/>
</tree>
</field>
</record>
<!--create form view-->
<record id="product_transaction_form_view" model="ir.ui.view">
<field name="name">product.transaction.form.view</field>
<field name="model">product.transaction</field>
<field name="arch" type="xml">
<form name="Product Transaction">
<header>
<button name="action_pending" string="Pending" class="oe_highlight" type="object"
attrs="{'invisible': [('transaction_status','=','pending')]}"/>
<button name="action_complete" string="Complete" class="oe_highlight" type="object"
attrs="{'invisible': [('transaction_status','=','complete')]}"/>
<field name="transaction_status" widget="statusbar" statusbar_visible="pending,complete"/>
</header>
<sheet>
<group string="Product Transaction Info">
<field name="product_transaction_id" readonly="1" force_save="1"/>
<field name="customer_id"/>
<field name="pet_shop_id"/>
<field name="product_id"/>
<field name="purchase"/>
<field name="price"/>
<field name="transaction_date" readonly="1" force_save="1"/>
<field name="quantity"/>
</group>
</sheet>
</form>
</field>
</record>
<!--create action-->
<record id="product_transaction_action" model="ir.actions.act_window">
<field name="res_model">product.transaction</field>
<field name="name">Product Transaction</field>
<field name="view_type">form</field>
<field name="view_model">tree,form</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">Manage your Product Transaction</p>
</field>
</record>
<!--sequence number-->
<record id="product_number_sequence" model="ir.sequence">
<field name="name">Transaction No</field>
<field name="code">product.transaction.sequence</field>
<field name="prefix">PRT</field>
<field name="padding">4</field>
</record>
<!--create menu-->
<menuitem id="product_transaction_menu_act" name="Product Transaction" parent="pet_shop_menu_catalog" action="product_transaction_action" sequence="1"/>
</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