so it's simple I get an error when adding a simple constraint (IdentationError: unexpected ident) that I added directly into postgres without problem
class fleet_site(osv.Model):
_name = 'fleet.site'
_description = 'Information du site'
_order= 'name asc'
_columns = {
'name': fields.char('Nom', help='Nom du site', required=True),
'vehicle_ids': fields.one2many('fleet.vehicle','site_id','Vehicules')
}
_sql_constraints = [('fleet_site_name_unique','unique(name)', 'Le nom du site existe')]
class fleet_site(osv.Model):
_name = 'fleet.site'
_description = 'Information du site'
_order= 'name asc'
_columns = {
'name': fields.char('Nom', help='Nom du site', required=True),
'vehicle_ids': fields.one2many('fleet.vehicle','site_id','Vehicules')
}
_sql_constraints = [('fleet_site_name_unique','unique(name)', 'Le nom du site existe')]
Python not allowed unidented code so you just need to manage equal spacing for eaxh block of code. I just removed extra spaces from your code.
Related
When adding the CSV file with multiple parent_id to the hr.profession.category model this error appears:
Exception: Module loading ptplus_hr_payroll failed: file ptplus_hr_payroll/data/hr.profession.category.csv could not be processed:
No matching record found for name 'Oficiais das Forças Armadas' in field 'Parent Category'
The data file contains the following table:
id,name,parent_id
hr_profession_category_1,Profissões das Forças Armadas,
hr_profession_category_2,Oficiais das Forças Armadas,Profissões das Forças Armadas
hr_profession_category_3,Oficial de Marinha,Oficiais das Forças Armadas
The model code for hr.profession.category looks like this:
class HrProfessionCategory(models.Model):
_name = "hr.profession.category"
_description = "Hr Profession Category"
_parent_name = "parent_id"
_parent_store = True
_rec_name = 'complete_name'
_order = 'complete_name'
name = fields.Char('Name', index=True, required=True)
complete_name = fields.Char(
'Complete Name', compute='_compute_complete_name',
store=True)
parent_id = fields.Many2one('hr.profession.category', 'Parent Category', index=True, ondelete='cascade')
parent_path = fields.Char(index=True)
child_id = fields.One2many('hr.profession.category', 'parent_id', 'Child Categories')
#api.depends('name', 'parent_id.complete_name')
def _compute_complete_name(self):
for category in self:
if category.parent_id:
category.complete_name = '%s / %s' % (category.parent_id.complete_name, category.name)
else:
category.complete_name = category.name
Can anyone help me decipher the problem?
When trying to import the CSV file, Odoo will call the name_search function using the = operator to find the DB id of the provided category name and if the following condition
not (name == '' and operator == 'ilike')
Is satisfied, Odoo will append the following search criteria to the search args:
(self._rec_name, operator, name)
Which will be evaluated to (You set the _rec_name to complete_name):
('complete_name', '=', 'Oficiais das Forças Armadas')
and because 'Oficiais das Forças Armadas' category has a parent categorty, the complete name should be:
Profissões das Forças Armadas / Oficiais das Forças Armadas
If you use this as a parent field value Odoo should import the csv file without any error.
Here is Model definition:
courier.cod.settings
from odoo import fields,models
class CodSetting(models.Model):
_name = 'courier.cod.settings'
_description = 'Code Settings'
merchant_id = fields.Many2one('res.partner', 'Merchant')
pickup_point_groups_ids = fields.Many2many('courier.pickup.point.groups', string='Pickup Point')
delivery_point_groups_ids = fields.Many2many('courier.delivery.point.groups', string='Delivery Point')
cod_charge = fields.Float('Cod Charge')
minimum_cod_charge = fields.Float('Minimum Cod Charge')
enabled = fields.Boolean(string="Active", default=True)
courier.pickup.point.groups
from odoo import fields,models
class PickupPointGroup(models.Model):
_name = 'courier.pickup.point.groups'
_description = 'Pickup Point Grouping'
title = fields.Char(string='Group Name', required=True, translate=True)
upazilla_ids = fields.Many2many('courier.upazillas','upazilla_id', string='Upazilla')
pickup_point_groups_id = fields.Many2one('courier.cod.settings', 'Cod Setting Line')
courier.delivery.point.groups
from odoo import fields,models
class DeliveryPointGroup(models.Model):
_name = 'courier.delivery.point.groups'
_description = 'Delivery Point Grouping'
title = fields.Char(string='Group Name', required=True, translate=True)
upazilla_ids = fields.Many2many('courier.upazillas','upazilla_id', string='Upazilla')
delivery_point_groups_id = fields.Many2one('courier.cod.settings', 'Cod Setting Line')
When I remove courier.delivery.point.groups everything works fine but when I add this as like courier.pickuup.point.groups I am getting https://prnt.sc/5sAnsTVCv6Ck this error. I am using odoo 15. Any idea?
I have two models:
medical.lab.test.type
This is my class:
class MedicalLabTestType(models.Model):
_name = "medical.lab.test.type"
_description = "Medical Lab Test Types"
name = fields.Char(
'Test',
help='Name of test type, such as X-Ray, Hemogram, Biopsy, etc.',
required=True,
)
code = fields.Char(
'Code',
size=128,
help='Short name or code for test type.',
required=True,
)
description = fields.Text('Description')
Test_Prix = fields.Float(
string='Price of the test',
required=True,
)
Nbr_days = fields.Integer(
string='Number of days to have results',
required=True,
)
and
medical.lab
This is my class:
class MedicalLab(models.Model):
_name = 'medical.lab'
_description = "Medical Labs"
test_type_id = fields.Many2one(
string='Test Type',
comodel_name='medical.lab.test.type',
help='Lab test type.',
)
physician_id = fields.Many2one(
string='Pathologist',
comodel_name='medical.physician',
help='Pathologist that performed the exam.',
)
request_physician_id = fields.Many2one(
string='Requesting Physician',
comodel_name='medical.physician',
help='Physician that requested the exam.',
)
The problem is to show on the view the value of Test_Prix and Nbr_days once I choose a Test
How should i proceed?, should I use an onchange function!!!
to show field of selected m2o on the current view you should use
related field.
in your midecal.lab model add:
# related field should always keep the same type Foalt Float, Char Char
# and it's recommended that you put readonly because if you edit
# the value the value will be edited in the related record when you save
Test_Prix = fields.Float(
retlated='test_type_id.Test_Prix',
readonly=True
)
Nbr_days = fields.Integer(
retlated='test_type_id.Nbr_days',
readonly=True
)
and now you can add this two field to you view like
NB: related field are not stored in database they work as proxy if you
want to create the field in the database use store=True
EDITS :
use onchange not compute field is computed
date_perform = fields.Datetime( string='Date of Results', )
#api.onchange('date_request', 'Nbr_days')
def _compute_date_result(self):
for record in self:
business_days_to_add = record.Nbr_days
current_date = fields.Datetime.from_string(record.date_request)
.....
Im trying to change the content of a many2one field when another field trigger onchange method.
Heres my py code:
class proevent(osv.osv):
_name = 'proevent.events'
_description = 'Events Module'
def onchange_client(self,cr,uid,ids, client_id,sale_orders_ids,context=None):
res={}
order_obj = self.pool.get('sale.order')
order_ids = order_obj.search(cr,uid, [('partner_id','=',client_id)])
logging.info('LIST OF SALE ORDERS OF SELECTED PARTNER')
logging.info(order_ids)
res['sale_orders_ids'] = order_ids
logging.info(res)
return {'value':res}
_columns = {
'eventdesc': fields.char('Evento', required=True),
'client_id': fields.many2one('res.partner', 'Cliente', required=True, change_default=True, select=True,track_visibility='always',domain=[('customer','=',True)]),
'sale_orders_ids': fields.many2one('sale.order','Lista'),
'eventaddress': fields.char('Direccion de Evento', required=True),
'description': fields.char('Descripcion del Evento', required=True),
'datein': fields.date('Fecha de Ingreso a Sistema', required=True, readonly=True),
'setupdatein': fields.datetime('Inicio de Montaje', required=True),
'setupdateout': fields.datetime('Fin de Montaje', required=True),
'eventdatein': fields.datetime('Inicio de Evento', required=True),
'eventdateout': fields.datetime('Fin de Evento', required=True),
'eventnotes': fields.char('Notas del Evento', required=True),
'readonlynote': fields.char('Nota'),
'partner_rtn': fields.related('partner_id','RTN',type="char",relation="res.partner",string="RTN",store=True,readonly=True),
}
proevent()
When I select a client_id which is filtered to only show customers,in triggers onchange method and then my onchange_client function.
My problem is I can't make my sale_orders_ids many2one field to show only the sale order ids from the selected partner,it show all the sale orders of the system.
How can I populate my sale_order_ids field?
def onchange_client(self,cr,uid,ids, client_id,sale_orders_ids,context=None):
res={}
order_obj = self.pool.get('sale.order')
order_ids = order_obj.search(cr,uid, [('partner_id','=',client_id)])
logging.info('LIST OF SALE ORDERS OF SELECTED PARTNER')
logging.info(order_ids)
return {'domain':{'sale_orders_ids':[('id','in',order_ids)]}}
you can do it with set domain on many2one field.
I've searched through the forums and tried all the solutions I've found, but nothing untill yet.
I've currently this:
class open_classB(osv.osv):
_name = "open.classB"
_rec_name = 'desc'
_columns = {
'desc':fields.char("Description:", size = 50, required = True),
}
open_classB()
class open_classA(osv.osv):
_name = 'open.classA'
_columns = {
'notes':fields.text('Notes:'),
'desc_id':fields.many2one('open.classB', 'Description:', 'desc'),
}
open_classA()
And instead of the dropdown show something like:
'Yellow' ; 'Blue';
It shows: 'open.classB, 1' ; 'open.classB, 2'
I already tried to put the "_rec_name" also on "open_classA", but it's the same.
And in the XML, I only put:
<field name="desc_id"/>
thanks.