Skip to content

Commit

Permalink
增加基本设置和基本设置的接口
Browse files Browse the repository at this point in the history
  • Loading branch information
elfgzp committed Aug 8, 2017
1 parent 2cc4f5f commit aec1920
Show file tree
Hide file tree
Showing 34 changed files with 4,543 additions and 125 deletions.
23 changes: 16 additions & 7 deletions __manifest__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# -*- coding: utf-8 -*-
{
'name': "wechat_mall",
'application': True,

'summary': """
Short (1 phrase/line) summary of the module's purpose, used as
subtitle on modules listing or apps.openerp.com""",
微信小程序商城管理后台""",

'description': """
Long description of module's purpose
""",

'author': "My Company",
'website': "http://www.yourcompany.com",
'author': "Gzp",
'website': "http://www.elfgzp.cn",

# 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
Expand All @@ -25,11 +25,20 @@
# always loaded
'data': [
# 'security/ir.model.access.csv',
'views/views.xml',
'views/templates.xml',
'views/parent_menus.xml',
'views/wechat_mall_banner_views.xml',
'views/wechat_mall_category_views.xml',
'views/wechat_mall_city_views.xml',
'views/wechat_mall_config_settings_views.xml',
'views/wechat_mall_district_views.xml',
'views/wechat_mall_goods_views.xml',
'views/wechat_mall_logistics_views.xml',
'views/wechat_mall_province_views.xml',
'views/wechat_mall_subshop_views.xml',
'views/wechat_mall_transportation_views.xml',
],
# only loaded in demonstration mode
'demo': [
'demo/demo.xml',
],
}
}
2 changes: 1 addition & 1 deletion controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# -*- coding: utf-8 -*-

from . import controllers
from . import config
35 changes: 35 additions & 0 deletions controllers/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-

import json

from odoo import http

from .error_code import error_code


class Config(http.Controller):
@http.route('/<model("res.users"):user>/config/get-value', auth='public')
def get(self, user, key=None):
if not key:
return json.dumps({'code': 300, 'msg': error_code[300]})

config = http.request.env['wechat_mall.config.settings']
value_obj = config.get_config(key, uid=user.id, obj=True)
if not value_obj:
return json.dumps({'code': 404, 'msg': error_code[404]})

response = {
'code': 0,
'data': {
'creatAt': value_obj.create_date,
'dateType': 0,
'id': value_obj.id,
'key': key,
'remark': '',
'updateAt': value_obj.write_date,
'userId': user.id,
'value': config.get_config(key, uid=user.id)
},
'msg': 'success'
}
return json.dumps(response)
20 changes: 0 additions & 20 deletions controllers/controllers.py

This file was deleted.

22 changes: 22 additions & 0 deletions controllers/error_code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-

error_code = {
-1: u'服务器内部错误',
0: u'接口调用成功',
403: u'禁止访问',
405: u'错误的请求类型',
501: u'数据库错误',
502: u'并发异常,请重试',
600: u'缺少参数',
601: u'无权操作:缺少 token',
602: u'签名错误',
700: u'暂无数据',
701: u'该功能暂未开通',
702: u'资源余额不足',
901: u'token错误',
300: u'缺少key参数',
400: u'域名错误',
401: u'该域名已删除',
402: u'该域名已禁用',
404: u'暂无数据',
}
3,510 changes: 3,510 additions & 0 deletions data.py

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions defs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# -*- coding: utf-8 -*-

from .utils import Const


class LogisticsValuationType(Const):
by_piece = ('by_piece', u'按件')


class TransportType(Const):
express = ('express', u'快递')
ems = ('ems', u'EMS')
post = ('post', u'平邮')
12 changes: 11 additions & 1 deletion models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# -*- coding: utf-8 -*-

from . import models
from . import banner
from . import category
from . import city
from . import config
from . import district
from . import goods
from . import logistics
from . import order
from . import province
from . import subshop
from . import transportation
17 changes: 17 additions & 0 deletions models/banner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-

from odoo import models, fields, api


class Banner(models.Model):
_name = 'wechat_mall.banner'
_description = u'横幅'

user_id = fields.Many2one('res.users', string='所属用户')
type_mark = fields.Integer(string='类型标记(用于扩展)')
business_id = fields.Integer(string='业务编号')
title = fields.Char(string='名称', required=True)
pic = fields.Binary(string='横幅图片', attachment=True)
link_url = fields.Char(string='链接地址')
sort = fields.Integer(string='排序')
remark = fields.Text(string='备注')
18 changes: 18 additions & 0 deletions models/category.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-

from odoo import models, fields, api


class Category(models.Model):
_name = 'wechat_mall.category'
_description = u'商品分类'

user_id = fields.Many2one('res.users', string='所属用户')
name = fields.Char(string='名称')
category_type = fields.Char(string='类型')
pid = fields.Many2one('wechat_mall.category', string='上级分类')
key = fields.Char(string='编号')
icon = fields.Binary(string='图标')
level = fields.Integer(string='分类级别')
is_use = fields.Boolean(string='是否启用')
sort = fields.Integer(string='排序')
11 changes: 11 additions & 0 deletions models/city.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-

from odoo import models, fields


class City(models.Model):
_name = 'wechat_mall.city'
_description = u'市'

pid = fields.Many2one('wechat_mall.province', string='省')
name = fields.Char('名称')
29 changes: 29 additions & 0 deletions models/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-

from odoo import models, fields, api


class ConfigSettings(models.Model):
_name = 'wechat_mall.config.settings'
_description = u'基本设置'
_inherit = 'res.config.settings'

mall_name = fields.Char('商城名称', help='显示在小程序顶部')

@api.model
def default_get(self, fields_list):
return {field: self.get_config(field) for field in fields_list}

@api.multi
def set_default_all(self):
self.env['ir.values'].set_default('wechat_mall.config.settings', 'mall_name_{uid}'.format(uid=self.env.uid),
self.mall_name)

def get_config(self, config_name, uid=False, obj=False):
uid = uid if uid else self.env.uid
if obj:
return self.env['ir.values'].search([('name', '=', '{config_name}_{uid}'.format(uid=uid,
config_name=config_name))])
return self.env['ir.values'].get_default(model=self._name,
field_name='{config_name}_{uid}'.format(uid=uid,
config_name=config_name))
17 changes: 17 additions & 0 deletions models/district.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-

from odoo import models, fields, api


class District(models.Model):
_name = 'wechat_mall.district'
_description = u'区'

pid = fields.Many2one('wechat_mall.city', string='市')
name = fields.Char('名称')

@api.model_cr
def _register_hook(self):
""" stuff to do right after the registry is built """
from .. import data
self.env.cr.execute(data.province_city_district_data)
26 changes: 26 additions & 0 deletions models/goods.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-

from odoo import models, fields


class Goods(models.Model):
_name = 'wechat_mall.goods'
_description = u'商品'

user_id = fields.Many2one('res.users', string='所属用户')
subshop_id = fields.Many2one('wechat_mall.subshop', string='所属店铺')
category_id = fields.Many2one('wechat_mall.category', string='商品分类')
name = fields.Char('商品名称')
characteristic = fields.Text('商品特色')
logistics_id = fields.Many2one('wechat_mall.logistics', string='物流模板')
sort = fields.Integer('排序')
recommend_status = fields.Boolean('是否推荐')
pic = fields.One2many('ir.attachment', 'res_id', string='图片')
content = fields.Html('详细介绍')
original_price = fields.Float('原价')
min_price = fields.Float('最低价')
stores = fields.Integer('库存')
number_good_reputation = fields.Integer('好评数')
number_order = fields.Integer('订单数')
number_fav = fields.Integer('收藏数')
views = fields.Integer('浏览量')
17 changes: 17 additions & 0 deletions models/logistics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-

from odoo import models, fields

from .. import defs


class Logistics(models.Model):
_name = 'wechat_mall.logistics'
_description = u'物流'

name = fields.Char('名称')
free = fields.Boolean('是否包邮')
valuation_type = fields.Selection(defs.LogisticsValuationType.attrs.items(), string='计价方式')

transportation_ids = fields.One2many('wechat_mall.transportation', 'logistics_id', string='运送费用')

15 changes: 0 additions & 15 deletions models/models.py

This file was deleted.

5 changes: 5 additions & 0 deletions models/order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-

from odoo import models, fields


10 changes: 10 additions & 0 deletions models/province.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-

from odoo import models, fields


class Province(models.Model):
_name = 'wechat_mall.province'
_description = u'省'

name = fields.Char('名称')
26 changes: 26 additions & 0 deletions models/subshop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-

from odoo import models, fields, api


class SubShop(models.Model):
_name = 'wechat_mall.subshop'
_description = u'商铺'

user_id = fields.Many2one('res.users', string='所属用户')
shop_type = fields.Char('店铺类型')
province_id = fields.Many2one('wechat_mall.province', string='省', required=True)
city_id = fields.Many2one('wechat_mall.city', string='市', required=True)
district_id = fields.Many2one('wechat_mall.district', string='区', required=True)
name = fields.Char('店铺名称', required=True)
address = fields.Char('地址')
phone = fields.Char('联系电话')
introduce = fields.Text('店铺介绍')
characteristic = fields.Text('店铺特色')
sort = fields.Integer('排序')
pic = fields.Binary('图片', attachment=True)
activity = fields.Char('打折优惠信息')
latitude = fields.Float('纬度')
longitude = fields.Float('经度')
number_good_reputation = fields.Integer('好评数')
number_order = fields.Integer('订单数')
21 changes: 21 additions & 0 deletions models/transportation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-

from odoo import models, fields

from .. import defs


class Transportation(models.Model):
_name = 'wechat_mall.transportation'
_description = u'运输费'

user_id = fields.Many2one('res.users', string='所属用户')
logistics_id = fields.Many2one('wechat_mall.logistics', string='物流')
transport_type = fields.Selection(defs.TransportType.attrs.items(), string='运输方式', required=True)
province_id = fields.Many2one('wechat_mall.province', string='省', required=True)
city_id = fields.Many2one('wechat_mall.city', string='市', required=True)
district_id = fields.Many2one('wechat_mall.district', string='区', required=True)
less_amount = fields.Integer('数量', required=True)
less_price = fields.Float('数量内价格', required=True)
beyond_amount = fields.Integer('超过数量', required=True)
beyond_price = fields.Float('递增价格', required=True)
Loading

0 comments on commit aec1920

Please sign in to comment.