def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False): res = super().fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu) # Read only field contact base specific groups account_advise = self.user_has_groups("account.group_account_manager") doc = etree.fromstring(res["arch"]) if not account_advise: if view_type == "form": list_readonly_field = [ "journal_id", "account_id", "user_id", "payment_term_id", "fiscal_position_id", "move_id", "date", "company_id", ] for node in doc.xpath("//field"): if node.get("name") in list_readonly_field: node.set("readonly", "1") setup_modifiers(node) res["arch"] = etree.tostring(doc) return res
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False): res = super(ResPartner, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu) doc = etree.XML(res['arch']) if view_type == 'form': no_sms = doc.xpath("//field[@name='no_sms']") no_auto_call = doc.xpath("//field[@name='no_auto_call']") fields_to_options = doc.xpath("//field") for node in fields_to_options: if no_sms and no_auto_call and node in (no_sms[0], no_auto_call[0]): if self.user_has_groups('base.group_system') or \ self.user_has_groups('mb_sale_contract.group_operator_mb_sale_contract'): node.set('readonly', "0") setup_modifiers(node) else: node.set('readonly', "1") setup_modifiers(node) res['arch'] = etree.tostring(doc) return res
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False): result = super(HrEmployee, self).fields_view_get(view_id, view_type, toolbar=toolbar, submenu=submenu) if view_type == "form": doc = etree.XML(result['arch']) for node in doc.iter(tag="field"): if 'readonly' in node.attrib.get("modifiers", ''): attrs = node.attrib.get("attrs", '') if 'readonly' in attrs: attrs_dict = safe_eval(node.get('attrs')) r_list = attrs_dict.get('readonly', ) if type(r_list) == list: r_list.insert(0, ('state', '=', 'verified')) if len(r_list) == 2: r_list.insert(0, '|') if len(r_list) > 2: r_list.insert(2, '|') attrs_dict.update({'readonly': r_list}) node.set('attrs', str(attrs_dict)) setup_modifiers(node, result['fields'][node.get("name")]) continue else: continue node.set('attrs', "{'readonly':[('state','=','verified')]}") setup_modifiers(node, result['fields'][node.get("name")]) result['arch'] = etree.tostring(doc) return result
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False): res = super(AccountInvoiceReport, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu) if view_type == 'search': doc = etree.XML(res['arch']) search_name_last_month = False search_name_inuka_month = False date_today = date.today().strftime('%d') if int(date_today) in [x for x in range(1, 8)]: search_name_last_month = "//filter[@name='last_month']" search_name_inuka_month = "//filter[@name='inuka_month']" else: search_name_last_month = "//filter[@name='last_month_1_7']" search_name_inuka_month = "//filter[@name='inuka_month_1_7']" if search_name_last_month: nodes = doc.xpath(search_name_last_month) for node in nodes: node.set('invisible', '1') setup_modifiers(node) if search_name_inuka_month: nodes = doc.xpath(search_name_inuka_month) for node in nodes: node.set('invisible', '1') setup_modifiers(node) res['arch'] = etree.tostring(doc) return res
def fields_view_get(self, view_id=None, view_type="form", toolbar=False, submenu=False): result = super(AccountInvoiceRefund, self).fields_view_get(view_id, view_type, toolbar, submenu) invoice_type = self.env.context.get("type", "out_invoice") operation_type = REFUND_TO_OPERATION[invoice_type] fiscal_type = FISCAL_TYPE_REFUND[operation_type] eview = etree.fromstring(result["arch"]) operation_id = eview.xpath( "//field[@name='force_fiscal_operation_id']") for field in operation_id: field.set( "domain", "[('operation_type', '=', '%s'), ('fiscal_type', 'in', %s)]" % (operation_type, fiscal_type), ) setup_modifiers(field) result["arch"] = etree.tostring(eview) return result
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False): res = super(ResUsers, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu) # Only admin users can see password in res_users form # see function _is_admin to know who is admin if not self.env.user._is_admin(): doc = etree.fromstring(res['arch']) if view_type == 'form': for node in doc.xpath("//field"): if node.get('name') == 'new_password': node.set('invisible', '1') setup_modifiers(node) for node in doc.xpath("//label"): if node.get('for') == 'new_password': node.set('invisible', '1') setup_modifiers(node) res['arch'] = etree.tostring(doc) return res
def fiscal_form_view(self, form_view_arch): try: fiscal_view = self.env.ref( "l10n_br_fiscal.document_fiscal_line_mixin_form") view_template_tags = { 'group': ['fiscal_fields'], 'page': ['fiscal_taxes', 'fiscal_line_extra_info'], } fsc_doc = etree.fromstring(fiscal_view["arch"]) doc = etree.fromstring(form_view_arch) for tag, tag_names in view_template_tags.items(): for tag_name in tag_names: fiscal_node = fsc_doc.xpath( "//{0}[@name='{1}']".format(tag, tag_name))[0] doc_node = doc.xpath( "//{0}[@name='{1}']".format(tag, tag_name))[0] setup_modifiers(doc_node) for n in doc_node.getiterator(): setup_modifiers(n) doc_node.getparent().replace(doc_node, fiscal_node) form_view_arch = etree.tostring(doc, encoding='unicode') except Exception: return form_view_arch return form_view_arch
def fields_view_get(self, view_id=None, view_type="form", toolbar=False, submenu=False): model_view = super().fields_view_get(view_id, view_type, toolbar, submenu) if view_type == 'form': try: vtex_view = self.env.ref("connector_vtex.vtex_mixin_form_view") vtex_arch = etree.fromstring(vtex_view["arch"]) doc = etree.fromstring(model_view.get('arch')) # Replace page doc_page_node = doc.xpath("//notebook") if doc_page_node: page_node = vtex_arch.xpath("//page[@name='vtex_page']")[0] for n in page_node.getiterator(): setup_modifiers(n) doc_page_node[0].append(page_node) else: sheet_page_node = doc.xpath("//sheet") or doc.xpath("//form") field_node = vtex_arch.xpath("//field[@name='vtex_bind_ids']")[0] for n in field_node.getiterator(): setup_modifiers(n) sheet_page_node[0].append(field_node) model_view["arch"] = etree.tostring(doc, encoding='unicode') except Exception: return model_view return model_view
def fiscal_form_view(self, form_view_arch): try: fiscal_view = self.env.ref( "l10n_br_fiscal.document_fiscal_line_mixin_form") # Get template tags fsc_doc = etree.fromstring(fiscal_view["arch"]) group_node = fsc_doc.xpath("//group[@name='fiscal_fields']")[0] page_node = fsc_doc.xpath("//page[@name='fiscal_taxes']")[0] doc = etree.fromstring(form_view_arch) # Replace group doc_group_node = doc.xpath("//group[@name='fiscal_fields']")[0] setup_modifiers(group_node) doc_group_node.getparent().replace(doc_group_node, group_node) # Replace page doc_page_node = doc.xpath("//page[@name='fiscal_taxes']")[0] for n in page_node.getiterator(): setup_modifiers(n) doc_page_node.getparent().replace(doc_page_node, page_node) form_view_arch = etree.tostring(doc, encoding='unicode') except Exception: return form_view_arch return form_view_arch
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False): res = super(AccountInvoice, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu) user = self.env.user if view_type == 'tree' and not all( user.has_group(group_ext_id) for group_ext_id in ( 'invoice_doc_type_ir_rules.group_remisiones', 'invoice_doc_type_ir_rules.group_cfdi', 'invoice_doc_type_ir_rules.group_vacios', )): doc = etree.XML(res['arch']) nodes = doc.xpath("//tree/field[@name='x_document_type']") for node in nodes: node.set('invisible', '1') setup_modifiers(node, in_tree_view=True) res['arch'] = etree.tostring(doc) return res
def _build_attribute_field(self, attribute_egroup): """Add an etree 'field' subelement (related to the current attribute 'self') to attribute_egroup, with a conditional invisibility based on its attribute sets.""" self.ensure_one() kwargs = {"name": "%s" % self.name} kwargs["attrs"] = str(self._get_attrs()) if self.readonly: kwargs["readonly"] = str(True) if self.ttype == "many2many": # TODO use an attribute field instead # to let user specify the widget. For now it fixes: # https://github.com/shopinvader/odoo-pim/issues/2 kwargs["widget"] = "many2many_tags" if self.ttype in ["many2one", "many2many"]: if self.relation_model_id: # TODO update related attribute.option in cascade to allow # attribute.option creation from the field. kwargs["options"] = "{'no_create': True}" # attribute.domain is a string, it may be an empty list try: domain = ast.literal_eval(self.domain) except ValueError: domain = None if domain: kwargs["domain"] = self.domain else: # Display only options linked to an existing object ids = [ op.value_ref.id for op in self.option_ids if op.value_ref ] kwargs["domain"] = "[('id', 'in', %s)]" % ids # Add color options if the attribute's Relational Model # has a color field relation_model_obj = self.env[self.relation_model_id.model] if "color" in relation_model_obj.fields_get().keys(): kwargs[ "options"] = "{'color_field': 'color', 'no_create': True}" elif self.nature == "custom": # Define field's domain and context with attribute's id to go along with # Attribute Options search and creation kwargs["domain"] = "[('attribute_id', '=', %s)]" % (self.id) kwargs["context"] = "{'default_attribute_id': %s}" % (self.id) if self.ttype == "text": # Display field label above his value field_title = etree.SubElement(attribute_egroup, "b", colspan="2", attrs=kwargs["attrs"]) field_title.text = self.field_description kwargs["nolabel"] = "1" kwargs["colspan"] = "2" setup_modifiers(field_title) efield = etree.SubElement(attribute_egroup, "field", **kwargs) setup_modifiers(efield)
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False): res = super(SaleService, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu) if view_type <> 'form': return res doc = etree.XML(res['arch']) check_customer = doc.xpath("//field[@name='customer_id']") check_product = doc.xpath("//field[@name='product_id']") if check_customer or check_product: fields_parent = doc.xpath("//field") for node in fields_parent: if (self.user_has_groups('base.group_system') or self.user_has_groups('mb_sale_contract.group_operator_mb_sale_contract')) and \ node in (check_customer[0], check_product[0]): node.set('options', "{}") setup_modifiers(node) elif not self.user_has_groups('base.group_system') and not self.user_has_groups('mb_sale_contract.group_operator_mb_sale_contract') and \ node in (check_customer[0], check_product[0]): node.set('options', "{'no_create_edit': True}") setup_modifiers(node) res['arch'] = etree.tostring(doc) return res
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False): res = super(ShiftCounterEvent, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu) doc = etree.fromstring(res['arch']) access_inform = self.user_has_groups( 'coop_membership.coop_group_access_res_partner_inform') if not access_inform: node = doc.xpath("//field[@name='reason_ids']") options = { 'no_create': True, 'no_quick_create': True, 'no_create_edit': True } if node: node[0].set("options", repr(options)) setup_modifiers(node[0], res['fields']['reason_ids']) res['arch'] = etree.tostring(doc) return res
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False): res = super(Lead, self).fields_view_get(view_id, view_type, toolbar, submenu) if view_type == 'form': doc = XML(res['arch']) FIELDS = ['source_id', 'campaign_id', 'medium_id'] if not self.user_has_groups('sales_team.group_sale_manager'): for field in FIELDS: LABEL_STR = "//field[@name='{0}']".format(field) node = doc.xpath(LABEL_STR) if node: node = node[0] node.set( "options", "{'no_create': True, 'no_create_edit': True}") if field in res['fields']: setup_modifiers(node, res['fields'][field]) res['arch'] = tostring(doc, encoding='unicode') return res
def fields_view_get(self, view_id=None, view_type=False, toolbar=False, submenu=False): PurchaseGrp = self.user_has_groups('purchase.group_purchase_user') res = super(InternalOrder, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu) doc = etree.XML(res['arch']) # print ("res['fields']") # for r in res['fields'].keys(): # # if r == 'order_line': # print ("......", r) # print (res['fields'][r].keys()) if PurchaseGrp and view_type == 'form': print("... inside ...") for node in doc.xpath("//field[@name='target_price']"): print("... found the node ...") # node = doc.xpath("//field[@name='method_end']")[0] # node.set('invisible', '1') # setup_modifiers(node, result['fields']['method_end']) node.set('string', 'Target Price Proc') setup_modifiers(node, res['fields']['currency_id']) res['arch'] = etree.tostring(doc) return res
def custom_field_details(self, model, view_type, result): fields = self.search([('model', '=', model), ('state', '=', 'manual')], order='sequence') view_form_fields, view_tree_fields, view_search_fields = '', '', '' for field in fields: view_form_fields = view_form_fields + """ <field name="%s"/>""" % field.name + '\n' if field.list_ok: view_tree_fields = view_tree_fields + """ <field name="%s"/>""" % field.name + '\n' if field.search_ok: view_search_fields = view_search_fields + """ <field name="%s"/>""" % field.name + '\n' result['fields'].update(field_details(field)) if view_type in ('form', 'tree', 'search'): result.update( {'arch': eval(view_type + '_view_arch')(eval('view_' + view_type + '_fields'), result['arch'])}) if view_type == 'form': doc = etree.XML(result['arch']) req_fields = self.search([('model', '=', model), ('state', '=', 'manual'), ('required', '=', True)]) for field in req_fields: for node in doc.xpath("//field[@name='%s']" % field.name): node.set('required', "1") setup_modifiers(node, result['fields'][field.name]) result['arch'] = etree.tostring(doc) mm_fields = self.search([('model', '=', model), ('state', '=', 'manual'), ('ttype', '=', 'many2many')]) for field in mm_fields: for node in doc.xpath("//field[@name='%s']" % field.name): node.set('widget', "many2many_tags") setup_modifiers(node, result['fields'][field.name]) result['arch'] = etree.tostring(doc) return result
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False): result = super(AccountMoveLine, self).fields_view_get(view_id, view_type, toolbar=toolbar, submenu=submenu) doc = etree.XML(result['arch']) if view_type == 'tree': for placeholder in doc.xpath("//field[@name='days_overdue']"): for overdue_term in self.env['account.overdue.term'].search( [], order='from_day DESC'): elem = etree.Element('field', { 'name': str(overdue_term.tech_name), 'readonly': 'True' }) orm.setup_modifiers(elem) placeholder.addnext(elem) result['fields'].update({ overdue_term.tech_name: { 'domain': [], 'string': overdue_term.name, 'context': {}, 'type': 'float', 'sum': 'Total' } }) result['arch'] = etree.tostring(doc) return result
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False): result = super(AssetModify, self).fields_view_get(view_id, view_type, toolbar=toolbar, submenu=submenu) asset_id = self.env.context.get('active_id') active_model = self.env.context.get('active_model') if active_model == 'account.asset.asset' and asset_id: asset = self.env['account.asset.asset'].browse(asset_id) doc = etree.XML(result['arch']) if asset.method_time == 'number' and doc.xpath( "//field[@name='method_end']"): node = doc.xpath("//field[@name='method_end']")[0] node.set('invisible', '1') setup_modifiers(node, result['fields']['method_end']) elif asset.method_time == 'end' and doc.xpath( "//field[@name='method_number']"): node = doc.xpath("//field[@name='method_number']")[0] node.set('invisible', '1') setup_modifiers(node, result['fields']['method_number']) result['arch'] = etree.tostring(doc, encoding='unicode') return result
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False): """ In user_profile, all groups of user will be defined in profile So, we need to set readonly for all fields in tab "access_rights" to make sure all users of a profile have same groups """ res = super(ResUsers, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu) attr_key = 'readonly' attr_value = '1' # only superuser can edit group of admin (uid = 1) if self.env.user._is_superuser(): attr_key = 'attrs' attr_value = "{'readonly': [('id', '!=', 2)]}" doc = etree.fromstring(res['arch']) if view_type == 'form': for node in doc.xpath("//page[@name='access_rights']//field"): node.set(attr_key, attr_value) setup_modifiers(node) res['arch'] = etree.tostring(doc) return res
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False): """ Override to add message_content field in all the objects that inherits mail.thread """ res = super(MailThread, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu) if view_type == 'search' and self._fields.get('message_content'): doc = etree.XML(res['arch']) res['fields'].update({ 'message_content': { 'type': 'char', 'string': _('Message Content'), } }) for node in doc.xpath("//field[last()]"): # Add message_content in search view elem = etree.Element('field', { 'name': 'message_content', }) setup_modifiers(elem) node.addnext(elem) res['arch'] = etree.tostring(doc) return res
def fields_view_get(self, view_id=None, view_type=False, toolbar=False, submenu=False): """ Only purchase manager can select any partner and purchase user can not select any other partner """ res = super(PurchaseOrder, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu) doc = etree.XML(res['arch']) manager = self.user_has_groups('purchase.group_purchase_manager') user = self.user_has_groups('purchase.group_purchase_user') admins = self.env['res.users'].search([('login', 'ilike', 'admin')]) for field in res['fields']: if field == 'partner_id': if manager or user or self.env.uid in admins: for node in doc.xpath("//field[@name='partner_id']"): node.set('readonly', '0') setup_modifiers(node, res['fields']['partner_id']) else: for node in doc.xpath("//field[@name='partner_id']"): node.set('readonly', '1') setup_modifiers(node, res['fields']['partner_id']) res['arch'] = etree.tostring(doc) return res
def _set_fields_readonly(doc, res): """Set all fields in the view to readonly""" for node in doc.xpath("//field"): field_name = node.get("name") if field_name: node.set("readonly", "1") if field_name in res["fields"]: setup_modifiers(node, res["fields"][field_name])
def _set_readonly_form_view(self, doc): for field in doc.iter("field"): env_fields = self._server_env_fields.keys() field_name = field.get("name") if field_name in env_fields: continue field.set("readonly", "1") setup_modifiers(field, self.fields_get(field_name))
def _add_localization_field(doc): elem = etree.Element('field', { 'name': 'l10n_cl_localization', 'invisible': 'True', }) nodes = doc.xpath("//form//field") if len(nodes): orm.setup_modifiers(elem) nodes[0].addnext(elem)
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False): """ If we came from sale order, we send in context 'force_product_edit' and we change tree view to make editable and also field qty """ res = super(ProductProduct, self).fields_view_get( view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu) sale_quotation_products = self._context.get('sale_quotation_products') if sale_quotation_products and view_type == 'tree': doc = etree.XML(res['arch']) # make all fields not editable for node in doc.xpath("//field"): node.set('readonly', '1') setup_modifiers(node, res['fields'], in_tree_view=True) # add qty field placeholder = doc.xpath("//field[1]")[0] placeholder.addprevious( etree.Element('field', { 'name': 'qty', # we force editable no matter user rights 'readonly': '0', })) # add button add one placeholder.addprevious( etree.Element('button', { 'name': 'action_product_add_one', 'type': 'object', 'icon': 'fa-plus', 'string': _('Add one'), })) res['fields'].update(self.fields_get(['qty'])) # add button tu open form placeholder = doc.xpath("//tree")[0] placeholder.append( etree.Element('button', { 'name': 'action_product_form', 'type': 'object', 'icon': 'fa-external-link', 'string': _('Open Product Form View'), 'groups': 'base.group_user', })) # make tree view editable for node in doc.xpath("/tree"): node.set('edit', 'true') node.set('create', 'false') node.set('editable', 'top') res['arch'] = etree.tostring(doc) return res
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False): res = super(NonMovingStock, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu) if not self.env['ir.config_parameter'].sudo().get_param('flexibite_com_advance.groups_ids'): if view_type == 'form': doc = etree.XML(res['arch']) nodes = doc.xpath("//button[@name='send_mail']") for node in nodes: node.set('invisible', '1') setup_modifiers(node) res['arch'] = etree.tostring(doc) return res
def _build_attribute_field(self, page, attribute): parent = etree.SubElement(page, 'group') kwargs = { 'String': "%s" % attribute.name, 'name': "%s" % attribute.attribute_code.lower().replace(" ", "_") } if attribute.type in ['multiselect', 'text']: parent = etree.SubElement(parent, 'group') etree.SubElement(parent, 'separator', string="%s" % attribute.frontend_label, name="name", colspan="4") kwargs['nolabel'] = "1" if attribute.type in ['multiselect', 'select']: # if attribute.relation_model_id: # # attribute.domain is a string, it may be an empty list # try: # domain = ast.literal_eval(attribute.domain) # except ValueError: # domain = None # if domain: # kwargs['domain'] = attribute.domain # else: # ids = [op.value_ref.id for op in attribute.option_ids] # kwargs['domain'] = "[('id', 'in', %s)]" % ids # else: if attribute.name == 'categ_ids': backend_ids = [ backend.backend_id.id for backend in attribute.attribute_id.magento_bind_ids ] domain = "[('magento_bind_ids.backend_id','in',%s)]" % backend_ids kwargs['domain'] = domain else: kwargs[ 'domain'] = "[('magento_attribute_id', '=', %s)]" % attribute.id if attribute.type == 'multiselect': kwargs['widget'] = 'many2many_tags' kwargs['options'] = "{'no_create':True}" kwargs[ 'context'] = "{'default_magento_attribute_id': %s}" % attribute.id if attribute.type == 'boolean': kwargs['required'] = str(False) else: kwargs['required'] = str(attribute.is_required) # or # attribute.required_on_views) field = etree.SubElement(parent, 'field', **kwargs) orm.setup_modifiers(field, self.fields_get(attribute.attribute_code)) return parent
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False): result = super(pos_session, self).fields_view_get(view_id, view_type, toolbar=toolbar, submenu=submenu) if view_type == 'form' and self.env.user.is_standard_cashier: doc = etree.XML(result['arch']) # statement ids label/separator for node in doc.xpath("//separator"): node.set('invisible', "1") setup_modifiers(node) # statement ids if doc.xpath("//field[@name='statement_ids']"): node = doc.xpath("//field[@name='statement_ids']")[0] node.set('invisible', '1') setup_modifiers(node, result['fields']['statement_ids']) # cash control -> opening balance and etc for node in doc.xpath( "//group/div[1]/group[hasclass('oe_subtotal_footer')]"): node.set('invisible', "1") setup_modifiers(node) break if doc.xpath("//field[@name='cash_register_difference']"): node = doc.xpath( "//field[@name='cash_register_difference']")[0] node.set('invisible', '1') setup_modifiers(node, result['fields']['cash_register_difference']) result['arch'] = etree.tostring(doc, encoding='unicode') return result
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False): """ Con esta funcion hacemos dos cosas: 1. Mostrar solo la columna que corresponda segun el modelo 2. Agregar dominio segun el dominio original de la porperty mas de cia """ res = super(ResCompanyProperty, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu) doc = etree.XML(res['arch']) property_field = self._context.get('property_field') domain = self._context.get('property_domain') record = self._get_record() if record: field = self._get_record()._fields.get(property_field) # si no viene definido un property_domain buscamos uno para # definido ene l campo de la property if not domain: try: domain = literal_eval(field.domain) except: domain = [] domain_elements = [str(x) for x in domain] # add company domain if comodel has company comodel = self._get_property_comodel() if comodel: if self.env[comodel]._fields.get('company_id'): domain_elements += [ "'|'", "('company_id', '=', False)", "('company_id', '=', company_id)" ] str_domain = '[%s]' % ','.join(domain_elements) company_property_field = self._get_company_property_field() xpath = "//field[@name='%s']" % company_property_field for node in doc.xpath(xpath): node.set('domain', str(str_domain)) node.set('invisible', '0') # modifiers make still invisible = 1 setup_modifiers(node, res['fields'][company_property_field]) res['arch'] = etree.tostring(doc) return res
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False): res = super(DataNcmNbsAbstract, self).fields_view_get( view_id, view_type, toolbar, submenu) if view_type == 'form': xml = etree.XML(res['arch']) xml_button = xml.xpath("//button[@name='action_ibpt_inquiry']") if xml_button and not self.env.user.company_id.ibpt_api: xml_button[0].attrib['invisible'] = '1' orm.setup_modifiers(xml_button[0]) res['arch'] = etree.tostring(xml, pretty_print=True) if res.get('toolbar') and not self.env.user.company_id.ibpt_api: res['toolbar']['action'] = [] return res
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False): result = super(AssetModify, self).fields_view_get(view_id, view_type, toolbar=toolbar, submenu=submenu) asset_id = self.env.context.get('active_id') active_model = self.env.context.get('active_model') if active_model == 'account.asset.asset' and asset_id: asset = self.env['account.asset.asset'].browse(asset_id) doc = etree.XML(result['arch']) if asset.method_time == 'number' and doc.xpath("//field[@name='method_end']"): node = doc.xpath("//field[@name='method_end']")[0] node.set('invisible', '1') setup_modifiers(node, result['fields']['method_end']) elif asset.method_time == 'end' and doc.xpath("//field[@name='method_number']"): node = doc.xpath("//field[@name='method_number']")[0] node.set('invisible', '1') setup_modifiers(node, result['fields']['method_number']) result['arch'] = etree.tostring(doc) return result