How to solve IO error in odoo? - odoo

i want inherit model in odoo, and i upgrade my modul, error showing like this :
File "/usr/lib/python2.7/dist-packages/openerp/tools/misc.py", line 199, in file_open
return _fileopen(name, mode=mode, basedir=rtp, pathinfo=pathinfo, basename=basename)File "/usr/lib/python2.7/dist-packages/openerp/tools/misc.py", line 246, in _fileopen
raise IOError('File not found: %s' % basename)IOError: File not found: estate_vehicle/views/inherit_transfertomn_spb_view
this my python code :
class InheritSPB(models.Model):
_inherit ='estate.nursery.seeddo'
timesheet_ids = fields.One2many('estate.timesheet.activity.transport','owner_id','Timesheet ids')
And this my view code :
record model="ir.ui.view" id="inherit_view_field_view_timesheet_transfermn_activity">
<field name="name">Inherit timesheet SPB</field>
<field name="model">estate.nursery.seeddo</field>
<field name="inherit_id" ref="estate_nursery.view_form_seeddo"/>
<field name="arch" type="xml">
<xpath expr="//page[#name='detail_transportir'']" position="after">
<page string="Vehicle Information">
<tree>
<field name="vehicle_timesheet_ids" track_visibility="onchange" attrs="{'required': [('state','=','draft')],
'readonly': [('state','=','done')]}"
context="{'tree_view_ref' : 'estate_nursery.view_tree_timesheet_activity_transport',
'default_dc_type' : 2}"/>
</tree>
</page>
</xpath>
</field>
</record>

In your case, file should be inherit_transfertomn_spb_view.xml
You need to check your files in module estate_vehicle views folder with inherit_transfertomn_spb_view.xml file name is available or not.
Now check your __openerp__.py
For example:
"data" : [
#new of file with proper destination
views/inherit_transfertomn_spb_view.xml
]

Related

How to keep the order of the records added in a many2many field the way I wrote them?

I want to keep the order of the records in the many2many field, the way I added them using the write method, but Odoo use the alphanumerical order by default and overwrote the order I put them in. How can I keep it in the same order when I wrote them, is that possible ?
Here is the model code:
# -*- coding: utf-8 -*-
from odoo import models, fields, api
class projet_richat(models.Model):
_inherit = 'project.task'
competence_ids = fields.Many2many('competence.competence',string='Compétences')
consultants=fields.Many2many('hr.employee', string="Consultants")
def search_comp(self):
if len(self.competence_ids) != 0:
consults=self.env['hr.employee'].sudo().search([])
list=[]
for cmp in self.competence_ids:
print(cmp.competence)
for cons in consults:
print(cons.name)
for c in cons.competences:
if c.competence.competence==cmp.competence:
list.append((cons.id,c.competence.competence,c.niveau))
sorted_by_level = sorted(list, key=lambda tup: tup[2], reverse=True)
print(sorted_by_level)
for sorted_cons in sorted_by_level:
self.write({'consultants': [[4, sorted_cons[0]]]})
and here is the view code:
<odoo>
<data>
<record model="ir.ui.view" id="project_inherit_form">
<field name="name">project.inherit.form</field>
<field name="model">project.task</field>
<field name="type">form</field>
<field name="inherit_id" ref="project.view_task_form2"/>
<field name="arch" type="xml">
<field name="user_ids" position="before">
<field name="competence_ids" widget="many2many_tags"/>
</field>
<field name="parent_id" position="after">
<field name="consultants">
<tree>
<field name="name"/>
</tree>
</field>
</field>
<button name="action_assign_to_me" position="after">
<button name="search_comp" string="Test" class="btn-primary"
type="object"
/>
</button>
</field>
</record>
</data>
</odoo>
Thanks in advance.
The many2many field will use the list view to show its content, the default order is defined by the _order attribute on the related model.
You can alter the default ordering by setting the default_order parameter on the tree tag
From the List view documentation:
default_orderoverrides the ordering of the view, replacing the model’s order (_order model attribute). The value is a comma-separated list of fields, postfixed by desc to sort in reverse order:
<tree default_order="sequence,name desc">
To keep the order you want, you can add an integer field sequence and use it to order records (_order='sequence') then in search_comp function set the sequence field value for each line

Create custom excel report from wizard in odoo 15

I am trying to generate an excel report from wizard using report_xlsx module but i am getting below error.
Traceback (most recent call last):
File "/home/kabeer/Projects/Odoo15ce/odoo/custom_addons/report_xlsx/controllers/main.py", line 76, in report_download
response = self.report_routes(
File "/home/kabeer/Projects/Odoo15ce/odoo/http.py", line 535, in response_wrap
response = f(*args, **kw)
File "/home/kabeer/Projects/Odoo15ce/odoo/custom_addons/report_xlsx/controllers/main.py", line 32, in report_routes
data.update(json.loads(data.pop("options")))
ValueError: dictionary update sequence element #0 has length 10; 2 is required
Here is what i did.
*.xml
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="open_purchase_order_print_menu" model="ir.actions.report">
<field name="name">Open PO</field>
<field name="model">open.po</field>
<field name="report_type">xlsx</field>
<field name="report_name">transight.open_po</field>
<field name="report_file">transight.open_po</field>
<field name="print_report_name">'Purchase Order'</field>
<!-- <field name="binding_model_id" ref="purchase.model_purchase_order"/> -->
<field name="binding_type">report</field>
</record>
<record id="open_po_view_form" model="ir.ui.view">
<field name="name">open.po.form</field>
<field name="model">open.po</field>
<field name="arch" type="xml">
<form string="Open PO">
<group>
<field name="mode" required="1"/>
</group>
<group col="4">
<field name="purchase_order_id"
widget="many2many_tags"
attrs="{'invisible':[('mode','=','partnumber')]}"/>
<field name="partnumber" attrs="{'invisible':[('mode','=','po')]}"/>
</group>
<footer>
<button string="Print" name="action_print" type="object" class="btn-primary"/>
<button string="Cancel" class="btn-secondary" special="cancel"/>
</footer>
</form>
</field>
</record>
<record id="action_open_po" model="ir.actions.act_window">
<field name="name">Open PO</field>
<field name="res_model">open.po</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
<menuitem id="menu_open_po_action" name="Open PO" parent="mrp.menu_mrp_configuration" action="action_open_po" sequence="4"/>
</odoo>
*.py
from odoo import fields,models,api,_
class OpenPOXlsx(models.AbstractModel):
_name = 'report.transight.open_po'
_inherit = 'report.report_xlsx.abstract'
def generate_xlsx_report(self, workbook, data, partners):
print('data',data)
for obj in partners:
report_name = 'Excel Report test'
# One sheet by partner
sheet = workbook.add_worksheet(report_name[:31])
bold = workbook.add_format({'bold': True})
sheet.write(0, 0, 'Hi Am here', bold)
class OpenPO(models.TransientModel):
_name = 'open.po'
_description = 'OpenPO'
purchase_order_id = fields.Many2many('purchase.order',string='Purchase Order')
partnumber = fields.Char(string="Partnumber")
mode = fields.Selection([('partnumber','Part Number'),('po','Purchase Order')],string="Filter by")
def action_print(self):
if self.mode == 'po':
query = """my query %s """
self.env.cr.execute(query,(tuple(self.purchase_order_id.ids),))
datas = self.env.cr.dictfetchall()
print('data---------',datas)
# return self.env.ref('account_batch_payment.action_print_batch_payment').report_action(self, config=False)
return self.env.ref('transight.open_purchase_order_print_menu').report_action(self,data=datas)
The dictfetchall() method returns a list of dicts and report_action is expecting data (datas) to be a dict.
In previous Odoo versions, we pass record data using form key, for example:
datas = {
'ids': active_ids,
'model': 'hr.contribution.register',
'form': self.read()[0]
}
To fix this issue, add the fetched values to datas:
values = self.env.cr.dictfetchall()
datas['values'] = values
Then use values key in generate_xlsx_report method
Make sure that datas is a dictionary before calling report_action

Adding a field to sale order lines in sale orders

I want to add a computed field "markup" to sale order lines in sale orders (quotes/sales orders).
I have created the model:
class SaleOrderLine(models.Model):
_inherit = "sale.order.line"
markup = fields.Float(compute='_compute_markup', digits=dp.get_precision('.2f%'), store=True)
def _compute_markup(self, order_id, product_id, product_uom_id):
frm_cur = self.env.user.company_id.currency_id
to_cur = order_id.pricelist_id.currency_id
purchase_price = product_id.standard_price
if product_uom_id != product_id.uom_id:
purchase_price = product_id.uom_id._compute_price(purchase_price, product_uom_id)
ctx = self.env.context.copy()
ctx['date'] = order_id.date_order
price = frm_cur.with_context(ctx).compute(purchase_price, to_cur, round=False)
return price
And a new view which inherits sale.view_order_form:
<?xml version="1.0"?>
<odoo>
<record id="view_order_form_margin" model="ir.ui.view">
<field name="name">sale.order.form.margin</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr='//field[#name="order_line"]/form/group/group/field[#name="price_unit"]' position="before">
<field name="markup"/>
</xpath>
</field>
</record>
</odoo>
But the field is not shown (the view appears when you check views that inherit current view). I have reloaded everything, restarted the server and cleared the browser cache.
Any tip on why the field is not being shown is welcomed. Maybe the Xpath expression?
Thanks.
may be in sale.order view price_unit getting 2 times so it's confusion where to add and sale order view consist as formview and tree view for the sale orderline.here is the code you can get in view.
formview:
<xpath expr="//notebook//page//field//form//field[#name='price_unit']" position="before">
<field name="markup"/>
</xpath>
in Tree View:
<xpath expr="//notebook//page//field//tree//field[#name='price_unit']" position="before">
<field name="markup"/>
</xpath>

Odoo. Tree/form display field data

I have some problem with tree/form view in Odoo.
My model have such classes: https://yadi.sk/d/sCLVo3gHtbVEu
class URLList(models.Model):
_name = 'webvisitorcalc.url_list'
url = fields.Char(string="URL", required=True)
url_parametes = fields.Char(string="URL parameters") #пераметры URLб всё что идёт после ?
target_session_id = fields.One2many('webvisitorcalc.session_visitor', 'target_url_ids', string='Target URL')
site_trip_prevouse_id = fields.One2many('webvisitorcalc.site_trip', 'url_prevouse_ids', string='Prevouse URL')
site_trip_current_id = fields.One2many('webvisitorcalc.site_trip', 'url_current_ids', string='Current URL')
remote_sites_id = fields.One2many('webvisitorcalc.remote_sites', 'site_url_ids', string='Remote site page with URL')
remote_sites_target_url_id = fields.One2many('webvisitorcalc.remote_sites', 'target_url_ids', string='URL on remote site page')
#api.multi
def url_exist(self, cr, SUPERUSER_ID, urlForCheck):
_logger.error("Check URL exist in DB ")
result = False
if (self.search_count(cr, SUPERUSER_ID, [('url', '=', urlForCheck)])>0):
result = True
return result
class SiteTrip(models.Model):
_name = 'webvisitorcalc.site_trip'
session_ids = fields.Many2one('webvisitorcalc.session_visitor', string='Session ID', index=True)
url_prevouse_ids = fields.Many2one('webvisitorcalc.url_list', string='Prevouse URL', index=True)
url_current_ids = fields.Many2one('webvisitorcalc.url_list', string='Current URL', index=True)
Template for this model: https://yadi.sk/d/Ob0o65PutbVFA
<record model="ir.actions.act_window" id="site_trip_list_action">
<field name="name">Site trip</field>
<field name="res_model">webvisitorcalc.site_trip</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">Create the first record for site trip
</p>
</field>
</record>
<record model="ir.actions.act_window" id="url_list_list_action">
<field name="name">URL list</field>
<field name="res_model">webvisitorcalc.url_list</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">Create the first url
</p>
</field>
</record>
<record model="ir.ui.view" id="site_trip_tree_view">
<field name="name">site_trip.tree</field>
<field name="model">webvisitorcalc.site_trip</field>
<field name="arch" type="xml">
<tree string="URL list tree">
<field name="session_ids"/>
<field name="url_prevouse_ids" string="PrevURL">
</field>
<!--<field name="url_prevouse_ids"/>-->
<field name="url_current_ids"/>
</tree>
</field>
</record>
<record model="ir.ui.view" id="url_list_tree_view">
<field name="name">url_list.tree</field>
<field name="model">webvisitorcalc.url_list</field>
<field name="arch" type="xml">
<tree string="URL list tree">
<field name="url"/>
<field name="url_parametes"/>
</tree>
</field>
</record>
<menuitem id="site_trip_menu" name="Site trip" parent="webvisitorcalc_menu"
action="site_trip_list_action"/>
<menuitem id="url_list_menu" name="URL list" parent="webvisitorcalc_menu"
action="url_list_list_action"/>
Screenshots are here:
Tree view for class SiteTrip
http://i.stack.imgur.com/FjRDK.png
Form view for class SiteTrip
http://i.stack.imgur.com/uDbOp.png
Tree view for class URLList
http://i.stack.imgur.com/tXzqL.png
Form view for class URLList
http://i.stack.imgur.com/oVnqg.png
As you see URLList displayed fine. For class SiteTrip present problem. Field is displaying not data from URLList. This is field stored element such webvisitorcalc.url_list.ID (array?). How I can display real data in this field (for example URL: http://some-site.com/page.html)?
URL in URLList must be uniq. SiteTrip must have stored only ID of URLList record.
UPD:
class RemoteSites(models.Model):
_name = 'webvisitorcalc.remote_sites'
site_id = advert_company_id = fields.One2many('webvisitorcalc.site_list', 'remote_sites_ids', string='Site')
site_url_ids = fields.Many2one('webvisitorcalc.url_list', string='URL page ')
target_url_ids = fields.Many2one('webvisitorcalc.url_list', string='URL target page')
You obviously have no name field on your webvisitorcalc.url_list model. Odoo needs this to use it as name in webclient wherever you use this model as e.g. many2one field or in the breadcrumb navigation.
So either you define a name field or you set _name on your class with another field identifier.
You can also (re-)define the method display_name on your model (enough examples in Odoo code) where you can do more cool stuff with the record display name :-)

How to update automatically other fields when quantity on hand get increase or decrease odoo?

I need to update automatically this field(qty_available_onhand) either when quantity on hand get increase or decrease below i have mentioned my code.
Current below code working perfectly but only when i fill this field(squ_meter) as i'm entering in this field get multiplied to field(qty_avl) which is qty_avl is nothing but it is actually quantity on hand.
Any answer would be much appreciated
class product_template(osv.osv):
_name = "product.template"
_inherit = "product.template"
_columns = {
'squ_meter':fields.float('Square Meter'),
'qty_available_onhand': fields.float(
'Qty Sqm Available',
compute='_compute_qty_available_onhand',
require = True
),
'qty_avl':fields.related(
'virtual_available',
relation='product.product',
string='Quantity on Hand'
),
}
#api.depends('qty_avl', 'squ_meter')
def _compute_qty_available_onhand(self):
for record in self:
record.qty_available_onhand = record.qty_avl * record.squ_meter
view.xml
<field name="name">product.product.inherited</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view"/>
<field name="type">form</field>
<field name="arch" type="xml">
<xpath expr="//field[#name='active']" position="after">
<field name="qty_available_onhand"/>
<field name="qty_avl" invisible='1'/>
<field name="squ_meter"/>
</xpath>