Here's the code of a custom model i made, the first class is a model of stocks and general information. The second class contains the daily prices of each of the stocks in the first class for 10 days. The relational field that connects the two is the name of the stock.
I've done a lot of research in order to import the models but i seem to not be able to make it work, any help would be massively appreciated.
class ticker_info(models.Model):
_name = 'ticker.rep'
_description = 'Repository of stocks'
name = fields.Many2one('ticker.db', string = 'Tickers')
Sector = fields.Char()
Symbol = fields.Char()
class ticker_prices(models.Model):
_name = 'ticker.db'
_description = 'Database of historical data'
name = fields.Char(string = 'Tickers')
Date = fields.Datetime()
Close = fields.Float(digits=(9, 5))
Edit: For each stock in class 1 it needs to be connected to model 2 where i can see 10 daily prices of that stock.
for one2many field you've to create a cyclic relation for example:
from odoo import models, fields, api
class ticker_info(models.Model):
_name = 'ticker.rep'
_description = 'Repository of stocks'
field_o2m_ids = fields.One2many('ticker.db', 'ticker_rep_id', string="Name of field")
class ticker_prices(models.Model):
_name = 'ticker.db'
_description = 'Database of historical data'
ticker_rep_id = fields.Many2one('ticker.rep', string="Name of field")
Related
I have model structure as
class VendorEvaluationTemplate(models.Model):
_name = 'vendor.evaluation.template'
_description = 'Vendor Evaluation Template'
name = fields.Char(string='Name', required=True)
evaluation_lines = fields.One2many('vendor.evaluation.template.line', 'evaluation_template_id', string='Vendor Evaluation Template Line')
class VendorEvaluationTemplateLine(models.Model):
_name = 'vendor.evaluation.template.line'
_description = 'Details Vendor Evaluation Template'
evaluation_template_id = fields.Many2one('vendor.evaluation.template', string='Evaluation Template', ondelete="cascade")
name = fields.Char(string='Name', required=True)
class VendorEvaluation(models.Model):
_inherit = 'vendor.evaluation'
evaluation_template = fields.Many2one('vendor.evaluation.template', string='Evaluation Template')
Now the requirement is when i select evaluation_template, the related lines name from vendor.evaluation.template.line should display below this field.
Following code will work if you only want to display related lines for information purposes. Ref related fields
evaluation_template_lines = fields.One2many(
related='evaluation_template.evaluation_lines',
string="Vendor Evaluation Template Line"
)
I want to create a record on inventory with quantity = 0 whenever I add a new record to products. Is it possible?
I have 2 modules like so :
class productss(models.Model):
_name = 'productss.productss'
name = fields.Char()
description = fields.Text()
price =fields.Float()
class inventory(models.Model):
_name = 'inventory.inventory'
id_product = fields.Many2one(comodel_name='productss.productss')
qte = fields.Integer(compute="_value_qte", store=True)
Yes, it is possible. Just override productss.productss's create() and create an inventory record within:
#api.model
def create(self, values)
record = super().create(values)
# create an inventory
inv_values = {'id_product': record.id, 'qte': 0}
self.env['inventory.inventory'].create(inv_values)
return record
This code requires the "new" Odoo API (V8+) and Python3
Put fields of an employee in accounting through a module
Hi. I am creating a module for a client that has a specific need. He wants us to add a price per hour to employees. That is, the price charged by the employee each hour of work. Then create a small expense report that goes into accounting.
The first thing I have done is to modify the employee module using _inherit to add two fields. Nickname that allows employees to filter by nickname. And the hourly price of that employee (what this employee charges for every hour).
employee example changes
The second has been to create a new model that allows adding employees and importing said data. In addition to adding a description.
form example
The challenge now is to link this information to the accounting module so that it will appreciate as a Journal Item and then have the copy confirmed to be appreciated as a Journal Entries.
I am really new in the development of odoo and there are many things that I am still assimilating. So the questions I have are the following:
How could I do this?
Do I have a problem with what I have done so far?
It is my first post and I would appreciate the help. Thanks in advance.
This its the code:
class EmpleadoObra(models.Model):
_inherit = 'hr.employee'
apodo = fields.Char('apodo', readonly=False, store=True)
precio_por_hora = fields.Float('Salario por hora', store=True)
#api.model
def name_search(self, name='', args=None, operator='ilike', limit=100):
args = args or []
recs = self.browse()
if name:
recs = self.search(['|', ('apodo', 'ilike', name), ('name', operator, name) ] + args, limit=limit)
return recs.name_get()
class EmpleadosProductos(models.Model):
_name = "employee.as.product"
# _inherits = {'hr.employee' : 'empleado_id'}
employee_line = fields.One2many(
'employee.line',
'id',
string='Employee Lines'
)
class EmployeLine(models.Model):
_name = 'employee.line'
descripcion = fields.Text(string='DescripciĆ³n', required=False)
employee_id = fields.Many2one(
'hr.employee',
string="Empleado",
requiered=True,
change_default=True
)
apodo = fields.Char('apodo', readonly=False)
precio_por_hora = fields.Float('precio_por_hora')
_rec_name = 'apodo'
#api.onchange('employee_id')
def onchange_employee_id(self):
addr = {}
if not self.employee_id.display_name:
return addr
if not self.employee_id.apodo:
self.apodo = "no apodo"
else:
self.apodo = self.employee_id.apodo
self.precio_por_hora = self.employee_id.precio_por_hora
return addr
I am working on this Odoo assignment. I have to make a custom module in which the requirement is like this.
There is a form say "Notebook" it contains a field that comes from 'hr.employee' i.e. Many2one. Next thing this form will contain is a table which 3 columns (Quality, Score, Comment). Now Qualities must be a master table which contains many qualities name.
I have achieved this task in the way SalesOrder form works i.e. for a particular sales order there are multiple sales lines.
But I want all the qualities to be there on form with default score value of 0.
Here is the code
Please tell me the resolution
class qualities_fields(models.Model):
_name = "ayda.qualities.fields"
_description = "Contains only Attributes"
#api.multi
def name_get(self):
data = []
for rows in self:
value = ''
value += rows.quality_name
data.append((rows.id, value))
return data
quality_name = fields.Char(string="Quality Name")
class qualities_data(models.Model):
_name = "qualities.data"
_description = "All points mandatory to be filled"
quality_id = fields.Many2one('notebook', string="Quality IDs")
quality_name = fields.Many2one('qualities.fields', string="Quality Name")
score = fields.Integer(string="Score")
comment = fields.Char(string="Comment")
class notebook(models.Model):
_name = "notebook"
_description = "Checking one2many of qualities"
def createRecords(self):
cr = self.pool.cursor()
quantity_fields = self.pool.get('qualities.fields').search(cr, self.env.uid, [])
quantity_lines = []
for field in quantity_fields:
quality_data = {
'quality_id' : self.id,
'quality_name' : field.id,
'score' : 0,
'comment' : ''
}
quantity_lines.append(quality_data)
return quantity_lines
name = fields.Many2one('hr.employee', string="Name")
qualities_line = fields.One2many('qualities.data', 'quality_id', string="Qualities Line", default=createRecords)
There's an easier way to do this, on the field definition just set the default score to 0
score = fields.Integer(string="Score", default=0)
That way all scores would be zero when they're created
I have fields for a quick access of the entities related to a project. For example:
class project(models.Model):
_name = "project.project"
_description = "Project"
_inherit = 'project.project'
production_order_ids = fields.One2many('mrp.production', 'project_id', 'Production orders')
purchase_order_ids = fields.One2many('purchase.order', 'project_id', 'Purchase orders')
....
I am trying to create a sale_order_ids in the project.project model. My first try did not work:
sale_order_ids = fields.One2many('sale.order', 'project_id', string='Sale orders')
because because the field sale.order.project_id is of type account.analytic.account.
A project.project object inherits from account.analytic.account. This query should work ok if they would share the same Id, but they do not. So the navigation would be:
"project.project".analytic_account_id" -> sale.order".project_id
And the result would be the corresponding sale.order(s).
Use a computed field:
sale_order_ids = fields.One2many('sale.order', compute='_get_sale_orders', string='Sale orders')
#api.model
def _get_sale_orders(self):
for record in self:
record.sale_order_ids = self.env['sale.order'].search([('project_id', '=', record.analytic_account_id.id)]).ids