How do i customise product template views by inheritance in odoo 14? - python-3.x

I'm trying to add a custom field in product_templte_form_vieew by doing this :
<!-- product template -->
<record id="mymoduleproduct_view_form" model="ir.ui.view">
<field name="name">mymodule.product</field>
<field name="model">mymodule.product</field>
<field name="inherit_id" ref="product.product_template_form_view"/>
<field name="arch" type="xml">
<xpath expr="//notebook/page[#name='general_information']/group[2]" position="attributes">
<field name="prixass"/>
<field name="taxes_id" position="attributes">
<attribute name="invisible">1</attribute>
</field>
</xpath>
</field>
</record>
No error in excution but it seems to not work. Need help to detect or correct what is wrong.
I have already define ‘prixass’ fields like this :
class MyModuleProduct(models.Model):
_name = "mymodule.product"
_description = "table des articles"
_inherit = "product.template"
prixass = fields.Float(string='Prix Assurance')
taxes_id = fields.Many2many('account.tax', 'product_hospi_taxes', 'prod_hospi_id', 'tax_id', string='Customer Taxes')
supplier_taxes_id = fields.Many2many('account.tax', 'product_hospi_supplier_taxes', 'prod_hospi_id', 'tax_id', string='Vendor Taxes')
route_ids = fields.Many2many('stock.location.route', 'stock_route_product_hospi', 'product_hospi_id', 'route_id', string='Routes',)
Also i’ld like to remove the fields taxes_id from the view, how do i do ?
.
the resume of the question in image here
Thanks .

Try this.
class MyModuleProduct(models.Model):
_inherit = "product.template"
prixass = fields.Float(string='Prix Assurance')
taxes_id = fields.Many2many('account.tax', 'product_hospi_taxes', 'prod_hospi_id', 'tax_id', string='Customer Taxes')
supplier_taxes_id = fields.Many2many('account.tax', 'product_hospi_supplier_taxes', 'prod_hospi_id', 'tax_id', string='Vendor Taxes')
route_ids = fields.Many2many('stock.location.route', 'stock_route_product_hospi', 'product_hospi_id', 'route_id', string='Routes',)
<record id="product_inherit_view" model="ir.ui.view">
<field name="name">product.template</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view"/>
<field name="arch" type="xml">
<xpath expr="//notebook/page[#name='general_information']/field[#name='default_code']" position="after">
<field name="prixass"/>
</xpath>
<field name="taxes_id" position="replace">
<field name="taxes_id" invisible="1"/>
</field>
</field>
</record>

but this work for me now
//model
class MyModuleProduct(models.Model):
_inherit = "product.template"
prixass = fields.Float(string='Prix Assurance')
taxes_id = fields.Many2many('account.tax', 'product_hospi_taxes', 'prod_hospi_id', 'tax_id', string='Customer Taxes')
supplier_taxes_id = fields.Many2many('account.tax', 'product_hospi_supplier_taxes', 'prod_hospi_id', 'tax_id', string='Vendor Taxes')
route_ids = fields.Many2many('stock.location.route', 'stock_route_product_hospi', 'product_hospi_id', 'route_id', string='Routes',)
//views
<record id="product_inherit_view" model="ir.ui.view">
<field name="name">product.template</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view"/>
<field name="arch" type="xml">
<xpath expr="//notebook/page[#name='general_information']/group[1]" position="after">
<group>
<field name="prixass"/>
</group>
</xpath>
<field name="taxes_id" position="replace">
<field name="taxes_id" invisible="1"/>
</field>
</record>
thanks.

Related

How to change string of Purchase Status(purchase_state) that is in Purchase Request? (ODOO)

So I want to change the string of "Purchase Order" inside Purchase Status(Inside Purchase Request) to something like "PO Created" when the purchase_state is in [purchase] but I don't know how I can do it. I want to create fresh module as well.
Here' s what I tried so far. I've created an XML and inherit the view.
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="purchase_request_form_inherit" model="ir.ui.view">
<field name="name">purchase.request.inherit</field>
<field name="model">purchase.request</field>
<field name="inherit_id" ref="purchase_request.view_purchase_request_form"/>
<field name="arch" type="xml">
<field name="purchase_state" position="attributes">
<attribute name="attrs" string="PO Created" attrs="{'readonly': [('po_line.state','=', 'purchase')]}"/>
</field>
</field>
</record>
</odoo>
I prefer use xpath:
<record id="purchase_request_form_inherit" model="ir.ui.view">
<field name="name">purchase.request.inherit</field>
<field name="model">purchase.request</field>
<field name="inherit_id" ref="purchase_request.view_purchase_request_form"/>
<field name="arch" type="xml">
<field expr="field[#name='purchase_state']" position="attributes">
<!-- To change the String -->
<attribute name="string">PO Created</attribute>
<!-- To change the attrs -->
<attribute name="attrs">{'readonly': [('po_line.state','=', 'purchase')]}</attribute>
</field>
</field>
</record>
I hope this answer could be helpful for you.

Odoo Inherit view can't set invisible attribute

I am odor newer.
I want to use the sale.order field and value to create a custom report by select some specific
field from sale.order.
I have created a custom model to inherit sale.order model.
And create a view to inherit view of sale.order.
Here is my code:
class SaleOrder(models.Model):
_inherit = 'sale.order'
<field name="name">Custom Sale Report</field>
<field name="res_model">sale.order</field>
<field name="view_mode">tree,form</field>
<field name="name">sale.order.inherited</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_tree" />
<field name="mode">primary</field>
<field name="arch" type="xml">
<xpath expr="//field[#name='name']" position="attributes">
<attribute name="invisible">1</attribute>
</xpath> </field> </record>
But I don't know why the invisible attribute is not working.
Please Help. Thanks.
Try this.
<field name="name">sale.order.inherited</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_tree" />
<field name="arch" type="xml">
<xpath expr="//field[#name='name']" position="replace">
<field name="name" optional="hide"/>
</xpath>
</field>
</record>

Getting values of fields in XML

I have the folling XML (as string)
xml = '''
<?xml version="1.0" encoding="utf-8"?>
<Response total="00:00:00.2130175">
<Result>
<Channel name="test">
<TotalCount ignoringpaging="2">2</TotalCount>
<Products>
<Product id="8050" ecommerceproduct="Productname">
<Fields>
<Field name="pid">8050</Field>
<Field name="ProductName">Productname</Field>
<Field name="ProductCategorie" culture="nl-NL">Category</Field>
<Field name="Titel" culture="nl-NL">Product Titel</Field>
<Field name="ProductHoogte">74</Field>
<Field name="ProductVerstelbaarheid">Vast</Field>
<Field name="ProductDikte">25</Field>
<Field name="ProductMateriaal">Gemelamineerd spaanplaat</Field>
<Field name="ProductLijn">0</Field>
<Field name="prodId">63258518</Field>
</Fields>
<Variants>
<Variant id="8060" ecommerceproduct="Productname">
<Fields>
<Field name="ProductName">Productname / Black</Field>
<Field name="PID">8060</Field>
<Field name="Zichtbaar">Y</Field>
<Field name="articleCode">123456</Field>
<Field name="priceExcl">469</Field>
<Field name="ProductBreedte">180</Field>
<Field name="ProductDiepte">80</Field>
<Field name="ProductHoogte">74</Field>
<Field name="varId">121655579</Field>
<Field name="visible">Y</Field>
</Fields>
</Variant>
</Variants>
</Product>
<Product id="8051" ecommerceproduct="Productname 2">
<Fields>
<Field name="pid">8051</Field>
<Field name="ProductName">Productname 2</Field>
<Field name="ProductCategorie" culture="nl-NL">Category</Field>
<Field name="Titel" culture="nl-NL">Product Titel 2</Field>
<Field name="ProductHoogte">74</Field>
<Field name="ProductVerstelbaarheid">Vast</Field>
<Field name="ProductDikte">25</Field>
<Field name="ProductMateriaal">Gemelamineerd spaanplaat</Field>
<Field name="ProductLijn">0</Field>
<Field name="prodId">63258520</Field>
</Fields>
<Variants>
<Variant id="8061" ecommerceproduct="Productname 2">
<Fields>
<Field name="ProductName">Productname 2 / White</Field>
<Field name="PID">8061</Field>
<Field name="Zichtbaar">Y</Field>
<Field name="articleCode">234567</Field>
<Field name="priceExcl">499</Field>
<Field name="ProductBreedte">180</Field>
<Field name="ProductDiepte">80</Field>
<Field name="ProductHoogte">74</Field>
<Field name="varId">216555798</Field>
<Field name="visible">N</Field>
</Fields>
</Variant>
</Variants>
</Product>
</Products>
</Channel>
</Result>
</Response>'''
with xml.etree I can iterate over the Products, but how can I get all the values of the fields and variants fields.
root = ET.fromstring(xml)
for p in root.iter('Product'):
print(p.attrib)
the output I get is:
{'id': '8050', 'ecommerceproduct': 'Productname'}
{'id': '8060', 'ecommerceproduct': 'Productname 2'}
So this seems to work, but whatever I try to get the values from the fields, I get no response.

how to fix the problem that a menu which is added to an existing menu doesn't be shown

i have develop a custom module which add a new menu in the attendance module to create attendance modification request for both groups "attendance/manual attendance" and "attendance/manager" the problem is my menu is added only for the admin user . If i connect with a user that has the access right manager or manual attendance for the attendance module it will be not shown. Any idea for help ?
Here is my code
hr_attendance_modification_request_view.xml
<record model="ir.ui.view" id="view_attendance_modification_request_form">
<field name="name">attendance.modification.request.form</field>
<field name="model">attendance.modification.request</field>
<field name="arch" type="xml">
<form string="Attendance modification Request">
<header>
<field name="state" statusbar_visible="draft,waiting,approved,cancel" widget="statusbar" />
<button name="submit_modification" string="Submit for manager" type="object" class="btn-primary"
attrs="{'invisible': [('state','not in','draft')]}"/>
<button name="modification_approval" type="object" string="Approve" class="oe_highlight"
groups="hr_attendance.group_hr_attendance_manager"
attrs="{'invisible': [('state','not in','waiting')]}"/>
<button name="modification_rejection" type="object" string="Cancel" class="oe_highlight"
groups="hr_attendance.group_hr_attendance_manager"
attrs="{'invisible': [('state','not in','waiting')]}"/>
</header>
<sheet>
<h2>
<group>
<field name="employee"/>
</group>
</h2>
<group string="Morning" col="4" colspan="4">
<field name="time_check_in_1"/>
<field name="time_check_out_1"/>
</group>
<group string="Afternoon" col="4" colspan="4">
<field name="time_check_in_2"/>
<field name="time_check_out_2"/>
</group>
<label for="note"/>
<field name="note"/>
</sheet>
<field name="message_follower_ids" widget="mail_followers" groups="base.group_user"/>
<field name="activity_ids" widget="mail_activity"/>
<field name="message_ids" widget="mail_thread"/>
</form>
</field>
</record>
<record model="ir.actions.act_window" id="attendance_modification_request_form_action">
<field name="name">Attendance modification Request</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">attendance.modification.request</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="domain">[]</field>
<field name="context">{"search_default_requested_by":uid}</field>
<!-- <field name="search_view_id" ref="view_attendance_request_search"/>-->
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Click to start a new attendance modification request process.
</p>
</field>
</record>
<menuitem action="attendance_modification_request_form_action" id="menu_attendance_modification_request"
name="Attendance modification request" parent="hr_attendance.menu_hr_attendance_manage_attendances"
sequence="14" groups="hr_attendance.group_hr_attendance"/>
<record model="ir.actions.act_window" id="action_view_attendance_request_approval">
<field name="name">Attendance modification request to approve</field>
<field name="res_model">attendance.modification.request</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="domain">[('state','!=','approved'),('state','!=','cancel')]</field>
<field name="help" type="html">
<p class="oe_view_no_content_create">Create new Record
</p>
</field>
</record>
<menuitem action="action_view_attendance_request_approval" id="menu_attendance_modification_request_to_approve"
name="Attendance modification request to Approve"
parent="hr_attendance.menu_hr_attendance_manage_attendances"
sequence="15" groups="hr_attendance.group_hr_attendance_manager"/>
i should add ir.model.access.csv file
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink access_attendance_modification_request,access_attendance_modification_request,model_attendance_modification_request,hr_attendance.group_hr_attendance_manager,1,1,1,1 access_attendance_modification_request,access_attendance_modification_request,model_attendance_modification_request,hr_attendance.group_hr_attendance,1,1,1,1

Query all nodes with a special attribute value

I have a problem querying an XML structure.
This is the document:
<?xml version="1.0" encoding="UTF-8"?>
<document>
<LangSet id="1031">
<field id="Language">1031</field>
<field id="PrimaryLanguage">7</field>
<Term id="18">
<field id="CreatedBy">dot_Termservice</field>
<field id="CreatedOn">20060905T170414Z</field>
<field id="CreatedOnUTC">20060905T150414Z</field>
<field id="CreatedOrUpdatedBy">dot_Termservice</field>
<field id="CreatedOrUpdatedOn">20080107T141350Z</field>
<field id="CreatedOrUpdatedOnUTC">20080107T121350Z</field>
<field id="Status">Negativterm.Kunden-orientiert;Negativterm.Technik-orientiert</field>
<field id="Term">Innenpersenning</field>
<field id="TermType">MainTerm</field>
<field id="UpdatedBy">dot_Termservice</field>
<field id="UpdatedOn">20080107T141350Z</field>
<field id="UpdatedOnUTC">20080107T121350Z</field>
<field id="UserId">11817</field>
</Term>
<Term id="19">
<field id="CreatedBy">dot_Termservice</field>
<field id="CreatedOn">20020626T120555Z</field>
<field id="CreatedOnUTC">20020626T100555Z</field>
<field id="CreatedOrUpdatedBy">dot_Termservice</field>
<field id="CreatedOrUpdatedOn">20020626T120555Z</field>
<field id="CreatedOrUpdatedOnUTC">20020626T100555Z</field>
<field id="Status">Vorzugsterm.Kunden-orientiert;Vorzugsterm.Technik-orientiert</field>
<field id="Term">Persenning</field>
<field id="TermType">MainTerm</field>
<field id="UserId">18088</field>
</Term>
<Term id="20">
<field id="CreatedBy">dot_Termservice</field>
<field id="CreatedOn">20011105T140407Z</field>
<field id="CreatedOnUTC">20011105T120407Z</field>
<field id="CreatedOrUpdatedBy">dot_Termservice</field>
<field id="CreatedOrUpdatedOn">20080107T141350Z</field>
<field id="CreatedOrUpdatedOnUTC">20080107T121350Z</field>
<field id="Status">Negativterm.Kunden-orientiert;Negativterm.Technik-orientiert</field>
<field id="Term">Verdeckabdeckung</field>
<field id="TermType">MainTerm</field>
<field id="UpdatedBy">dot_Termservice</field>
<field id="UpdatedOn">20080107T141350Z</field>
<field id="UpdatedOnUTC">20080107T121350Z</field>
<field id="UserId">32287</field>
</Term>
</LangSet>
<LangSet id="1031">
<field id="Language">1031</field>
<field id="PrimaryLanguage">7</field>
<Term id="8">
<field id="CreatedBy">dot_Termservice</field>
<field id="CreatedOn">20060905T170414Z</field>
<field id="CreatedOnUTC">20060905T150414Z</field>
<field id="CreatedOrUpdatedBy">dot_Termservice</field>
<field id="CreatedOrUpdatedOn">20070711T153241Z</field>
<field id="CreatedOrUpdatedOnUTC">20070711T133241Z</field>
<field id="Status">Vorzugsterm.Kunden-orientiert;Vorzugsterm.Technik-orientiert</field>
<field id="Term">Innenrad</field>
<field id="TermType">MainTerm</field>
<field id="UpdatedBy">dot_Termservice</field>
<field id="UpdatedOn">20070711T153241Z</field>
<field id="UpdatedOnUTC">20070711T133241Z</field>
<field id="UserId">11818</field>
</Term>
</LangSet>
</document>
All I want to do is to get all the Textvalues of the field elements with the attribute id=Term and return them in a LangSet as showned below:
<LangSet> <field id="Term">Innenpersenning</field> <field
id="Term">Persenning</field> <field id="Term">Verdeckabdeckung</field>
</LangSet>
<LangSet>
<field id="Term">Innenrad</field>
</LangSet>
<LangSet>
<field id="Term">Raumakustik</field>
</LangSet>
<LangSet>
<field id="Term">Fahrgastraumbeleuchtung</field> <field
id="Term">IB</field> <field id="Term">Innenbeleuchtung</field> <field
id="Term">Innenraumbeleuchtung</field>
</LangSet>
I'm getting the right values but unfortunatley not in a Langset node:
xquery version "1.0";
declare boundary-space strip;
declare namespace xs="http://www.w3.org/2001/XMLSchema";
for $x in doc("Sample.xml")/Document/Database/Dictionary/Concept/LangSet/Term//field
where $x/#id="Term"
return $x
I'm sure that it isn't that difficult but I'm stuck in documentation and I can't find the solution which works for me.
Thank you for any suggestions!
If you decide to return <LangSet> elements from your document, which contain appropriate <field> descendant elements, they will also contain all their other descendants.
If I understand what you want, you need to create on-the-fly some semi-clone elements reflecting partially your input document filtered and return them.
Scan LangSet-s and test each of them for desired descendants. If found, create appropriate output elements:
let $doc := doc("Sample.xml")
for $langset in $doc/document/LangSet
let $fields := $langset/descendant::field[#id = 'Term']
where exists($fields)
return
<LangSet>
{
for $field in $fields return
<field id='Term'>{string($field)}</field>
}
</LangSet>
You can solve this with an top-down approach like CiaPan's answer is or an bottom-up approach.
Based on the xml example you gave solutions could be:
Top-down
let $document := doc("langset.xml")/*
for $langset in $document/LangSet
let $fields := $langset//field[#id = 'Term']
return
<LangSet>
{ $fields }
</LangSet>
Bottom-up
let $document := doc("langset.xml")/*
for $field in $document//field[#id = 'Term']
group by $langset := $field/ancestor::LangSet
order by $langset descending
return
<LangSet>
{ $field }
</LangSet>

Resources