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:
@@ -23,7 +23,7 @@
|
||||
|
||||
{
|
||||
'name': 'Odoo 15,14,13 Customize OEM(Boost, Data reset)',
|
||||
'version': '14.21.03.31',
|
||||
'version': '14.21.11.09',
|
||||
'author': 'Sunpop.cn',
|
||||
'category': 'Productivity',
|
||||
'website': 'https://www.sunpop.cn',
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
import logging
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.exceptions import UserError, ValidationError
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -118,7 +117,11 @@ class ResConfigSettings(models.TransientModel):
|
||||
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)
|
||||
@@ -130,16 +133,11 @@ class ResConfigSettings(models.TransientModel):
|
||||
|
||||
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):
|
||||
@@ -291,6 +289,7 @@ class ResConfigSettings(models.TransientModel):
|
||||
'stock.',
|
||||
'picking.',
|
||||
'procurement.group',
|
||||
'product.tracking.default',
|
||||
'WH/',
|
||||
]
|
||||
return self.remove_app_data(to_removes, seqs)
|
||||
@@ -338,7 +337,6 @@ class ResConfigSettings(models.TransientModel):
|
||||
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 = [
|
||||
@@ -372,59 +370,60 @@ class ResConfigSettings(models.TransientModel):
|
||||
_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):
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
|
||||
{
|
||||
'name': '2021最新中国企业会计表.Latest Chinese Accounting.',
|
||||
'version': '14.21.11.07',
|
||||
'version': '14.21.11.09',
|
||||
'author': 'Sunpop.cn',
|
||||
'category': 'Localization',
|
||||
'category': 'Accounting/Localizations/Account Charts',
|
||||
'website': 'https://www.sunpop.cn',
|
||||
'license': 'LGPL-3',
|
||||
'sequence': 12,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"id","code_prefix","name"
|
||||
"account_group_1","1","资产类"
|
||||
"account_group_2","2","负债类"
|
||||
"account_group_3","3","共同类"
|
||||
"account_group_4","4","所有者权益类"
|
||||
"account_group_5","5","成本类"
|
||||
"account_group_6","6","损益类"
|
||||
"id","code_prefix_start","code_prefix_end","name"
|
||||
"account_group_1","1","1","资产类"
|
||||
"account_group_2","2","2","负债类"
|
||||
"account_group_3","3","3","共同类"
|
||||
"account_group_4","4","4","所有者权益类"
|
||||
"account_group_5","5","5","成本类"
|
||||
"account_group_6","6","6","损益类"
|
||||
|
@@ -12,7 +12,7 @@
|
||||
</record>
|
||||
|
||||
<function model="account.chart.template" name="try_loading">
|
||||
<value eval="[ref('l10n_chart_china_standard_business_latest')]"/>
|
||||
<value eval="[ref('l10n_cn_standard_latest.l10n_chart_china_standard_business_latest')]"/>
|
||||
</function>
|
||||
</data>
|
||||
</odoo>
|
||||
|
||||
Reference in New Issue
Block a user