Odoo 15 Helpdesk formatting ID field - formatting

I need help with the modul Helpdesk. I wanted to add the field ID into the tree view via Addon. I could manage to do so, but now I want to format the field like this Ticket ID : #1234, at the moment its in this kind of format : Ticket ID 1,234. I also canĀ“t find the field ID in the source code.
This my code for the tree view:
<!-- Helpdesk Addon Tree View -->
<record id="helpdesk_addon_tree_view" model="ir.ui.view">
<field name="name">view.helpdesk.addon.tree</field>
<field name="model">helpdesk.ticket</field>
<field name="inherit_id" ref="helpdesk.helpdesk_tickets_view_tree"/>
<field name="arch" type="xml">
<field name="display_name" position="before">
<field name="id" string="ID"/>
</field>
<field name="stage_id" position="after">
<field name="create_date"/>
</field>
</field>
</record>
</odoo>

The id is a number and you can't format it, as a workaround you can add new Char field and override create method to fill it then you can use the new created field in the list view.
from odoo import models, api, fields, _
class HelpdeskTicket(models.Model):
_inherit = 'helpdesk.ticket'
ticket_no = fields.Char(string="Ticket No")
#api.model_create_multi
def create(self, list_value):
tickets = super(HelpdeskTicket, self).create(list_value)
# set ticket Id
for ticket in tickets:
if ticket.id:
ticket.ticket_no= '#' + str(ticket.id)
return tickets
XML will be:
<!-- Helpdesk Addon Tree View -->
<record id="helpdesk_addon_tree_view" model="ir.ui.view">
<field name="name">view.helpdesk.addon.tree</field>
<field name="model">helpdesk.ticket</field>
<field name="inherit_id" ref="helpdesk.helpdesk_tickets_view_tree"/>
<field name="arch" type="xml">
<field name="display_name" position="before">
<field name="ticket_no" string="ID"/>
</field>
<field name="stage_id" position="after">
<field name="create_date"/>
</field>
</field>
</record>
</odoo>

Related

Odoo 10 - Extend view to include related model field

I am trying to extend the view which displays packages in Odoo 10 so it display also the product_id:
<record id="stock_view_picking_form_enhanced" model="ir.ui.view">
<field name="name">stock_view_picking_form_enhanced</field>
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock.view_picking_form"/>
<field name="priority">20</field>
<field name="arch" type="xml">
<xpath expr="//field[#name='pack_operation_product_ids']/tree/field[#name='package_id']" position="after">
<field name="package_id.product_id"/>
</xpath>
</field>
</record>
So basically I am looking to display related field product_id from pack_operation_product_id.
Which is the right approach to implement this?
First you must include the related field in your inherited python class.
class StockPicking(models.Model):
_inherit = "stock.picking"
product_id = fields.Many2one('product.product', related='package_id.product_id', string='Product', store=True)
Then in XML you can write like the following:
<record id="stock_view_picking_form_enhanced" model="ir.ui.view">
<field name="name">stock_view_picking_form_enhanced</field>
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock.view_picking_form"/>
<field name="priority">20</field>
<field name="arch" type="xml">
<xpath expr="//field[#name='pack_operation_product_ids']/tree/field[#name='package_id']" position="after">
<field name="product_id"/>
</xpath>
</field>
</record>

Odoo. How to create a view to extended model

I am very new in odoo and i really need your help.
I've extended res.partner :
class extendedPartner(models.Model):
_name = 'extended.partner'
_inherit = 'res.partner'
auto = fields.One2Many('partner.car', 'auto_name', 'Car', required=False)
class partnerCar(models.Model):
_name = 'partner.car'
auto_model = fields.Char('Model auto', size=20, required=True)
release = fields.Integer('Year of release', required=True)
auto_name = fields.Many2One('extended.partner', 'Car Name', required=True)
But I don't know how to write xml so that I could see all partner's cars and information about them
<record model="ir.ui.view" id="view_partner_form">
<field name="name">res.partner.form.inherit</field>
<field name="model">extended.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<notebook position="inside">
<page string="Cars">
<!-- what should I write here? -->
</page>
</notebook>
</field>
</record>
Could you please help me? Thank you in advance.
UPD:
Is it right solution?
<record model="ir.ui.view" id="view_partner_form">
<field name="name">res.partner.form.inherit</field>
<field name="model">extended.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<field name="auto">
<tree>
<field name="auto_name"/>
<field name="auto_model"/>
<field name="release"/>
</tree>
</field>
</field>
</record>
You are almost there, since you inherit from another view and you injecting your view into the view you inherit from, you need to give your new view a "hook" in the parent view which it can use to attach its contents. So you use an xpath expression, and then you insert your field.
When you insert a relational field you can create so called embedded views. Here you have defined a tree view for your field. That means whenever your field will be rendered as a tree that is the tree that will be used, in your case the form.
You could also create a <form> after <tree> to be shown when clicked.
<record model="ir.ui.view" id="view_partner_form">
<field name="name">res.partner.form.inherit</field>
<field name="model">extended.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<xpath expr="insert_x_path_xpression here" position="after, before etc"
<field name="auto">
<tree>
<field name="auto_name"/>
<field name="auto_model"/>
<field name="release"/>
</tree>
</field>
</xpath>
</field>
</record>

Unknown field 'state' in domain when editing attribute

Using Odoo 10 (fetched from GitHub commit 7413b26, branch 10.0), installing a module which I'm porting over from Odoo 8.
This module forces the purchase.order.line form to show up upon clicking a line in purchase.order by removing the editable attribute from the tree, but when saving changes done in that form Odoo raises:
Error: Unknown field state in domain [["state","in",["purchase","to approve","done","cancel"]]]
purchase_order_error.xml:
<record id="purchase_order_line_tree" model="ir.ui.view">
<field name="name">purchase.order.form</field>
<field name="model">purchase.order</field>
<field name="priority" eval="33"/>
<field name="type">form</field>
<field name="inherit_id" ref="purchase.purchase_order_form"/>
<field name="arch" type="xml">
<xpath expr="//notebook/page/field[#name='order_line']/tree" position="attributes">
<attribute name="editable"/>
</xpath>
</field>
</record>
The __manifest__.py is:
{'name': "purchase_order_error",'depends': ['base', 'product', 'purchase'],'data': ['purchase_order_error.xml',],'installable':True}
and __init__.py is just the usual from . import purchase_order_error.
Here are some more observations:
The field state can have the following Selection values: [draft], [sent], [to approve], [purchase], [done], [cancel]; [draft] and [sent] do not appear in the error.
An Odoo user reported same problem on the Odoo GitHub bug tracker, without any solution as the time of writing.
Is there a workaround ?
You should add
<record id="purchase_order_line_tree" model="ir.ui.view">
<field name="name">purchase.order.form</field>
<field name="model">purchase.order</field>
<field name="priority" eval="33"/>
<field name="type">form</field>
<field name="inherit_id" ref="purchase.purchase_order_form"/>
<field name="arch" type="xml">
<xpath expr="//notebook/page/field[#name='order_line']/tree" position="attributes">
<attribute name="editable">top</attribute>
</xpath>
</field>
</record>
In your case it's going to open form view to allow you to create
records, because you have not given the value of editable attribute.
So in form view of purchase order line there might be no field defined "state". According to rule if fields are used anywhere in attrs, domains then it must be defined on view, it doesn't matter you can define it invisible.
So just add this field in Purchase order line form view or follow the first solution for editable="top"
<field name="state" invisible="1" />
The problem is when saving the record from the form view
the state field is not defined. you don't get this error
in the tree view because the field is there:
<page string="Products">
<field name="order_line" attrs="{'readonly': [('state', 'in', ('done', 'cancel'))]}">
<tree string="Purchase Order Lines" editable="bottom">
<field name="currency_id" invisible="1"/>
<field name="state" invisible="1"/>
.....
....
..
so you need to add it to the embedded form too:
<record id="xxx_purchase_order_form_list_details" model="ir.ui.view">
<field name="name">xxx_purchase_order_form_list_details</field>
<field name="model">purchase.order</field>
<field name="inherit_id" ref="purchase.purchase_order_form"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='order_line']/tree" position="attributes">
<attribute name="editable"/>
</xpath>
<xpath expr="//field[#name='order_line']//form//field[#name='product_id']" position="before">
<field name="state" invisible="1"/>
</xpath>
</field>
</record>

Odoo - How can I get some field's value in purchase module to show in stock module?

How can I get some field's value in purchase module to show in stock module?
I want to show field (po_name) in purchase module in tree view of stock module.
This is my code
<record id="vpicktree_kwan" model="ir.ui.view">
<field name="name">stock.picking.tree.kwan</field>
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock.vpicktree"/>
<field name="arch" type="xml">
<field name="name" position="after">
<field name="po_name" string="PO number"/>
</field>
</field>
</record>
Could you guide me please?

Openerp 6.1 put product category in sale order line

I want to show the product category in the sale.order.line.tree view of a sales order with the following code which I wrote. It shows the category button under the group by button but on clicking it, I get the following error and I have don't know how to solve the bug:assert groupby_def and groupby_def._classic_write, "Fields in 'groupby' must be regular database-persisted fields (no function or related fields), or function fields with store=True"
AssertionError: Fields in 'groupby' must be regular database-persisted fields (no function or related fields), or function fields with store=True
Here is my code:
from osv import fields, osv<code>
class sales_order_line_category(osv.osv):
_name='sale.order.line'
_inherit='sale.order.line'
_columns={'categ_id': fields.related('product_id', 'categ_id', type='many2one', relation='product.categ_id'),
}
sales_order_line_category()
My view:
`<?xml version="1.0" encoding="utf-8"?>
<record id="view_sale_orderlinecategory" model="ir.ui.view">
<field name="name">sale.order.line.categoryinherit</field>
<field name="model">sale.order.line</field>
<field name="type">tree</field>
<field name="inherit_id" ref="sale.view_order_line_tree"/>
<field name="arch" type="xml">
<field name="name" position="after">
<field name="categ_id" string="Category"/>
</field>
</field>
</record>
<record id="view_sale_orderlinecategory2" model="ir.ui.view">
<field name="name">sale.order.line.categoryinherit2</field>
<field name="model">sale.order.line</field>
<field name="type">search</field>
<field name="inherit_id" ref="sale.view_sales_order_uninvoiced_line_filter"/>
<field name="arch" type="xml">
<group expand="0" string="Group By..." >
<filter string="Category of Product" icon="terp-stock_symbol-selection" name="Category" context="{'group_by':'categ_id'}"/>
</group>
</field>
</record>
<record id="view_sale_orderlinecategory3" model="ir.ui.view">
<field name="name">sale.order.line.categoryinherit3</field>
<field name="model">sale.order,line</field>
<field name="type">search</field>
<field name="inherit_id" ref="sale.view_sales_order_uninvoiced_line_filter"/>
<field name="arch" type="xml">
<field name="name" position="before">
<field name="categ_id" string="Category"/>
</field>
</field>
</record>
</data>
`
WOuld you please try with following code replace?
'categ_id': fields.related('product_id', 'categ_id', type='many2one', relation='product.category', store=True),
Check that your field categ_id must be appear in tree view of sale.order.line where you try to do group by categ_id
Hope this help