Please, i need to customize fields to print from rapport of sale module, so I created a new module and installed it (odoo 12). I have created an XML file, but have this error:
odoo.tools.convert.ParseError: "Error while validating constraint
Element '<xpath expr="//table[#class='table table-condensed']//thead//tr">' cannot be located in parent view
Error context:
View `report_quotation_inherit_demo`
[view_id: 1603, xml_id: n/a, model: n/a, parent_id: 649]
None" while parsing None:5, near
<data inherit_id="sale.report_saleorder_document">
<!-- Finds the first table with as class table table-condensed and gives the ability to modify it
This will replace everything withing tr (including tr)-->
<xpath expr="//table[#class='table table-condensed']//thead//tr" position="replace">
<tr style="background-color:lightgray;">
<th>Description</th>
<th class="text-right">Price</th>
</tr>
</xpath>
<!-- This will search for the 4'th td element (in the tbody with class sale_tbody) and will remove it. -->
<!-- Important: if you would start with element 2, then do 3 and then do 4 you will see strange behaviour.
The first statement would remove element 2 making all other elements move in numbering too. -->
<xpath expr="//tbody[#class='sale_tbody']//tr//td[4]" position="replace">
</xpath>
<xpath expr="//tbody[#class='sale_tbody']//tr//td[3]" position="replace">
</xpath>
<xpath expr="//tbody[#class='sale_tbody']//tr//td[2]" position="replace">
</xpath>
</data>
You can also define xpath like this:
<xpath expr="//table//thead//tr[1]" position="replace">
From this, it is necessary to have only one table in that template and one thead in that table.
If there are multiple than you can define number like as I given example tr[1]
Related
I am trying to replace a <t> element using xpath, but it contains a single quote inside the condition.
here is what I tried.
<xpath expr="//t[#t-if='receipt.client and env.pos.company.country and env.pos.company.country.code == 'IN'']" position="replace"/>
How can I do it?
There are two solutions for this.
First :
<xpath expr="//t[#t-if="receipt.client and env.pos.company.country and env.pos.company.country.code == 'IN'"]" position="replace"/>
Second :
<xpath expr="//t[contains(#t-if,"receipt.client and env.pos.company.country and env.pos.company.country.code == 'IN'")]" position="replace"/>
Consider using this form instead :
<xpath expr="//t[#t-if][1]" position="replace"/>
Hello I need to add some information to the delete record confirmation dialog on Odoo 12, adding some information of how many dependent records will be deleted. Something like:
Are you sure you want to delete this record ?
Doing this you will lose N records.
Currently is defined on "addons/web/static/src/js/views/basic/basic_controller.js" on _deleteRecords method. But if I change it there it will be changed for all my modules.
I'm wondering if there is a method to overwrite this... Or my other idea is to hide the button and use a wizard to do it.
any idea?
By default odoo can do that from xml file but if you need dynamic message than
please create one transient model for wizard and this model have two fields which is your message field and your main form view id after that you simply override the method unlink and in method do your computations if you want confirmation in deletion then return from that condition like this:
return{
'type':'ir.actions.act_window',
'name':'Message',
'res_model':'your.wizard.model',
'view_type':'form',
'view_mode':'form',
'target':'new',
'context':{'thesis_obj':self.id,'text_message_field':'course Work completed'},
'res_id':value.id
}
After wizard opened you have your wizard's form view right?
in wizard form view if user click on OK button then call your original method from which you have to do it in first place.
Wizard View Reference:
<record id="wizard_message_form_view" model="ir.ui.view">
<field name="name">Approval Message</field>
<field name="model">your.wizard.model</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Message">
<separator string="Message" colspan="6"/>
<field name="text_message" colspan="4" nolabel="1" readonly="1" widget="html"/>
<newline/>
<separator colspan="6"/>
<footer>
<button name="btn_approve_oric" type="object" string="OK" class="oe_highlight"/>
<button special="cancel" string="No"/>
</footer>
</form>
</field>
Feel free to ask.
I want to update the field done_date which is part of the project.task form view when pulling a Kanban tile on the stage that is indicated as being the final stage.
My code below works fine if the field is part of the Kanban view but fails to write if the field is only part of the task form view and not part of the Kanban project view.
The done_date field should be written even without being part of the Kanban view.
models.py
# -*- coding: utf-8 -*-
from odoo import models, fields, api
class project_set_end_date(models.Model):
inherit = 'project.task.type'
last_stage = fields.Boolean(string="Final stage")
class project_set_end_date(models.Model):
_inherit = 'project.task'
#api.onchange('stage_id')
def _set_end_date(self):
if self.stage_id.last_stage:
self.date_finished = fields.Datetime.now()
views.py
<odoo>
<data>
<!-- explicit list view definition -->
<record model="ir.ui.view" id="project_set_end_date">
<field name="name">project.task.type.form</field>
<field name="model">project.task.type</field>
<field name="inherit_id" ref="project.task_type_edit"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='fold']" position='after'>
<field name="last_stage"/>
</xpath>
</field>
</record>
</data>
</odoo>
Odoo doesn't write to a field that doesn't exist in the current view. So I suggest adding the field but with the attribute invisible = True to avoid showing it:
<field name="your_field" invisible="True"/>
I'm a new Odoo developer and I need to hide the edit button when my form is entering a custom state, I need this because of a security problem.
This code in XML does not work when I try to give an attribute to the form.
<record model="ir.ui.view" id="pesan_form_view">
<field name="name">pesan_service_form</field>
<field name="model">pesan.service</field>
<field name="arch" type="xml">
<form string="Booking Service" attrs="{edit:'false':[('state','in','baru')]}">
<!-- structure of form -->
</record>
I don't know why it doesn't work.
qWeb conditions doesn't work for FormView.
You can check it here(path_to_odoo/addons/web/static/src/js/framework/view.js):
/**
* Return whether the user can perform the action ('create', 'edit', 'delete') in this view.
* An action is disabled by setting the corresponding attribute in the view's main element,
* like: <form string="" create="false" edit="false" delete="false">
*/
is_action_enabled: function(action) {
var attrs = this.fields_view.arch.attrs;
return (action in attrs) ? JSON.parse(attrs[action]) : true;
},
This method calls from template FormView.buttons in path_to_odoo/addons/web/static/src/xml/base.xml:
<button t-if="widget.is_action_enabled('edit')"
type="button"
class="oe_form_button_edit btn btn-default btn-sm" accesskey="E">
Edit
</button>
These problems are solved in Odoo with the help of rules(ir.rule object of Odoo)
You can find and edit rules in GUI here: Settings(top menu) -> Security(left menu) -> Access Rules(left menu). Use admin user in debug mode for this.
At the same you can add some rules to data.xml of your module for import. They will be added when you install or update module.
Be careful! Record rules do not apply to the Administrator user.
At the same you can try to expand widget FormView.
Hope this helps you.
Try this code.
<record model="ir.ui.view" id="pesan_form_view">
<field name="name">pesan_service_form</field>
<field name="model">pesan.service</field>
<field name="arch" type="xml">
<form string="Booking Service" attrs="{'edit': [('state', 'in', ['baru'])]}">
<!-- structure of form -->
</record>
... In openerp7
I want my new state to show up in sale module ... But it is not appearing
Pls have a look at code below
In sale.py module I added state like:
class Sale_order(osv.Model):
_inherit = 'sale.order'
_columns = {
'state': fields.selection([
('draft', 'Draft Quotation'),
('my_new_state', 'My New State'),
('sent', 'Quotation Sent'),
('cancel', 'Cancelled'),
('waiting_date', 'Waiting Schedule'),
('progress', 'Sales Order'),
('manual', 'Sale to Invoice'),
('invoice_except', 'Invoice Exception'),
('done', 'Done'),
], 'Status', readonly=True, track_visibility='onchange',
help="Gives the status of the quotation or sales order. \nThe exception status is automatically set when a cancel operation occurs in the processing of a document linked to the sales order. \nThe 'Waiting Schedule' status is set when the invoice is confirmed but waiting for the scheduler to run on the order date.", select=True),
}
And in sale_view.xml, I added this piece of code..
<openerp>
<data>
<!-- Inherit the sale order model's form view and customize -->
<record id="sale_form_view" model="ir.ui.view">
<field name="name">sale.order.form.inherit</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<!-- Statusbar widget should also contain the new status -->
<field name="state" position="replace">
<field name="state" widget="statusbar" statusbar_visible="draft,my_new_state,sent,invoiced,done" statusbar_colors='{"invoice_except":"red","waiting_date":"blue"}'/>
</field>
</field>
</record>
</data>
But.... My new state is not appearing between draft quotation and quotation sent
Please guide
Why is this so
Thanks
First thing I would check is to make sure you are replacing the proper field in your view (if there are several instances of a field named "state" in the view you inherit, the wrong occurence could be replaced). Check the view by opening the 'Modify FormView' item in the developper tools/view.
If it is the wrong occurence you are replacing, you main need to change your view definition by using an xpath expression.
Second thing I would check, is make sure the sequence of your inherited view is smaller that the original view you are trying to replace/modify. You can check in 'Manage Views' item in the developper tools/view.
Third thing I would try is to rename your class from 'Sale_order' to 'sale_order' just to match the name of the original class your are trying to override.
Hope this helps.