add super m2o, o2m

This commit is contained in:
ivan deng
2020-10-24 22:55:27 +08:00
parent 2e70ec1571
commit 3d2c6a138d
5 changed files with 55 additions and 5 deletions

View File

@@ -18,7 +18,7 @@
{
'name': "App base chinese中国化基本模块增强",
'version': '13.20.09.19',
'version': '13.20.10.19',
'author': 'Sunpop.cn',
'category': 'Base',
'website': 'https://www.sunpop.cn',

View File

@@ -33,13 +33,13 @@ def post_init_hook(cr, registry):
env = api.Environment(cr, SUPERUSER_ID, {})
ids = env['product.category'].sudo().with_context(lang='zh_CN').search([
('parent_id', '!=', False)
], order='complete_name')
], order='parent_path')
for rec in ids:
rec._compute_complete_name()
ids = env['stock.location'].sudo().with_context(lang='zh_CN').search([
('location_id', '!=', False),
('usage', '!=', 'views'),
], order='complete_name')
], order='parent_path')
for rec in ids:
rec._compute_complete_name()
# 超级用户改时区为中国
@@ -52,4 +52,4 @@ def uninstall_hook(cr, registry):
"""
数据初始化,卸载时执行
"""
pass
pass

View File

@@ -23,3 +23,5 @@
# description:
from . import base
from . import fields

View File

@@ -0,0 +1,48 @@
# -*- coding: utf-8 -*-
from odoo.fields import Field, resolve_mro
from odoo.fields import Selection as oldSelection
from odoo.tools import merge_sequences
import logging
_logger = logging.getLogger(__name__)
class Selection(Field):
def _setup_attrs_app(self, model, name):
Field._setup_attrs(self, model, name)
# determine selection (applying 'selection_add' extensions)
values = None
labels = {}
for field in reversed(resolve_mro(model, name, self._can_setup_from)):
# We cannot use field.selection or field.selection_add here
# because those attributes are overridden by ``_setup_attrs``.
if 'selection' in field.args:
selection = field.args['selection']
if isinstance(selection, list):
if (
values is not None
and values != [kv[0] for kv in selection]
):
_logger.debug("%s: selection=%r overrides existing selection; use selection_add instead", self, selection)
values = [kv[0] for kv in selection]
labels = dict(selection)
else:
self.selection = selection
values = None
labels = {}
if 'selection_add' in field.args:
selection_add = field.args['selection_add']
assert isinstance(selection_add, list), \
"%s: selection_add=%r must be a list" % (self, selection_add)
assert values is not None, \
"%s: selection_add=%r on non-list selection %r" % (self, selection_add, self.selection)
values = merge_sequences(values, [kv[0] for kv in selection_add])
labels.update(kv for kv in selection_add if len(kv) == 2)
if values is not None:
self.selection = [(value, labels[value]) for value in values]
oldSelection._setup_attrs = Selection._setup_attrs_app

View File

@@ -5,7 +5,7 @@
<field name="model">product.category</field>
<field name="inherit_id" ref="product.product_category_form_view"/>
<field name="arch" type="xml">
<xpath expr="//div[@class='oe_button_box']" position="after">
<xpath expr="//div[hasclass('oe_button_box')]" position="after">
<div id="o_node_container">
<div id="o_node_main">
<span id="add_title"/>