mirror of
https://github.com/guohuadeng/app-odoo.git
synced 2025-02-23 04:11:36 +02:00
fix Clean up accounting errors清理会计科目报错(App Customize Odoo 14) #48
This commit is contained in:
@@ -3,14 +3,13 @@
|
||||
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")
|
||||
app_show_lang = fields.Boolean('Show Quick Language Switcher',
|
||||
help="When enable,User can quick switch language in user menu")
|
||||
@@ -26,7 +25,7 @@ class ResConfigSettings(models.TransientModel):
|
||||
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')
|
||||
app_documentation_dev_url = fields.Char('Developer Documentation Url')
|
||||
app_support_url = fields.Char('Support Url')
|
||||
@@ -34,13 +33,13 @@ class ResConfigSettings(models.TransientModel):
|
||||
app_account_url = fields.Char('My Odoo.com Account Url')
|
||||
app_enterprise_url = fields.Char('Customize Module Url(eg. Enterprise)')
|
||||
app_ribbon_name = fields.Char('Show Demo Ribbon')
|
||||
|
||||
|
||||
@api.model
|
||||
def get_values(self):
|
||||
res = super(ResConfigSettings, self).get_values()
|
||||
ir_config = self.env['ir.config_parameter'].sudo()
|
||||
app_system_name = ir_config.get_param('app_system_name', default='odooApp')
|
||||
|
||||
|
||||
app_show_lang = True if ir_config.get_param('app_show_lang') == "True" else False
|
||||
app_show_debug = True if ir_config.get_param('app_show_debug') == "True" else False
|
||||
app_show_documentation = True if ir_config.get_param('app_show_documentation') == "True" else False
|
||||
@@ -50,7 +49,7 @@ class ResConfigSettings(models.TransientModel):
|
||||
app_show_enterprise = True if ir_config.get_param('app_show_enterprise') == "True" else False
|
||||
app_show_share = True if ir_config.get_param('app_show_share') == "True" else False
|
||||
app_show_poweredby = True if ir_config.get_param('app_show_poweredby') == "True" else False
|
||||
|
||||
|
||||
app_documentation_url = ir_config.get_param('app_documentation_url',
|
||||
default='https://www.sunpop.cn/documentation/user/12.0/en/index.html')
|
||||
app_documentation_dev_url = ir_config.get_param('app_documentation_dev_url',
|
||||
@@ -71,7 +70,7 @@ class ResConfigSettings(models.TransientModel):
|
||||
app_show_enterprise=app_show_enterprise,
|
||||
app_show_share=app_show_share,
|
||||
app_show_poweredby=app_show_poweredby,
|
||||
|
||||
|
||||
app_documentation_url=app_documentation_url,
|
||||
app_documentation_dev_url=app_documentation_dev_url,
|
||||
app_support_url=app_support_url,
|
||||
@@ -81,7 +80,7 @@ class ResConfigSettings(models.TransientModel):
|
||||
app_ribbon_name=app_ribbon_name
|
||||
)
|
||||
return res
|
||||
|
||||
|
||||
def set_values(self):
|
||||
super(ResConfigSettings, self).set_values()
|
||||
ir_config = self.env['ir.config_parameter'].sudo()
|
||||
@@ -95,7 +94,7 @@ class ResConfigSettings(models.TransientModel):
|
||||
ir_config.set_param("app_show_enterprise", self.app_show_enterprise or "False")
|
||||
ir_config.set_param("app_show_share", self.app_show_share or "False")
|
||||
ir_config.set_param("app_show_poweredby", self.app_show_poweredby or "False")
|
||||
|
||||
|
||||
ir_config.set_param("app_documentation_url",
|
||||
self.app_documentation_url or "https://www.sunpop.cn/documentation/user/12.0/en/index.html")
|
||||
ir_config.set_param("app_documentation_dev_url",
|
||||
@@ -105,7 +104,7 @@ class ResConfigSettings(models.TransientModel):
|
||||
ir_config.set_param("app_account_url", self.app_account_url or "https://www.sunpop.cn/my-account/")
|
||||
ir_config.set_param("app_enterprise_url", self.app_enterprise_url or "https://www.sunpop.cn")
|
||||
ir_config.set_param("app_ribbon_name", self.app_ribbon_name or "*Sunpop.cn")
|
||||
|
||||
|
||||
def set_module_url(self):
|
||||
sql = "UPDATE ir_module_module SET website = '%s' WHERE license like '%s' and website <> ''" % (self.app_enterprise_url, 'OEEL%')
|
||||
try:
|
||||
@@ -113,12 +112,16 @@ class ResConfigSettings(models.TransientModel):
|
||||
self._cr.commit()
|
||||
except Exception as e:
|
||||
pass
|
||||
|
||||
# 清数据,o=对象, s=序列
|
||||
|
||||
# 清数据,o=对象, s=序列
|
||||
def remove_app_data(self, o, s=[]):
|
||||
for line in o:
|
||||
# 检查是否存在
|
||||
if not self.env['ir.model']._get(line):
|
||||
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)
|
||||
@@ -127,19 +130,14 @@ class ResConfigSettings(models.TransientModel):
|
||||
t_name = obj_name.replace('.', '_')
|
||||
else:
|
||||
t_name = obj._table
|
||||
|
||||
|
||||
sql = "delete from %s" % t_name
|
||||
# 增加多公司处理
|
||||
if hasattr(self.env[obj_name], 'company_id'):
|
||||
field = self.env[obj_name]._fields['company_id']
|
||||
if not field.related or field.store:
|
||||
sql = "%s where company_id=%d" % (sql, self.env.company.id)
|
||||
_logger.warning('remove_app_data where add company_id: %s' % obj_name)
|
||||
try:
|
||||
self._cr.execute(sql)
|
||||
# self._cr.commit()
|
||||
self._cr.commit()
|
||||
except Exception as e:
|
||||
_logger.error('remove data error: %s,%s', line, e)
|
||||
_logger.warning('remove data error: %s,%s', line, e)
|
||||
# 更新序号
|
||||
for line in s:
|
||||
domain = ['|', ('code', '=ilike', line + '%'), ('prefix', '=ilike', line + '%')]
|
||||
@@ -150,7 +148,7 @@ class ResConfigSettings(models.TransientModel):
|
||||
'number_next': 1,
|
||||
})
|
||||
except Exception as e:
|
||||
_logger.error('reset sequence data error: %s,%s', line, e)
|
||||
_logger.warning('reset sequence data error: %s,%s', line, e)
|
||||
return True
|
||||
|
||||
def remove_sales(self):
|
||||
@@ -169,7 +167,7 @@ class ResConfigSettings(models.TransientModel):
|
||||
'sale',
|
||||
]
|
||||
return self.remove_app_data(to_removes, seqs)
|
||||
|
||||
|
||||
def remove_product(self):
|
||||
to_removes = [
|
||||
# 清除产品数据
|
||||
@@ -180,7 +178,7 @@ class ResConfigSettings(models.TransientModel):
|
||||
'product.product',
|
||||
]
|
||||
return self.remove_app_data(to_removes, seqs)
|
||||
|
||||
|
||||
def remove_product_attribute(self):
|
||||
to_removes = [
|
||||
# 清除产品属性
|
||||
@@ -189,7 +187,7 @@ class ResConfigSettings(models.TransientModel):
|
||||
]
|
||||
seqs = []
|
||||
return self.remove_app_data(to_removes, seqs)
|
||||
|
||||
|
||||
def remove_pos(self):
|
||||
to_removes = [
|
||||
# 清除POS单据
|
||||
@@ -202,9 +200,9 @@ class ResConfigSettings(models.TransientModel):
|
||||
'pos.',
|
||||
]
|
||||
res = self.remove_app_data(to_removes, seqs)
|
||||
|
||||
|
||||
# 更新要关帐的值,因为 store=true 的计算字段要重置
|
||||
|
||||
|
||||
try:
|
||||
statement = self.env['account.bank.statement'].sudo().search([])
|
||||
for s in statement:
|
||||
@@ -212,7 +210,7 @@ class ResConfigSettings(models.TransientModel):
|
||||
except Exception as e:
|
||||
_logger.error('reset sequence data error: %s', e)
|
||||
return res
|
||||
|
||||
|
||||
def remove_purchase(self):
|
||||
to_removes = [
|
||||
# 清除采购单据
|
||||
@@ -225,7 +223,7 @@ class ResConfigSettings(models.TransientModel):
|
||||
'purchase.',
|
||||
]
|
||||
return self.remove_app_data(to_removes, seqs)
|
||||
|
||||
|
||||
def remove_expense(self):
|
||||
to_removes = [
|
||||
# 清除
|
||||
@@ -238,7 +236,7 @@ class ResConfigSettings(models.TransientModel):
|
||||
'hr.expense.',
|
||||
]
|
||||
return self.remove_app_data(to_removes, seqs)
|
||||
|
||||
|
||||
def remove_mrp(self):
|
||||
to_removes = [
|
||||
# 清除生产单据
|
||||
@@ -257,7 +255,7 @@ class ResConfigSettings(models.TransientModel):
|
||||
'mrp.',
|
||||
]
|
||||
return self.remove_app_data(to_removes, seqs)
|
||||
|
||||
|
||||
def remove_mrp_bom(self):
|
||||
to_removes = [
|
||||
# 清除生产BOM
|
||||
@@ -266,7 +264,7 @@ class ResConfigSettings(models.TransientModel):
|
||||
]
|
||||
seqs = []
|
||||
return self.remove_app_data(to_removes, seqs)
|
||||
|
||||
|
||||
def remove_inventory(self):
|
||||
to_removes = [
|
||||
# 清除库存单据
|
||||
@@ -291,10 +289,11 @@ class ResConfigSettings(models.TransientModel):
|
||||
'stock.',
|
||||
'picking.',
|
||||
'procurement.group',
|
||||
'product.tracking.default',
|
||||
'WH/',
|
||||
]
|
||||
return self.remove_app_data(to_removes, seqs)
|
||||
|
||||
|
||||
def remove_account(self):
|
||||
to_removes = [
|
||||
# 清除财务会计单据
|
||||
@@ -314,7 +313,7 @@ class ResConfigSettings(models.TransientModel):
|
||||
'account.move',
|
||||
]
|
||||
res = self.remove_app_data(to_removes, [])
|
||||
|
||||
|
||||
# extra 更新序号
|
||||
domain = [
|
||||
('company_id', '=', self.env.company.id),
|
||||
@@ -336,9 +335,8 @@ class ResConfigSettings(models.TransientModel):
|
||||
except Exception as e:
|
||||
_logger.error('reset sequence data error: %s,%s', domain, e)
|
||||
return res
|
||||
|
||||
|
||||
def remove_account_chart(self):
|
||||
# todo: 安装会计模块后,会有问题,后续处理
|
||||
company_id = self.env.company.id
|
||||
self = self.with_context(force_company=company_id, company_id=company_id)
|
||||
to_removes = [
|
||||
@@ -360,73 +358,74 @@ class ResConfigSettings(models.TransientModel):
|
||||
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,
|
||||
try:
|
||||
rec = self.env['pos.config'].search([])
|
||||
rec.write({
|
||||
'journal_id': None,
|
||||
'invoice_journal_id': None,
|
||||
})
|
||||
except Exception as e:
|
||||
_logger.error('remove data error: %s,%s', 'account_chart', e)
|
||||
# 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,
|
||||
})
|
||||
rec.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,
|
||||
})
|
||||
rec.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,
|
||||
})
|
||||
rec.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,
|
||||
})
|
||||
rec.write({
|
||||
'valuation_in_account_id': None,
|
||||
'valuation_out_account_id': None,
|
||||
})
|
||||
except Exception as e:
|
||||
pass # raise Warning(e)
|
||||
|
||||
|
||||
seqs = []
|
||||
res = self.remove_app_data(to_removes, seqs)
|
||||
self.env.company.write({'chart_template_id': False})
|
||||
self._cr.commit()
|
||||
self.env.company.sudo().write({'chart_template_id': False})
|
||||
return res
|
||||
|
||||
|
||||
def remove_project(self):
|
||||
to_removes = [
|
||||
# 清除项目
|
||||
@@ -437,7 +436,7 @@ class ResConfigSettings(models.TransientModel):
|
||||
]
|
||||
seqs = []
|
||||
return self.remove_app_data(to_removes, seqs)
|
||||
|
||||
|
||||
def remove_quality(self):
|
||||
to_removes = [
|
||||
# 清除质检数据
|
||||
@@ -456,7 +455,7 @@ class ResConfigSettings(models.TransientModel):
|
||||
# 'quality.point',
|
||||
]
|
||||
return self.remove_app_data(to_removes, seqs)
|
||||
|
||||
|
||||
def remove_quality_setting(self):
|
||||
to_removes = [
|
||||
# 清除质检设置
|
||||
@@ -468,7 +467,7 @@ class ResConfigSettings(models.TransientModel):
|
||||
'quality.tag',
|
||||
]
|
||||
return self.remove_app_data(to_removes)
|
||||
|
||||
|
||||
def remove_website(self):
|
||||
to_removes = [
|
||||
# 清除网站数据,w, w_blog
|
||||
@@ -489,7 +488,7 @@ class ResConfigSettings(models.TransientModel):
|
||||
]
|
||||
seqs = []
|
||||
return self.remove_app_data(to_removes, seqs)
|
||||
|
||||
|
||||
def remove_message(self):
|
||||
to_removes = [
|
||||
# 清除消息数据
|
||||
@@ -499,7 +498,7 @@ class ResConfigSettings(models.TransientModel):
|
||||
]
|
||||
seqs = []
|
||||
return self.remove_app_data(to_removes, seqs)
|
||||
|
||||
|
||||
def remove_workflow(self):
|
||||
to_removes = [
|
||||
# 清除工作流
|
||||
@@ -508,7 +507,7 @@ class ResConfigSettings(models.TransientModel):
|
||||
]
|
||||
seqs = []
|
||||
return self.remove_app_data(to_removes, seqs)
|
||||
|
||||
|
||||
def remove_all_biz(self):
|
||||
self.remove_account()
|
||||
self.remove_quality()
|
||||
@@ -521,7 +520,7 @@ class ResConfigSettings(models.TransientModel):
|
||||
self.remove_expense()
|
||||
self.remove_message()
|
||||
return True
|
||||
|
||||
|
||||
def reset_cat_loc_name(self):
|
||||
ids = self.env['product.category'].search([
|
||||
('parent_id', '!=', False)
|
||||
|
||||
Reference in New Issue
Block a user