@ -0,0 +1,59 @@ |
|||
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.svg |
|||
:target: https://www.gnu.org/licenses/agpl-3.0-standalone.html |
|||
:alt: License: AGPL-3 |
|||
|
|||
Sale Order Custom Fields |
|||
======================== |
|||
This module enables to generate custom fields in Sale Order. |
|||
|
|||
Features |
|||
======== |
|||
* Custom fields in Sale Order. |
|||
* Filter for dynamically generated fields in settings. |
|||
|
|||
Configuration |
|||
============= |
|||
- After installation, go to Settings - Users & Companies. |
|||
- Select any user and enable the checkbox Create Custom Fields in Sale. |
|||
|
|||
License |
|||
------- |
|||
Affero General Public License, v3.0 (AGPL v3). |
|||
(https://www.gnu.org/licenses/agpl-3.0-standalone.html) |
|||
|
|||
Company |
|||
------- |
|||
* `Cybrosys Techno Solutions <https://cybrosys.com/>`__ |
|||
|
|||
Credits |
|||
------- |
|||
* Developers: |
|||
Ajmal J K, |
|||
(V14) Minhaj T, |
|||
(V15) Midilaj V K, |
|||
(V16) Sreelakshmi P M, |
|||
(V17) Aysha Shalin, |
|||
(V18) Safa KB |
|||
Contact: odoo@cybrosys.com |
|||
|
|||
Contacts |
|||
-------- |
|||
* Mail Contact : odoo@cybrosys.com |
|||
* Website : https://cybrosys.com |
|||
|
|||
Bug Tracker |
|||
----------- |
|||
Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. |
|||
|
|||
Maintainer |
|||
========== |
|||
.. image:: https://cybrosys.com/images/logo.png |
|||
:target: https://cybrosys.com |
|||
|
|||
This module is maintained by Cybrosys Technologies. |
|||
|
|||
For support and more information, please visit `Our Website <https://cybrosys.com/>`__ |
|||
|
|||
Further information |
|||
=================== |
|||
HTML Description: `<static/description/index.html>`__ |
@ -0,0 +1,23 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################### |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
|||
# Author: Safa KB (odoo@cybrosys.com) |
|||
# |
|||
# You can modify it under the terms of the GNU AFFERO |
|||
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. |
|||
# |
|||
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
|||
# (AGPL v3) along with this program. |
|||
# If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################### |
|||
from . import models |
|||
from . import wizard |
@ -0,0 +1,47 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################### |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
|||
# Author: Safa KB (odoo@cybrosys.com) |
|||
# |
|||
# You can modify it under the terms of the GNU AFFERO |
|||
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. |
|||
# |
|||
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
|||
# (AGPL v3) along with this program. |
|||
# If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################### |
|||
{ |
|||
'name': 'Sale Order Custom Fields', |
|||
'version': '18.0.1.0.0', |
|||
'category': 'Sales', |
|||
'summary': """Custom fields in Sale Order from user level""", |
|||
'description': """This module enables to generate custom fields in Sale Order |
|||
from user level without the need of coding.""", |
|||
'author': 'Cybrosys Techno Solutions', |
|||
'company': 'Cybrosys Techno Solutions', |
|||
'maintainer': 'Cybrosys Techno Solutions', |
|||
'website': "https://www.cybrosys.com", |
|||
'depends': ['sale_management'], |
|||
'data': [ |
|||
'security/dynamic_sale_order_fields_groups.xml', |
|||
'security/ir.model.access.csv', |
|||
'data/field_widget_data.xml', |
|||
'wizard/sale_order_dynamic_field_views.xml', |
|||
'views/dynamic_sale_order_fields_menu.xml', |
|||
'views/ir_model_fields_views.xml', |
|||
], |
|||
'images': ['static/description/banner.jpg'], |
|||
'license': 'AGPL-3', |
|||
'installable': True, |
|||
'auto_install': False, |
|||
'application': False, |
|||
} |
@ -0,0 +1,47 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<odoo> |
|||
<data noupdate="1"> |
|||
<!-- Widget 'image' for 'binary' field --> |
|||
<record id="field_widgets_image_widget" model="field.widget"> |
|||
<field name="name">image</field> |
|||
<field name="data_type">binary</field> |
|||
<field name="description">Image</field> |
|||
</record> |
|||
<!-- Widget 'many2many_tags' for 'many2many' field --> |
|||
<record id="field_widgets_many2many_tag_widget" model="field.widget"> |
|||
<field name="name">many2many_tags</field> |
|||
<field name="data_type">many2many</field> |
|||
<field name="description">Many2many Tags</field> |
|||
</record> |
|||
<!-- Widget 'many2many_binary' for 'many2many' field --> |
|||
<record id="field_widgets_many2many_binary_widget" model="field.widget"> |
|||
<field name="name">many2many_binary</field> |
|||
<field name="data_type">many2many</field> |
|||
<field name="description">Binary</field> |
|||
</record> |
|||
<!-- Widget 'radio' for 'selection' field --> |
|||
<record id="field_widgets_radio_widget" model="field.widget"> |
|||
<field name="name">radio</field> |
|||
<field name="data_type">selection</field> |
|||
<field name="description">Radio</field> |
|||
</record> |
|||
<!-- Widget 'priority' for 'selection' field --> |
|||
<record id="field_widgets_priority_widget" model="field.widget"> |
|||
<field name="name">priority</field> |
|||
<field name="data_type">selection</field> |
|||
<field name="description">Priority</field> |
|||
</record> |
|||
<!-- Widget 'monetory' for 'float' field --> |
|||
<record id="field_widgets_monetory_widget" model="field.widget"> |
|||
<field name="name">monetary</field> |
|||
<field name="data_type">float</field> |
|||
<field name="description">Monetary</field> |
|||
</record> |
|||
<!-- Widget 'selection' for 'Many2one' field --> |
|||
<record id="field_widgets_selection_widget" model="field.widget"> |
|||
<field name="name">selection</field> |
|||
<field name="data_type">many2one</field> |
|||
<field name="description">Selection</field> |
|||
</record> |
|||
</data> |
|||
</odoo> |
@ -0,0 +1,6 @@ |
|||
## Module <dynamic_sale_order_fields> |
|||
|
|||
#### 14.02.2024 |
|||
#### Version 18.0.1.0.0 |
|||
##### ADD |
|||
- Initial Commit for Sale Order Custom Fields |
@ -0,0 +1,23 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################### |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
|||
# Author: Safa KB (odoo@cybrosys.com) |
|||
# |
|||
# You can modify it under the terms of the GNU AFFERO |
|||
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. |
|||
# |
|||
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
|||
# (AGPL v3) along with this program. |
|||
# If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################### |
|||
from . import ir_model_fields |
|||
from . import field_widget |
@ -0,0 +1,41 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################### |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
|||
# Author: Safa KB (odoo@cybrosys.com) |
|||
# |
|||
# You can modify it under the terms of the GNU AFFERO |
|||
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. |
|||
# |
|||
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
|||
# along with this program. |
|||
# If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################### |
|||
from odoo import fields, models |
|||
|
|||
|
|||
class FieldWidget(models.Model): |
|||
""" |
|||
Need of this model is because we can't filter a selection field dynamically |
|||
so when we select a field its widgets also need to change according to field |
|||
type, this cannot be achieved using a 'selection' field; we require a |
|||
'Many2one' field. |
|||
""" |
|||
_name = 'field.widget' |
|||
_description = 'Field Widget' |
|||
_rec_name = 'description' |
|||
|
|||
name = fields.Char(string="Name", help="Name of widget") |
|||
description = fields.Char(string="Description", |
|||
help="Description of widget") |
|||
data_type = fields.Char(string="Data type", |
|||
widget="Field type of widget", |
|||
help="Type of field") |
@ -0,0 +1,34 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################### |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
|||
# Author: Safa KB (odoo@cybrosys.com) |
|||
# |
|||
# You can modify it under the terms of the GNU AFFERO |
|||
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. |
|||
# |
|||
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
|||
# (AGPL v3) along with this program. |
|||
# If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################### |
|||
from odoo import fields, models |
|||
|
|||
|
|||
class IrModelFields(models.Model): |
|||
""" |
|||
Adding a new field to indicate whether a field in a model is dynamically |
|||
created. |
|||
""" |
|||
_inherit = 'ir.model.fields' |
|||
|
|||
is_dynamic = fields.Boolean( |
|||
string="Dynamic Field", |
|||
help="Whether this field is dynamically created or not") |
@ -0,0 +1,7 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<odoo> |
|||
<!-- Defines a new user group for creating custom fields in sale order. --> |
|||
<record id="group_add_sale_custom_fields" model="res.groups"> |
|||
<field name="name">Create Custom Fields in Sale</field> |
|||
</record> |
|||
</odoo> |
|
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 28 KiB |
After Width: | Height: | Size: 628 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 210 KiB |
After Width: | Height: | Size: 209 KiB |
After Width: | Height: | Size: 109 KiB |
After Width: | Height: | Size: 495 B |
After Width: | Height: | Size: 1.0 KiB |
After Width: | Height: | Size: 624 B |
After Width: | Height: | Size: 136 KiB |
After Width: | Height: | Size: 214 KiB |
After Width: | Height: | Size: 36 KiB |
After Width: | Height: | Size: 3.6 KiB |
After Width: | Height: | Size: 310 B |
After Width: | Height: | Size: 929 B |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 3.3 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 17 KiB |
After Width: | Height: | Size: 542 B |
After Width: | Height: | Size: 576 B |
After Width: | Height: | Size: 733 B |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 4.0 KiB |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 738 KiB |
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 911 B |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 600 B |
After Width: | Height: | Size: 673 B |
After Width: | Height: | Size: 2.0 KiB |
After Width: | Height: | Size: 462 B |
After Width: | Height: | Size: 2.1 KiB |
After Width: | Height: | Size: 926 B |
After Width: | Height: | Size: 9.0 KiB |
After Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 7.0 KiB |
After Width: | Height: | Size: 878 B |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 653 B |
After Width: | Height: | Size: 800 B |
After Width: | Height: | Size: 905 B |
After Width: | Height: | Size: 189 KiB |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 839 B |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 5.9 KiB |
After Width: | Height: | Size: 1.6 KiB |
After Width: | Height: | Size: 34 KiB |
After Width: | Height: | Size: 26 KiB |
After Width: | Height: | Size: 3.8 KiB |
After Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 427 B |
After Width: | Height: | Size: 627 B |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 988 B |
After Width: | Height: | Size: 3.7 KiB |
After Width: | Height: | Size: 5.0 KiB |
After Width: | Height: | Size: 875 B |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 87 KiB |
After Width: | Height: | Size: 131 KiB |
After Width: | Height: | Size: 92 KiB |
After Width: | Height: | Size: 87 KiB |
After Width: | Height: | Size: 92 KiB |
After Width: | Height: | Size: 86 KiB |
After Width: | Height: | Size: 277 KiB |
After Width: | Height: | Size: 150 KiB |
After Width: | Height: | Size: 179 KiB |
After Width: | Height: | Size: 120 KiB |
After Width: | Height: | Size: 124 KiB |
After Width: | Height: | Size: 129 KiB |
After Width: | Height: | Size: 166 KiB |
After Width: | Height: | Size: 68 KiB |
After Width: | Height: | Size: 880 KiB |
After Width: | Height: | Size: 90 KiB |
After Width: | Height: | Size: 40 KiB |
@ -0,0 +1,10 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<odoo> |
|||
<!-- Menu item for creating dynamic fields in sale order. --> |
|||
<menuitem id="sale_order_dynamic_field_menu" |
|||
action="dynamic_sale_order_fields.sale_order_dynamic_field_action" |
|||
parent="sale.menu_sale_config" |
|||
groups="dynamic_sale_order_fields.group_add_sale_custom_fields" |
|||
name="Create Fields" |
|||
sequence="100"/> |
|||
</odoo> |
@ -0,0 +1,15 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<odoo> |
|||
<!-- Adding custom filter for dynamic fields in search view of fields. --> |
|||
<record id="view_model_fields_search" model="ir.ui.view"> |
|||
<field name="name">ir.model.fields.view.search.inherit.dynamic.sale.order.fields</field> |
|||
<field name="model">ir.model.fields</field> |
|||
<field name="inherit_id" ref="base.view_model_fields_search"/> |
|||
<field name="arch" type="xml"> |
|||
<xpath expr="//search/filter[@name='translate']" position="after"> |
|||
<separator/> |
|||
<filter string="Dynamic Fields" name="dynamic_field" domain="[('is_dynamic', '=', True)]"/> |
|||
</xpath> |
|||
</field> |
|||
</record> |
|||
</odoo> |
@ -0,0 +1,22 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################### |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
|||
# Author: Safa KB (odoo@cybrosys.com) |
|||
# |
|||
# You can modify it under the terms of the GNU AFFERO |
|||
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. |
|||
# |
|||
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
|||
# (AGPL v3) along with this program. |
|||
# If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################### |
|||
from . import sale_order_dynamic_field |
@ -0,0 +1,164 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################### |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
|||
# Author: Safa KB (odoo@cybrosys.com) |
|||
# |
|||
# You can modify it under the terms of the GNU AFFERO |
|||
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. |
|||
# |
|||
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
|||
# (AGPL v3) along with this program. |
|||
# If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################### |
|||
import xml.etree.ElementTree as xee |
|||
from odoo import api, models, fields, _ |
|||
from odoo.exceptions import UserError |
|||
|
|||
|
|||
class SaleOrderDynamicFields(models.TransientModel): |
|||
""" For adding custom fields in 'sale.order'.""" |
|||
_name = 'sale.order.dynamic.field' |
|||
_description = 'Sale Order Dynamic Fields' |
|||
_inherit = 'ir.model.fields' |
|||
|
|||
@api.model |
|||
def get_possible_field_types(self): |
|||
""" |
|||
Return all available field types other than 'one2many' and 'reference' |
|||
fields. |
|||
""" |
|||
field_list = sorted((key, key) for key in fields.MetaField.by_type) |
|||
field_list.remove(('one2many', 'one2many')) |
|||
field_list.remove(('reference', 'reference')) |
|||
return field_list |
|||
|
|||
def set_domain(self): |
|||
""" Return the fields that currently present in the form.""" |
|||
view_id = self.env.ref('sale.view_order_form') |
|||
view_arch = str(view_id.arch_base) |
|||
doc = xee.fromstring(view_arch) |
|||
field_list = [] |
|||
for tag in doc.findall('.//field'): |
|||
field_list.append(tag.attrib['name']) |
|||
model_id = self.env['ir.model'].sudo().search([ |
|||
('model', '=', 'sale.order')]) |
|||
return [('model_id', '=', model_id.id), ('state', '=', 'base'), |
|||
('name', 'in', field_list)] |
|||
|
|||
def _set_default(self): |
|||
""" Set default model for dynamically created fields.""" |
|||
model_id = self.env['ir.model'].sudo().search([ |
|||
('model', '=', 'sale.order')]) |
|||
return [('id', '=', model_id.id)] |
|||
|
|||
def create_fields(self): |
|||
""" Create custom fields """ |
|||
self.env['ir.model.fields'].sudo().create({ |
|||
'name': self.name, |
|||
'field_description': self.field_description, |
|||
'model_id': self.model_id.id, |
|||
'ttype': self.field_type, |
|||
'relation': self.ref_model_id.model, |
|||
'required': self.required, |
|||
'index': self.index, |
|||
'store': self.store, |
|||
'help': self.help, |
|||
'readonly': self.readonly, |
|||
'selection': self.selection_field, |
|||
'copied': self.copied, |
|||
'is_dynamic': True |
|||
}) |
|||
inherit_id = self.env.ref('sale.view_order_form') |
|||
arch_base = _('<?xml version="1.0"?>' |
|||
'<data>' |
|||
'<field name="%s" position="%s">' |
|||
'<field name="%s"/>' |
|||
'</field>' |
|||
'</data>') % (self.position_field.name, self.position, |
|||
self.name) |
|||
if self.widget: |
|||
arch_base = _('<?xml version="1.0"?>' |
|||
'<data>' |
|||
'<field name="%s" position="%s">' |
|||
'<field name="%s" widget="%s"/>' |
|||
'</field>' |
|||
'</data>' |
|||
) % (self.position_field.name, self.position, |
|||
self.name, self.widget.name) |
|||
self.env['ir.ui.view'].sudo().create({ |
|||
'name': 'sale.order.dynamic.field', |
|||
'type': 'form', |
|||
'model': 'sale.order', |
|||
'mode': 'extension', |
|||
'inherit_id': inherit_id.id, |
|||
'arch_base': arch_base, |
|||
'active': True |
|||
}) |
|||
return { |
|||
'type': 'ir.actions.client', |
|||
'tag': 'reload', |
|||
} |
|||
|
|||
position_field = fields.Many2one( |
|||
'ir.model.fields', string='Field Name', |
|||
domain=set_domain, required=True, |
|||
help="The custom field is added before or after this field") |
|||
position = fields.Selection( |
|||
[('before', 'Before'), ('after', 'After')], |
|||
string='Position', |
|||
required=True, |
|||
help="Before/After") |
|||
model_id = fields.Many2one( |
|||
'ir.model', string='Model', |
|||
required=True, index=True, ondelete='cascade', |
|||
help="The model this field belongs to", domain=_set_default) |
|||
ref_model_id = fields.Many2one( |
|||
'ir.model', string='Model', index=True, |
|||
help="Reference model for Many2one and Many2many field types") |
|||
selection_field = fields.Char(string="Selection Options", |
|||
help="Field type Selection") |
|||
field_type = fields.Selection( |
|||
selection='get_possible_field_types', string='Field Type', |
|||
required=True, help="Type of field") |
|||
ttype = fields.Selection( |
|||
string="Field Type", related='field_type', help="Type of field") |
|||
widget = fields.Many2one( |
|||
'field.widget', string='Widget', |
|||
domain=lambda self: "[('data_type', '=', field_type)]", |
|||
help="Widget for the field type") |
|||
groups = fields.Many2many( |
|||
'res.groups', |
|||
'sale_dynamic_fields_group_rel', |
|||
'field_id', |
|||
'group_id', help="User group allows this operation") |
|||
extra_features = fields.Boolean( |
|||
string="Show Extra Properties", help="Extra properties for field") |
|||
|
|||
@api.onchange('widget') |
|||
def _onchange_widget(self): |
|||
""" |
|||
Checking the selected model 'ir.attachment' for many2many_binary widget. |
|||
""" |
|||
if self.widget.name == 'many2many_binary': |
|||
self.ref_model_id = self.env.ref('base.model_ir_attachment') |
|||
|
|||
@api.onchange('ref_model_id') |
|||
def _onchange_ref_model_id(self): |
|||
""" |
|||
Raise a warning if the wrong model is chosen for the 'many2many_binary' |
|||
widget. |
|||
""" |
|||
if (self.widget.name == 'many2many_binary' and |
|||
self.ref_model_id.name != 'Attachment'): |
|||
self.ref_model_id = self.env.ref('base.model_ir_attachment') |
|||
raise UserError( |
|||
'This widget is only available for model Attachment') |