mirror of
https://github.com/guohuadeng/app-odoo.git
synced 2025-02-23 04:11:36 +02:00
add super m2o, o2m
This commit is contained in:
@@ -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',
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -23,3 +23,5 @@
|
||||
# description:
|
||||
|
||||
from . import base
|
||||
from . import fields
|
||||
|
||||
|
||||
48
app_common/models/fields.py
Normal file
48
app_common/models/fields.py
Normal 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
|
||||
@@ -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"/>
|
||||
|
||||
Reference in New Issue
Block a user