mirror of
https://github.com/guohuadeng/app-odoo.git
synced 2025-02-23 04:11:36 +02:00
init common and customize
This commit is contained in:
11
app_odoo_customize/models/__init__.py
Normal file
11
app_odoo_customize/models/__init__.py
Normal file
@@ -0,0 +1,11 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from . import res_config_settings
|
||||
from . import base_language_install
|
||||
from . import ir_module_module
|
||||
from . import web_environment_ribbon_backend
|
||||
from . import ir_http
|
||||
from . import ir_module_addons_path
|
||||
from . import mail_thread
|
||||
# from . import ir_ui_view
|
||||
# from . import ir_ui_menu
|
||||
8
app_odoo_customize/models/base_language_install.py
Normal file
8
app_odoo_customize/models/base_language_install.py
Normal file
@@ -0,0 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
|
||||
|
||||
class BaseLanguageInstall(models.TransientModel):
|
||||
_inherit = "base.language.install"
|
||||
38
app_odoo_customize/models/ir_http.py
Normal file
38
app_odoo_customize/models/ir_http.py
Normal file
@@ -0,0 +1,38 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
|
||||
from odoo import models
|
||||
from odoo.http import request
|
||||
|
||||
|
||||
|
||||
class IrHttp(models.AbstractModel):
|
||||
_inherit = 'ir.http'
|
||||
|
||||
def session_info(self):
|
||||
result = super(IrHttp, self).session_info()
|
||||
config_parameter = request.env['ir.config_parameter'].sudo()
|
||||
result['app_system_name'] = config_parameter.get_param('app_system_name', 'odooAi')
|
||||
result['app_documentation_url'] = config_parameter.get_param('app_documentation_url')
|
||||
result['app_documentation_dev_url'] = config_parameter.get_param('app_documentation_dev_url')
|
||||
result['app_support_url'] = config_parameter.get_param('app_support_url')
|
||||
result['app_account_title'] = config_parameter.get_param('app_account_title')
|
||||
result['app_account_url'] = config_parameter.get_param('app_account_url')
|
||||
result['app_show_lang'] = config_parameter.get_param('app_show_lang')
|
||||
result['app_show_debug'] = config_parameter.get_param('app_show_debug')
|
||||
result['app_show_documentation'] = config_parameter.get_param('app_show_documentation')
|
||||
result['app_show_documentation_dev'] = config_parameter.get_param('app_show_documentation_dev')
|
||||
result['app_show_support'] = config_parameter.get_param('app_show_support')
|
||||
result['app_show_account'] = config_parameter.get_param('app_show_account')
|
||||
result['app_show_poweredby'] = config_parameter.get_param('app_show_poweredby')
|
||||
# 增加多语言
|
||||
result['app_lang_list'] = self.env['res.lang'].search_read([], ['id', 'code', 'name'])
|
||||
result['is_erp_manager'] = self.env.user.has_group('base.group_erp_manager')
|
||||
# 增加 bar位置处理
|
||||
result['app_navbar_pos_pc'] = config_parameter.get_param('app_navbar_pos_pc', 'top')
|
||||
result['app_navbar_pos_mobile'] = config_parameter.get_param('app_navbar_pos_mobile', 'top')
|
||||
# 此处直接取,不用 session
|
||||
result['app_debug_only_admin'] = config_parameter.get_param('app_debug_only_admin')
|
||||
result['app_stop_subscribe'] = config_parameter.get_param('app_stop_subscribe')
|
||||
return result
|
||||
41
app_odoo_customize/models/ir_module_addons_path.py
Normal file
41
app_odoo_customize/models/ir_module_addons_path.py
Normal file
@@ -0,0 +1,41 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import random
|
||||
from odoo import api, fields, models, modules, tools, _
|
||||
|
||||
|
||||
class IrModuleAddonsPath(models.Model):
|
||||
_name = "ir.module.addons.path"
|
||||
_description = 'Module Addons Path'
|
||||
|
||||
def _default_bg_color(self):
|
||||
colors = ['#F06050', '#F4A45F', '#F7CD2E', '#6CC1ED', '#EB7E7F', '#5CC482',
|
||||
'#2c8297', '#D8485E', '#9365B8', '#804967', '#475576', ]
|
||||
res = '#FFFFFF'
|
||||
try:
|
||||
res = random.choice(colors)
|
||||
except:
|
||||
pass
|
||||
return res
|
||||
|
||||
name = fields.Char(string='Short Name')
|
||||
path = fields.Char(string='Path')
|
||||
path_temp = fields.Char(string='Path Temp')
|
||||
color = fields.Char(default=_default_bg_color)
|
||||
module_ids = fields.One2many('ir.module.module', 'addons_path_id')
|
||||
module_count = fields.Integer(compute='_compute_module_count')
|
||||
|
||||
def _compute_module_count(self):
|
||||
for rec in self:
|
||||
rec.module_count = len(rec.module_ids)
|
||||
|
||||
def open_apps_view(self):
|
||||
self.ensure_one()
|
||||
|
||||
return {'type': 'ir.actions.act_window',
|
||||
'name': 'Apps',
|
||||
'view_mode': 'kanban,tree,form',
|
||||
'res_model': 'ir.module.module',
|
||||
'context': {},
|
||||
'domain': [('addons_path_id', '=', self.id)],
|
||||
}
|
||||
84
app_odoo_customize/models/ir_module_module.py
Normal file
84
app_odoo_customize/models/ir_module_module.py
Normal file
@@ -0,0 +1,84 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from odoo import api, fields, models, modules, tools, _
|
||||
|
||||
import operator
|
||||
|
||||
|
||||
class IrModule(models.Model):
|
||||
_inherit = 'ir.module.module'
|
||||
|
||||
# attention: Incorrect field names !!
|
||||
# installed_version refers the latest version (the one on disk)
|
||||
# latest_version refers the installed version (the one in database)
|
||||
# published_version refers the version available on the repository
|
||||
# installed_version = fields.Char('Latest Version', compute='_get_latest_version')
|
||||
# latest_version = fields.Char('Installed Version', readonly=True)
|
||||
|
||||
local_updatable = fields.Boolean('Local updatable', compute=False, default=False, store=True)
|
||||
addons_path_id = fields.Many2one('ir.module.addons.path', string='Addons Path ID', readonly=True)
|
||||
addons_path = fields.Char(string='Addons Path', related='addons_path_id.path', readonly=True)
|
||||
license = fields.Char(readonly=True)
|
||||
|
||||
def module_multi_uninstall(self):
|
||||
""" Perform the various steps required to uninstall a module completely
|
||||
including the deletion of all database structures created by the module:
|
||||
tables, columns, constraints, etc.
|
||||
"""
|
||||
modules = self.browse(self.env.context.get('active_ids'))
|
||||
[module.button_immediate_uninstall() for module in modules if module not in ['base', 'web']]
|
||||
|
||||
# 更新翻译,当前语言
|
||||
def module_multi_refresh_po(self):
|
||||
lang = self.env.user.lang
|
||||
modules = self.filtered(lambda r: r.state == 'installed')
|
||||
# 先清理, odoo原生经常清理不干净
|
||||
# odoo 16中,不再使用 ir.translation,直接使用json字段
|
||||
# for rec in modules:
|
||||
# translate = self.env['ir.translation'].search([
|
||||
# ('lang', '=', lang),
|
||||
# ('module', '=', rec.name)
|
||||
# ])
|
||||
# translate.sudo().unlink()
|
||||
# 再重载
|
||||
modules._update_translations(filter_lang=lang, overwrite=True)
|
||||
# odoo 16翻译模式改变,仍需更新模块
|
||||
return {
|
||||
'type': 'ir.actions.client',
|
||||
'tag': 'display_notification',
|
||||
'target': 'new',
|
||||
'params': {
|
||||
'message': _("The languages that you selected have been successfully update.\
|
||||
You still need to Upgrade the apps to make it worked."),
|
||||
'type': 'success',
|
||||
'sticky': False,
|
||||
'next': {'type': 'ir.actions.act_window_close'},
|
||||
}
|
||||
}
|
||||
|
||||
def button_get_po(self):
|
||||
self.ensure_one()
|
||||
action = self.env.ref('app_odoo_customize.action_server_module_multi_get_po').sudo().read()[0]
|
||||
action['context'].update({
|
||||
'default_lang': self.env.user.lang,
|
||||
})
|
||||
return action
|
||||
|
||||
def update_list(self):
|
||||
res = super(IrModule, self).update_list()
|
||||
default_version = modules.adapt_version('1.0')
|
||||
known_mods = self.with_context(lang=None).search([])
|
||||
known_mods_names = {mod.name: mod for mod in known_mods}
|
||||
# 处理可更新字段, 不要compute,会出错
|
||||
for mod_name in modules.get_modules():
|
||||
mod = known_mods_names.get(mod_name)
|
||||
if mod:
|
||||
installed_version = self.get_module_info(mod.name).get('version', default_version)
|
||||
if installed_version and mod.latest_version and operator.gt(installed_version, mod.latest_version):
|
||||
local_updatable = True
|
||||
else:
|
||||
local_updatable = False
|
||||
if mod.local_updatable != local_updatable:
|
||||
mod.write({'local_updatable': local_updatable})
|
||||
|
||||
return res
|
||||
26
app_odoo_customize/models/ir_ui_menu.py
Normal file
26
app_odoo_customize/models/ir_ui_menu.py
Normal file
@@ -0,0 +1,26 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import re
|
||||
|
||||
from odoo import api, fields, models, tools, _
|
||||
|
||||
MENU_ITEM_SEPARATOR = "/"
|
||||
NUMBER_PARENS = re.compile(r"\(([0-9]+)\)")
|
||||
|
||||
|
||||
class IrUiMenu(models.Model):
|
||||
_inherit = 'ir.ui.menu'
|
||||
|
||||
def _get_full_name(self, level=6):
|
||||
""" Return the full name of ``self`` (up to a certain level). """
|
||||
if level <= 0:
|
||||
return '...'
|
||||
if self.parent_id:
|
||||
try:
|
||||
name = self.parent_id._get_full_name(level - 1) + MENU_ITEM_SEPARATOR + (self.name or "")
|
||||
except Exception:
|
||||
name = self.name or "..."
|
||||
else:
|
||||
name = self.name
|
||||
return name
|
||||
|
||||
17
app_odoo_customize/models/ir_ui_view.py
Normal file
17
app_odoo_customize/models/ir_ui_view.py
Normal file
@@ -0,0 +1,17 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import logging
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
class View(models.Model):
|
||||
_inherit = 'ir.ui.view'
|
||||
|
||||
def _render_template(self, template, values=None, engine='ir.qweb'):
|
||||
# if template in ['web.login', 'web.webclient_bootstrap']:
|
||||
if not values:
|
||||
values = {}
|
||||
values["title"] = values["app_title"] = self.env['ir.config_parameter'].sudo().get_param("app_system_name", "odooAi")
|
||||
return super(View, self)._render_template(template, values=values, engine=engine)
|
||||
44
app_odoo_customize/models/mail_thread.py
Normal file
44
app_odoo_customize/models/mail_thread.py
Normal file
@@ -0,0 +1,44 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
|
||||
|
||||
class MailThread(models.AbstractModel):
|
||||
_inherit = "mail.thread"
|
||||
|
||||
def message_subscribe(self, partner_ids=None, channel_ids=None, subtype_ids=None):
|
||||
""" 停用订阅功能. """
|
||||
ir_config = self.env['ir.config_parameter']
|
||||
app_stop_subscribe = True if ir_config.get_param('app_stop_subscribe', False) == "True" else False
|
||||
if app_stop_subscribe:
|
||||
return True
|
||||
else:
|
||||
return super(MailThread, self).message_subscribe(partner_ids, subtype_ids)
|
||||
|
||||
def _message_subscribe(self, partner_ids=None, channel_ids=None, subtype_ids=None, customer_ids=None):
|
||||
""" 停用订阅功能. """
|
||||
ir_config = self.env['ir.config_parameter']
|
||||
app_stop_subscribe = True if ir_config.get_param('app_stop_subscribe', False) == "True" else False
|
||||
if app_stop_subscribe:
|
||||
return True
|
||||
else:
|
||||
return super(MailThread, self)._message_subscribe(partner_ids, subtype_ids, customer_ids)
|
||||
|
||||
def _message_auto_subscribe_followers(self, updated_values, default_subtype_ids):
|
||||
""" 停用订阅功能. """
|
||||
ir_config = self.env['ir.config_parameter']
|
||||
app_stop_subscribe = True if ir_config.get_param('app_stop_subscribe', False) == "True" else False
|
||||
if app_stop_subscribe:
|
||||
return []
|
||||
else:
|
||||
return super(MailThread, self)._message_auto_subscribe_followers(updated_values, default_subtype_ids)
|
||||
|
||||
def _message_auto_subscribe_notify(self, partner_ids, template):
|
||||
""" 停用订阅功能. """
|
||||
ir_config = self.env['ir.config_parameter']
|
||||
app_stop_subscribe = True if ir_config.get_param('app_stop_subscribe', False) == "True" else False
|
||||
if app_stop_subscribe:
|
||||
return True
|
||||
else:
|
||||
return super(MailThread, self)._message_auto_subscribe_notify(partner_ids, template)
|
||||
531
app_odoo_customize/models/res_config_settings.py
Normal file
531
app_odoo_customize/models/res_config_settings.py
Normal file
@@ -0,0 +1,531 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import logging
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.exceptions import UserError, ValidationError
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ResConfigSettings(models.TransientModel):
|
||||
_inherit = 'res.config.settings'
|
||||
|
||||
app_system_name = fields.Char('System Name', help="Setup System Name,which replace Odoo",
|
||||
default='odooAi', config_parameter='app_system_name')
|
||||
app_show_lang = fields.Boolean('Show Quick Language Switcher',
|
||||
help="When enable,User can quick switch language in user menu",
|
||||
config_parameter='app_show_lang')
|
||||
app_show_debug = fields.Boolean('Show Quick Debug', help="When enable,everyone login can see the debug menu",
|
||||
config_parameter='app_show_debug')
|
||||
app_show_documentation = fields.Boolean('Show Documentation', help="When enable,User can visit user manual",
|
||||
config_parameter='app_show_documentation')
|
||||
# 停用
|
||||
app_show_documentation_dev = fields.Boolean('Show Developer Documentation',
|
||||
help="When enable,User can visit development documentation")
|
||||
app_show_support = fields.Boolean('Show Support', help="When enable,User can vist your support site",
|
||||
config_parameter='app_show_support')
|
||||
app_show_account = fields.Boolean('Show My Account', help="When enable,User can login to your website",
|
||||
config_parameter='app_show_account')
|
||||
app_show_enterprise = fields.Boolean('Show Enterprise Tag', help="Uncheck to hide the Enterprise tag",
|
||||
config_parameter='app_show_enterprise')
|
||||
app_show_share = fields.Boolean('Show Share Dashboard', help="Uncheck to hide the Odoo Share Dashboard",
|
||||
config_parameter='app_show_share')
|
||||
app_show_poweredby = fields.Boolean('Show Powered by Odoo', help="Uncheck to hide the Powered by text",
|
||||
config_parameter='app_show_poweredby')
|
||||
group_show_author_in_apps = fields.Boolean(string="Show Author in Apps Dashboard", implied_group='app_odoo_customize.group_show_author_in_apps',
|
||||
help="Uncheck to Hide Author and Website in Apps Dashboard")
|
||||
module_odoo_referral = fields.Boolean('Show Odoo Referral', help="Uncheck to remove the Odoo Referral")
|
||||
|
||||
app_documentation_url = fields.Char('Documentation Url', config_parameter='app_documentation_url')
|
||||
app_documentation_dev_url = fields.Char('Developer Documentation Url', config_parameter='app_documentation_dev_url')
|
||||
app_support_url = fields.Char('Support Url', config_parameter='app_support_url')
|
||||
app_account_title = fields.Char('My Odoo.com Account Title', config_parameter='app_account_title')
|
||||
app_account_url = fields.Char('My Odoo.com Account Url', config_parameter='app_account_url')
|
||||
app_enterprise_url = fields.Char('Customize Module Url(eg. Enterprise)', config_parameter='app_enterprise_url')
|
||||
app_ribbon_name = fields.Char('Show Demo Ribbon', config_parameter='app_ribbon_name')
|
||||
app_navbar_pos_pc = fields.Selection(string="Navbar PC", selection=[
|
||||
('top', 'Top(Default)'),
|
||||
('bottom', 'Bottom'),
|
||||
# ('left', 'Left'),
|
||||
], config_parameter='app_navbar_pos_pc')
|
||||
app_navbar_pos_mobile = fields.Selection(string="Navbar Mobile", selection=[
|
||||
('top', 'Top(Default)'),
|
||||
('bottom', 'Bottom'),
|
||||
# ('left', 'Left'),
|
||||
], config_parameter='app_navbar_pos_mobile')
|
||||
|
||||
# 安全与提速
|
||||
app_debug_only_admin = fields.Boolean('Debug for Admin', config_parameter='app_debug_only_admin',
|
||||
help="Check to only Debug / Debug Assets for Odoo Admin. Deny debug from url for other user.")
|
||||
app_stop_subscribe = fields.Boolean('Stop Odoo Subscribe', help="Check to stop subscribe and follow. This to make odoo speed up.",
|
||||
config_parameter='app_stop_subscribe')
|
||||
# 处理额外模块
|
||||
module_app_odoo_doc = fields.Boolean("Help Document Anywhere", help='Get Help Documentation on current odoo operation or topic.')
|
||||
module_app_chatgpt = fields.Boolean("Ai Center", help='Use Ai to boost you business.')
|
||||
|
||||
# 应用帮助文档
|
||||
app_doc_root_url = fields.Char('Help of topic domain', config_parameter='app_doc_root_url', default='https://odooai.cn')
|
||||
|
||||
@api.model
|
||||
def set_module_url(self, rec=None):
|
||||
if not self._app_check_sys_op():
|
||||
raise UserError(_('Not allow.'))
|
||||
config_parameter = self.env['ir.config_parameter'].sudo()
|
||||
app_enterprise_url = config_parameter.get_param('app_enterprise_url', 'https://www.odooai.cn')
|
||||
modules = self.env['ir.module.module'].search([('license', 'like', 'OEEL%'), ('website', '!=', False)])
|
||||
if modules:
|
||||
sql = "UPDATE ir_module_module SET website = '%s' WHERE id IN %s" % (app_enterprise_url, tuple(modules.ids))
|
||||
try:
|
||||
self._cr.execute(sql)
|
||||
except Exception as e:
|
||||
pass
|
||||
|
||||
# 清数据,o=对象, s=序列
|
||||
def _remove_app_data(self, o, s=[]):
|
||||
if not self._app_check_sys_op():
|
||||
raise UserError(_('Not allow.'))
|
||||
for line in o:
|
||||
# 检查是否存在
|
||||
try:
|
||||
if not self.env['ir.model']._get(line):
|
||||
continue
|
||||
except Exception as e:
|
||||
_logger.warning('remove data error get ir.model: %s,%s', line, e)
|
||||
continue
|
||||
obj_name = line
|
||||
obj = self.pool.get(obj_name)
|
||||
if not obj:
|
||||
# 有时安装出错数据乱,没有 obj 但有 table
|
||||
t_name = obj_name.replace('.', '_')
|
||||
else:
|
||||
t_name = obj._table
|
||||
|
||||
sql = "delete from %s" % t_name
|
||||
# 增加多公司处理
|
||||
try:
|
||||
self._cr.execute(sql)
|
||||
self._cr.commit()
|
||||
except Exception as e:
|
||||
_logger.warning('remove data error: %s,%s', line, e)
|
||||
# 更新序号
|
||||
for line in s:
|
||||
domain = ['|', ('code', '=ilike', line + '%'), ('prefix', '=ilike', line + '%')]
|
||||
try:
|
||||
seqs = self.env['ir.sequence'].sudo().search(domain)
|
||||
if seqs.exists():
|
||||
seqs.write({
|
||||
'number_next': 1,
|
||||
})
|
||||
except Exception as e:
|
||||
_logger.warning('reset sequence data error: %s,%s', line, e)
|
||||
return True
|
||||
|
||||
def remove_sales(self):
|
||||
to_removes = [
|
||||
# 清除销售单据
|
||||
'sale.order.line',
|
||||
'sale.order',
|
||||
# 销售提成,自用
|
||||
# 'sale.commission.line',
|
||||
# 不能删除报价单模板
|
||||
'sale.order.template.option',
|
||||
'sale.order.template.line',
|
||||
'sale.order.template',
|
||||
]
|
||||
seqs = [
|
||||
'sale',
|
||||
]
|
||||
return self._remove_app_data(to_removes, seqs)
|
||||
|
||||
def remove_product(self):
|
||||
to_removes = [
|
||||
# 清除产品数据
|
||||
'product.product',
|
||||
'product.template',
|
||||
]
|
||||
seqs = [
|
||||
'product.product',
|
||||
]
|
||||
return self._remove_app_data(to_removes, seqs)
|
||||
|
||||
def remove_product_attribute(self):
|
||||
to_removes = [
|
||||
# 清除产品属性
|
||||
'product.attribute.value',
|
||||
'product.attribute',
|
||||
]
|
||||
seqs = []
|
||||
return self._remove_app_data(to_removes, seqs)
|
||||
|
||||
def remove_pos(self):
|
||||
to_removes = [
|
||||
# 清除POS单据
|
||||
'pos.payment',
|
||||
'pos.order.line',
|
||||
'pos.order',
|
||||
'pos.session',
|
||||
]
|
||||
seqs = [
|
||||
'pos.',
|
||||
]
|
||||
res = self._remove_app_data(to_removes, seqs)
|
||||
|
||||
# 更新要关帐的值,因为 store=true 的计算字段要重置
|
||||
|
||||
try:
|
||||
statement = self.env['account.bank.statement'].search([])
|
||||
for s in statement:
|
||||
s._end_balance()
|
||||
except Exception as e:
|
||||
_logger.error('reset sequence data error: %s', e)
|
||||
return res
|
||||
|
||||
def remove_purchase(self):
|
||||
to_removes = [
|
||||
# 清除采购单据
|
||||
'purchase.order.line',
|
||||
'purchase.order',
|
||||
'purchase.requisition.line',
|
||||
'purchase.requisition',
|
||||
]
|
||||
seqs = [
|
||||
'purchase.',
|
||||
]
|
||||
return self._remove_app_data(to_removes, seqs)
|
||||
|
||||
def remove_expense(self):
|
||||
to_removes = [
|
||||
# 清除
|
||||
'hr.expense.sheet',
|
||||
'hr.expense',
|
||||
'hr.payslip',
|
||||
'hr.payslip.run',
|
||||
]
|
||||
seqs = [
|
||||
'hr.expense.',
|
||||
]
|
||||
return self._remove_app_data(to_removes, seqs)
|
||||
|
||||
def remove_mrp(self):
|
||||
to_removes = [
|
||||
# 清除生产单据
|
||||
'mrp.workcenter.productivity',
|
||||
'mrp.workorder',
|
||||
# 'mrp.production.workcenter.line',
|
||||
'change.production.qty',
|
||||
'mrp.production',
|
||||
# 'mrp.production.product.line',
|
||||
'mrp.unbuild',
|
||||
'change.production.qty',
|
||||
# 'sale.forecast.indirect',
|
||||
# 'sale.forecast',
|
||||
]
|
||||
seqs = [
|
||||
'mrp.',
|
||||
]
|
||||
return self._remove_app_data(to_removes, seqs)
|
||||
|
||||
def remove_mrp_bom(self):
|
||||
to_removes = [
|
||||
# 清除生产BOM
|
||||
'mrp.bom.line',
|
||||
'mrp.bom',
|
||||
]
|
||||
seqs = []
|
||||
return self._remove_app_data(to_removes, seqs)
|
||||
|
||||
def remove_inventory(self):
|
||||
to_removes = [
|
||||
# 清除库存单据
|
||||
'stock.quant',
|
||||
'stock.move.line',
|
||||
'stock.package_level',
|
||||
'stock.quantity.history',
|
||||
'stock.quant.package',
|
||||
'stock.move',
|
||||
# 'stock.pack.operation',
|
||||
'stock.picking',
|
||||
'stock.scrap',
|
||||
'stock.picking.batch',
|
||||
'stock.inventory.adjustment.name',
|
||||
'stock.valuation.layer',
|
||||
'stock.lot',
|
||||
# 'stock.fixed.putaway.strat',
|
||||
'procurement.group',
|
||||
]
|
||||
seqs = [
|
||||
'stock.',
|
||||
'picking.',
|
||||
'procurement.group',
|
||||
'product.tracking.default',
|
||||
'WH/',
|
||||
]
|
||||
return self._remove_app_data(to_removes, seqs)
|
||||
|
||||
def remove_account(self):
|
||||
to_removes = [
|
||||
# 清除财务会计单据
|
||||
'payment.transaction',
|
||||
# 'account.voucher.line',
|
||||
# 'account.voucher',
|
||||
# 'account.invoice.line',
|
||||
# 'account.invoice.refund',
|
||||
# 'account.invoice',
|
||||
'account.bank.statement.line',
|
||||
'account.payment',
|
||||
'account.batch.payment',
|
||||
'account.analytic.line',
|
||||
'account.analytic.account',
|
||||
'account.partial.reconcile',
|
||||
'account.move.line',
|
||||
'hr.expense.sheet',
|
||||
'account.move',
|
||||
]
|
||||
res = self._remove_app_data(to_removes, [])
|
||||
|
||||
# extra 更新序号
|
||||
domain = [
|
||||
('company_id', '=', self.env.company.id),
|
||||
'|', ('code', '=ilike', 'account.%'),
|
||||
'|', ('prefix', '=ilike', 'BNK1/%'),
|
||||
'|', ('prefix', '=ilike', 'CSH1/%'),
|
||||
'|', ('prefix', '=ilike', 'INV/%'),
|
||||
'|', ('prefix', '=ilike', 'EXCH/%'),
|
||||
'|', ('prefix', '=ilike', 'MISC/%'),
|
||||
'|', ('prefix', '=ilike', '账单/%'),
|
||||
('prefix', '=ilike', '杂项/%')
|
||||
]
|
||||
try:
|
||||
seqs = self.env['ir.sequence'].search(domain)
|
||||
if seqs.exists():
|
||||
seqs.write({
|
||||
'number_next': 1,
|
||||
})
|
||||
except Exception as e:
|
||||
_logger.error('reset sequence data error: %s,%s', domain, e)
|
||||
return res
|
||||
|
||||
def remove_account_chart(self):
|
||||
company_id = self.env.company.id
|
||||
self = self.with_company(self.env.company)
|
||||
to_removes = [
|
||||
# 清除财务科目,用于重设
|
||||
'res.partner.bank',
|
||||
# 'account.invoice',
|
||||
'account.payment',
|
||||
'account.bank.statement',
|
||||
# 'account.tax.account.tag',
|
||||
'account.tax',
|
||||
# 'wizard_multi_charts_accounts',
|
||||
'account.account',
|
||||
]
|
||||
# todo: 要做 remove_hr,因为工资表会用到 account
|
||||
# 更新account关联,很多是多公司字段,故只存在 ir_property,故在原模型,只能用update
|
||||
try:
|
||||
field1 = self.env['ir.model.fields']._get('product.template', "taxes_id").id
|
||||
field2 = self.env['ir.model.fields']._get('product.template', "supplier_taxes_id").id
|
||||
|
||||
sql = "delete from ir_default where (field_id = %s or field_id = %s) and company_id=%d" \
|
||||
% (field1, field2, company_id)
|
||||
sql2 = "update account_journal set bank_account_id=NULL where company_id=%d;" % company_id
|
||||
self._cr.execute(sql)
|
||||
self._cr.execute(sql2)
|
||||
|
||||
self._cr.commit()
|
||||
except Exception as e:
|
||||
_logger.error('remove data error: %s,%s', 'account_chart: set tax and account_journal', e)
|
||||
|
||||
# 增加对 pos的处理
|
||||
if self.env['ir.model']._get('pos.config'):
|
||||
self.env['pos.config'].write({
|
||||
'journal_id': False,
|
||||
})
|
||||
# todo: 以下处理参考 res.partner的合并,将所有m2o的都一次处理,不需要次次找模型
|
||||
# partner 处理
|
||||
try:
|
||||
rec = self.env['res.partner'].search([])
|
||||
for r in rec:
|
||||
r.write({
|
||||
'property_account_receivable_id': None,
|
||||
'property_account_payable_id': None,
|
||||
})
|
||||
except Exception as e:
|
||||
_logger.error('remove data error: %s,%s', 'account_chart', e)
|
||||
# 品类处理
|
||||
try:
|
||||
rec = self.env['product.category'].search([])
|
||||
for r in rec:
|
||||
r.write({
|
||||
'property_account_income_categ_id': None,
|
||||
'property_account_expense_categ_id': None,
|
||||
'property_account_creditor_price_difference_categ': None,
|
||||
'property_stock_account_input_categ_id': None,
|
||||
'property_stock_account_output_categ_id': None,
|
||||
'property_stock_valuation_account_id': None,
|
||||
})
|
||||
except Exception as e:
|
||||
pass
|
||||
# 产品处理
|
||||
try:
|
||||
rec = self.env['product.template'].search([])
|
||||
for r in rec:
|
||||
r.write({
|
||||
'property_account_income_id': None,
|
||||
'property_account_expense_id': None,
|
||||
})
|
||||
except Exception as e:
|
||||
pass
|
||||
# 库存计价处理
|
||||
try:
|
||||
rec = self.env['stock.location'].search([])
|
||||
for r in rec:
|
||||
r.write({
|
||||
'valuation_in_account_id': None,
|
||||
'valuation_out_account_id': None,
|
||||
})
|
||||
except Exception as e:
|
||||
pass # raise Warning(e)
|
||||
|
||||
try:
|
||||
rec = self.env['account.journal'].search([])
|
||||
rec.write({
|
||||
'default_account_id': False,
|
||||
'suspense_account_id': False
|
||||
})
|
||||
except Exception as e:
|
||||
pass
|
||||
|
||||
seqs = []
|
||||
|
||||
res = self._remove_app_data(to_removes, seqs)
|
||||
return res
|
||||
|
||||
def remove_project(self):
|
||||
to_removes = [
|
||||
# 清除项目
|
||||
'account.analytic.line',
|
||||
'project.task',
|
||||
# 'project.forecast',
|
||||
'project.update',
|
||||
'project.project',
|
||||
'project.collaborator',
|
||||
'project.milestone',
|
||||
# 'project.project.stage',
|
||||
'project.task.recurrence',
|
||||
# 表名为 project_task_user_rel
|
||||
'project.task.stage.personal',
|
||||
]
|
||||
seqs = []
|
||||
return self._remove_app_data(to_removes, seqs)
|
||||
|
||||
def remove_quality(self):
|
||||
to_removes = [
|
||||
# 清除质检数据
|
||||
'quality.check',
|
||||
'quality.alert',
|
||||
# 'quality.point',
|
||||
# 'quality.alert.stage',
|
||||
# 'quality.alert.team',
|
||||
# 'quality.point.test_type',
|
||||
# 'quality.reason',
|
||||
# 'quality.tag',
|
||||
]
|
||||
seqs = [
|
||||
'quality.check',
|
||||
'quality.alert',
|
||||
# 'quality.point',
|
||||
]
|
||||
return self._remove_app_data(to_removes, seqs)
|
||||
|
||||
def remove_quality_setting(self):
|
||||
to_removes = [
|
||||
# 清除质检设置
|
||||
'quality.point',
|
||||
'quality.alert.stage',
|
||||
'quality.alert.team',
|
||||
'quality.point.test_type',
|
||||
'quality.reason',
|
||||
'quality.tag',
|
||||
]
|
||||
return self._remove_app_data(to_removes)
|
||||
|
||||
def remove_website(self):
|
||||
to_removes = [
|
||||
# 清除网站数据,w, w_blog
|
||||
'blog.tag.category',
|
||||
'blog.tag',
|
||||
'blog.post',
|
||||
'blog.blog',
|
||||
'product.wishlist',
|
||||
'website.published.multi.mixin',
|
||||
'website.published.mixin',
|
||||
'website.multi.mixin',
|
||||
'website.visitor',
|
||||
'website.rewrite',
|
||||
'website.seo.metadata',
|
||||
# 'website.page',
|
||||
# 'website.menu',
|
||||
# 'website',
|
||||
]
|
||||
seqs = []
|
||||
return self._remove_app_data(to_removes, seqs)
|
||||
|
||||
def remove_message(self):
|
||||
to_removes = [
|
||||
# 清除消息数据
|
||||
'mail.message',
|
||||
'mail.followers',
|
||||
'mail.activity',
|
||||
]
|
||||
seqs = []
|
||||
return self._remove_app_data(to_removes, seqs)
|
||||
|
||||
def remove_workflow(self):
|
||||
to_removes = [
|
||||
# 清除工作流
|
||||
# 'wkf.workitem',
|
||||
# 'wkf.instance',
|
||||
]
|
||||
seqs = []
|
||||
return self._remove_app_data(to_removes, seqs)
|
||||
|
||||
def remove_all_biz(self):
|
||||
self.remove_account()
|
||||
self.remove_quality()
|
||||
self.remove_inventory()
|
||||
self.remove_purchase()
|
||||
self.remove_mrp()
|
||||
self.remove_sales()
|
||||
self.remove_project()
|
||||
self.remove_pos()
|
||||
self.remove_expense()
|
||||
self.remove_message()
|
||||
return True
|
||||
|
||||
def reset_cat_loc_name(self):
|
||||
ids = self.env['product.category'].search([
|
||||
('parent_id', '!=', False)
|
||||
], order='complete_name')
|
||||
for rec in ids:
|
||||
try:
|
||||
rec._compute_complete_name()
|
||||
except:
|
||||
pass
|
||||
ids = self.env['stock.location'].search([
|
||||
('location_id', '!=', False),
|
||||
('usage', '!=', 'views'),
|
||||
], order='complete_name')
|
||||
for rec in ids:
|
||||
try:
|
||||
rec._compute_complete_name()
|
||||
except:
|
||||
pass
|
||||
return True
|
||||
|
||||
def action_set_app_doc_root_to_my(self):
|
||||
base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url')
|
||||
self.app_doc_root_url = base_url
|
||||
|
||||
# def action_set_all_to_app_doc_root_url(self):
|
||||
# if self.app_doc_root_url:
|
||||
36
app_odoo_customize/models/web_environment_ribbon_backend.py
Normal file
36
app_odoo_customize/models/web_environment_ribbon_backend.py
Normal file
@@ -0,0 +1,36 @@
|
||||
# Copyright 2017 ACSONE SA/NV
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import api, models
|
||||
|
||||
|
||||
class WebEnvironmentRibbonBackend(models.AbstractModel):
|
||||
|
||||
_name = "web.environment.ribbon.backend"
|
||||
_description = "Web Environment Ribbon Backend"
|
||||
|
||||
@api.model
|
||||
def _prepare_ribbon_format_vals(self):
|
||||
return {"db_name": self.env.cr.dbname}
|
||||
|
||||
@api.model
|
||||
def _prepare_ribbon_name(self):
|
||||
name_tmpl = self.env["ir.config_parameter"].sudo().get_param("app_ribbon_name") or False
|
||||
vals = self._prepare_ribbon_format_vals()
|
||||
return name_tmpl and name_tmpl.format(**vals) or name_tmpl
|
||||
|
||||
@api.model
|
||||
def get_environment_ribbon(self):
|
||||
"""
|
||||
This method returns the ribbon data from ir config parameters
|
||||
:return: dictionary
|
||||
"""
|
||||
ir_config_model = self.env["ir.config_parameter"]
|
||||
name = self._prepare_ribbon_name()
|
||||
return {
|
||||
"name": name,
|
||||
"color": ir_config_model.sudo().get_param("app_ribbon_color"),
|
||||
"background_color": ir_config_model.sudo().get_param(
|
||||
"app_ribbon_background_color"
|
||||
),
|
||||
}
|
||||
Reference in New Issue
Block a user