Odoo 16 custom module could not be installed - odoo

My Code in views:
<!--account account type form view inherit-->
<record id="view_account_type_from" model="ir.ui.view">
<field name="name">view.account.type.form</field>
<field name="model">account.account.type</field>
<field name="inherit_id" ref="account.view_account_type_form"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='include_initial_balance']" position="after">
Error on install:
odoo.tools.convert.ParseError: while
parsing....../odoo_account_type_menu/views/account_type_menu.xml:9,
somewhere inside strong text

The view account.account.type model has been removed in Odoo 16, and it's replaced with the below selection field in account.account model.
So you can inherit account.account model and override the selection field.
account_type = fields.Selection(
selection=[
("asset_receivable", "Receivable"),
("asset_cash", "Bank and Cash"),
("asset_current", "Current Assets"),
("asset_non_current", "Non-current Assets"),
("asset_prepayments", "Prepayments"),
("asset_fixed", "Fixed Assets"),
("liability_payable", "Payable"),
("liability_credit_card", "Credit Card"),
("liability_current", "Current Liabilities"),
("liability_non_current", "Non-current Liabilities"),
("equity", "Equity"),
("equity_unaffected", "Current Year Earnings"),
("income", "Income"),
("income_other", "Other Income"),
("expense", "Expenses"),
("expense_depreciation", "Depreciation"),
("expense_direct_cost", "Cost of Revenue"),
("off_balance", "Off-Balance Sheet"),
],
string="Type", tracking=True,
required=True,
compute='_compute_account_type', store=True, readonly=False, precompute=True,
help="Account Type is used for information purpose, to generate country-specific legal reports, and set the rules to close a fiscal year and generate opening entries."
)

Related

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>

Adding a field in parent view

i am having some problems when i try to add a field in the parent view.
The class is:
class VademecumFraccionamiento(models.Model):
_name = 'farmacia.vademecum_fraccionamiento'
_inherits={
'farmacia.vademecum': 'vademecum_id'
}
hijo = fields.Many2one('farmacia.vademecum_fraccionamiento', string="Artículo hijo", index=True)
vademecum_id = fields.Many2one('farmacia.vademecum', string='Artículo Padre', required=True, ondelete='cascade', index=True)
The xml is:
<record model="ir.ui.view" id="farmacia_vademecum_fraccionamiento_form_view">
<field name="name">farmacia_vademecum_fraccionamiento.form</field>
<field name="model">farmacia.vademecum</field>
<field name="inherit_id" ref="farmacia_vademecum.farmacia_vademecum_form_view"/>
<field name="arch" type="xml">
<xpath expr="//page[#string='lalala']" position="after">
<page string="Fracc">
</page>
</xpath>
<xpath expr="//page[#string='Fracc']" position="inside">
<group>
<field name="vademecum_id">
</field>
</group>
</xpath>
</field>
</record>
The error is:
Error details:
The field vademecum_id not exists
I don't know how to solve that.
Thanks in advance
You should refer addons/product/product_view.xml for more help, in which you will get all the answers of your questions related to inheritance.
I would change the code to:
_columns = {
'hijo' : fields.Many2one('farmacia.vademecum_fraccionamiento', string="Artículo hijo", index=True),
'vademecum_id' : fields.Many2one('farmacia.vademecum', string='Artículo Padre', required=True, ondelete='cascade', index=True),
}
This will add the fields to your model
There are two concepts in odoo for field inheritance.
_inherit : can be used in case you want to extend existing model.
Example: adding birth date field in res.partner model
class res_partner(models.Model):
_inherit = 'res.partner'
birth_date = fields.Date('Birthdate')
_inherits : can be used in case you want to adept module field in current model.
Example: Using customer fields in student model,
class Student(models.Model):
_name = 'stundent.student'
_inherits = {'res.partner': partner_id}
partner_id = fields.Many2one('res.partner', 'Partner')
after adding a partner_id field in your model you can use all the fields of partner in xml view of student form & tree.
Hope this helps.

Master-detail relation, variable scope, passing variables, etc in openerp

I'm writing a warehouse management module and I came to the inventory step.
I need to make an inventory every now and then for each warehouse separately and each inventory operation will be kept in the database as a master-detail relation,
ie:
one record for the basic data such as id, date, warehouse_id etc. and
this will be recorded in a table created by (inventory) object.
many records will keep the details of the operation (one record for each material) recording the material id, inventory id, balance, etc. and this will be recorded in the table (inventory_lines).
During the data entry, when the user selects a material, I need to check its current balance and display it in the balance field. In order to do this, I'll need to know the warehouse id because every warehouse shall have separate inventories.
I have many materials stored in many warehouses.
For example: I can have a quantity of 5 pens in warehouse A and 10 pens in warehouse B and 6 pens in warehouse C.
First, I select the warehouse (A or B or C) --- let's say warehouse B
Then I select the material (Pen or notebook or whatever) --- let's say Pen
Now, I want to search the database to find the balance of (Pen) in (Warehouse B)
I can write something like this:
select balance from inventory_lines where material_id=mmmmmm and warehouse_id=wwwwww
So, I need to get the material id (mmmmm) and the warehouse id (wwwww)
And that will be done with each material I choose.
The warehouse id is in the column: inventory_id in the object: inventory
'warehouse_id' : fields.many2one('makhazen.warehouse', 'Warehouse Name',required=True),
The material id is in the column: material_id of the object inventory_line as in the picture in the question
'material_id' : fields.many2one('makhazen.material' ,'Material Name'),
I faced the following problem:
I could use the (on_change) method in the form view on the material_id field and could trigger a method to search for the balance in the database but I needed the warehouse_id which I couldn't get.
The questions are:
- How are this master-detail relationship is handled in openerp? how values are passed between the master table and the details table?
- How can we extend the scope of the warehouse_id so that it can be seen from any method in the module?
- I could change the values of the fields by calling a method and returning the desired values in a dictionary, but how to do the opposite (read them)?
It's very critical matter to me.
Firstly, you don't need the warehouse_id field in the wh_inventory_line class. You can always access it trough the the parent object:
inventory_line = self.pool.get('wh.inventory.line').browse(cr, uid, line_id)
wharehouse_id = inventory_line.inventory_id.warehouse_id.id
Secondly, in your case you can just pass the warehouse_id value as parameter to your onchange method. Something like this:
<field name="material_id"
on_change="onchange_material_id(material_id, warehouse_id)"/>
or, if you follow my first advice and remove the warehouse_id from wh_inventory_line:
<field name="material_id"
on_change="onchange_material_id(material_id, parent.warehouse_id)"/>
EDIT
After testing on OpenERP 6.0 I found some errors in your code. I'm just wondering how did you manage to run it.
First, you missed a quote (\') on the warehouse_id column definition of your wh.inventory model:
_columns = {
'date': fields.datetime('Date'),
'warehouse_id': fields.many2one('wh.warehouse', 'Warehouse Name, required=True),
Second, the fields.char() field definition takes at least size parameter additionally to the supplied Field Name. Again, you missed a quote on the following line:
'notes': fields.char('Notes),
Not an error but something you should consider too - you tagged your question with the openerp-7 tag. In OpenERP v7 inheriting from osv.osv is deprecated. Inherit from osv.Model instead.
If I insist on your errors it's because the solution I proposed to you is working fine on my side. So there must be some little error somewhere that prevents your code for doing what is expected.
Here is my test code. You can try it:
wh.py
# -*- encoding: utf-8 -*-
import netsvc
import pooler
from osv import fields, osv
class wh_warehouse(osv.osv):
_name = 'wh.warehouse'
_columns = {
'name': fields.char('Name', 128),
}
wh_warehouse()
class wh_material(osv.osv):
_name = 'wh.material'
_columns = {
'name': fields.char('Name', 128),
}
wh_material()
class wh_inventory(osv.osv):
_name = 'wh.inventory'
_columns = {
'date': fields.datetime('Date'),
'warehouse_id': fields.many2one('wh.warehouse', 'Warehouse Name', required=True),
'inventory_line_ids': fields.one2many('wh.inventory.line', 'inventory_id', 'Inventory'),
'notes': fields.char('Notes', 512),
'balance_track': fields.boolean('Balance Track'),
}
wh_inventory()
class wh_inventory_line(osv.osv):
_name = 'wh.inventory.line'
_columns = {
'inventory_id': fields.many2one('wh.inventory', 'Inventory'),
'material_id': fields.many2one('wh.material', 'Material'),
'balance': fields.float('Balance'),
'previous_balance': fields.float('Previous Balance'),
'notes': fields.char('Notes', 512),
}
def onchange_material_id(self, cr, uid, ids, material_id, warehouse_id):
return = {'value': {
'notes': 'Selected material {0} and warehouse {1}'.format(material_id, warehouse_id), }
}
wh_inventory_line()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
wh_view.xml
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_wh_inventory_form" model="ir.ui.view">
<field name="name">wh.inventory.form</field>
<field name="model">wh.inventory</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Warehouse Inventory">
<field name="date"/>
<field name="warehouse_id" widget="selection"/>
<field name="notes"/>
<field name="balance_track"/>
<field colspan="4" name="inventory_line_ids" widget="one2many_list">
<tree string="Details" editable="bottom">
<field name="material_id" widget="selection"
on_change="onchange_material_id(material_id, parent.warehouse_id)"/>
<field name="balance"/>
<field name="previous_balance"/>
<field name="notes"/>
</tree>
</field>
</form>
</field>
</record>
<record id="view_wh_inventory_tree" model="ir.ui.view">
<field name="name">wh.inventory.tree</field>
<field name="model">wh.inventory</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="Warehouse Inventory">
<field name="date"/>
<field name="warehouse_id" widget="selection"/>
<field name="notes"/>
<field name="balance_track"/>
</tree>
</field>
</record>
<record id="action_wh_inventory_form" model="ir.actions.act_window">
<field name="name">Warehouse Inventory</field>
<field name="res_model">wh.inventory</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="view_wh_inventory_tree"/>
</record>
<menuitem
action="action_wh_inventory_form"
id="menu_wh_inventory_form"
parent="account.menu_finance"
/>
<!-- Sample data -->
<record id="warehouse_1" model="wh.warehouse">
<field name="name">Warehouse 1</field>
</record>
<record id="warehouse_2" model="wh.warehouse">
<field name="name">Warehouse 2</field>
</record>
<record id="warehouse_3" model="wh.warehouse">
<field name="name">Warehouse 3</field>
</record>
<record id="material_1" model="wh.material">
<field name="name">Material 1</field>
</record>
<record id="material_2" model="wh.material">
<field name="name">Material 2</field>
</record>
<record id="material_3" model="wh.material">
<field name="name">Material 3</field>
</record>
</data>
</openerp>