Odoo 10 - Move 1 unit to scrap location - odoo

Greetings to everyone.
I'm expanding the hr.employee class to add employee equipment. As this equipment will sooner or later need to be replaced, I want to make a button so that if a checkbox is marked, it will transfer a unit from the stock location to scrap location.
The reason is to have an updated inventory and a history of the use of these elements. I have recently started programming using the framework provided by Odoo and the truth is that I am somewhat lost.
class HrEmployeeLprl(models.Model):
_inherit = 'hr.employee'
# Botón actualizar
#api.one
#api.depends('hr', 'stock')
def action_lprl_update_inventory(self):
if self.renew_glasses:
move = self.env['stock.move'].create({
'name': '',
'location_id': self.glasses.property_stock_production.id,
'location_dest_id': self.scrap_location.id,
'product_id': self.glasses.id,
'product_uom': self.glasses.uom_id.id,
'product_uom_qty': 1
})
move._action_confirm()
move._action_assign()
move.move_line_ids.write({qty_done: 1})
move._action_done()
glasses = fields.Many2one(
comodel_name='product.product',
domain="[('categ_id', '=', 'LPRL / Gafas'), ('qty_available', '>', 0)]",
string=u'Equipo de protección visual',
help=u'Si no se muestra ningún producto compruebe que existan productos de la categoría en cuestión y que el stock sea mayor de 0'
)
renew_glasses = fields.Boolean(string="¿Renovar equipo de protección visual?")
scrap_location = fields.Many2one(
comodel_name='stock.location',
string=u'Destino del desecho',
help=u'¿En donde se almacena el desecho?'
)
It throws the following message in the log:
> /srv/http/odoo/odoo10/custom-addons/hr_lprl/models/hr_employee_lprl.py(34)action_lprl_update_inventory()
-> move._action_confirm()
And the view remains freezed.
I would appreciate advice and references where to go deeper, thanks.

Juanma Beltran Osa
As error Suggest on Odoo-10 stock.move does not have the method called
_action_confirm it is the action_confirm.
Try to check on Odoo-10 with the object that has those methods which you were trying to access and perform the operation.
Thanks

Related

Group by catid SQL result in a selectbox

I have a RSform (3.0.18) in Joommla (3.10.9) on server PHP (7.4.21).
One of the fields is a Dropdown (no multiselect) with a query SQL to get article from catid 15 OR 16. Thhe code below is given by RSForm documentation and adapted to my need.
//<code>
// Prepare the empty array
$items = array();
// Prepare the database connection
$db = JFactory::getDbo();
// Keep this if you'd like a "Please select" option, otherwise comment or remove it
$items[] = "|Sélectionnez...[c]";
// Run the SQL query and store it in $results
$db->setQuery("SELECT id, title FROM #__content WHERE catid = 15 or catid = 16");
$results = $db->loadObjectList();
// Now, we need to convert the results into a readable RSForm! Pro format.
// The Items field will accept values in this format:
// value-to-be-stored|value-to-be-shown
// Eg. m|M-sized T-shirt
foreach ($results as $result) {
$value = $result->id;
$label = $result->title;
$items[] = $value.'|'.$label;
}
// Multiple values are separated by new lines, so we need to do this now
$items = implode("\n", $items);
// Now we need to return the value to the field
return $items;
//</code>
The query works and I get a result like :
Sélectionnez...
Introduction aux médias et à la prise de parole en public
Réussir une prise de parole
Réussir une interview
Médiatraining élus
But I would like it group by catid, which could give something like :
Sélectionnez...
Enterprises formations (not selectable)
Introduction aux médias et à la prise de parole en public
Réussir une prise de parole
Réussir une interview
Administrations formations (not selectable)
Médiatraining élus
Any advice to help writing this ?
Thanks in advance...

add columns in a CDS view and fill it with a condition

I have been trying for several days, in a cds view, to convert a row of the acdoca table (here the amount of a debit/credit transaction, the hsl attribute in acdoca), into two columns debit and credit.
The amount of a transaction would go into a column depending on the type of debit/credit (attribute drcrk in acdoca which returns H for a debit or S for a credit). Is there a solution to my problem or a doc accessible to a beginner to solve this problem
(PS I don't know ABAP so if you have a solution using it is it possible to describe where and how to integrate it to Eclipse).
I tried to declare a direct attribute in the view, to alter the view, but all this does not work. I have been told about the possibility of using a functional table, which seems to work, but I can't structure it correctly just in the typing of my tables.
I can pass my view if necessary.
define view Z_test_dc as select from acdoca
inner join bseg on acdoca.rbukrs = bseg.bukrs
and bseg.belnr = acdoca.belnr
and bseg.gjahr = acdoca.gjahr
and bseg.buzei = acdoca.buzei
left outer join but000 on but000.partner = acdoca.kunnr
left outer join t003t on t003t.blart = acdoca.blart
{
key acdoca.rbukrs, //Société
key acdoca.gjahr, //Exercice comptable
key acdoca.belnr, //Numéro de pièce comptable
key acdoca.racct, //Numéro de compte
key acdoca.docln, //Ligne d'écriture à six caractères pour ledger
acdoca.kunnr, //Client
acdoca.fiscyearper, //Période/exercice
acdoca.augbl, //Nº pièce rapprochement
acdoca.bldat, //Date de la pièce
acdoca.budat, //Date comptable du document
acdoca.blart, //Type de pièce
t003t.ltext, //Description type de pièce
acdoca.hsl, //Montant en devise société
acdoca.rhcur, //Devise société
acdoca.netdt, //Date echéance nette
bseg.madat, //Data de la dernière relance
bseg.mansp, //Blocage relance
bseg.manst, //Niveau de relance
bseg.zterm, //Conditions de paiement
but000.bu_group, //le regroupement du client
bseg.valut, //Date valeur delais
bseg.sgtxt, //Texte descriptif postes
acdoca.drcrk //type debit/credit (return H ou S)
}
...
I didn't think it was possible, because I had thought that an alias as just a renamed of my column, but with the right syntax the box works fine here is the code I rendered thanks for your help.
define view VIEW as select from acdoca
inner join bseg on acdoca.rbukrs = bseg.bukrs
and bseg.belnr = acdoca.belnr
and bseg.gjahr = acdoca.gjahr
and bseg.buzei = acdoca.buzei
left outer join but000 on but000.partner = acdoca.kunnr
left outer join t003t on t003t.blart = acdoca.blart {
key acdoca.rbukrs, //Société
key acdoca.gjahr, //Exercice comptable
key acdoca.belnr, //Numéro de pièce comptable
key acdoca.racct, //Numéro de compte
key acdoca.docln, //Ligne d'écriture à six caractères pour ledger
acdoca.kunnr, //Client
acdoca.fiscyearper, //Période/exercice
acdoca.augbl, //Nº pièce rapprochement
acdoca.bldat, //Date de la pièce
acdoca.budat, //Date comptable du document
acdoca.blart, //Type de pièce
t003t.ltext, //Description type de pièce
acdoca.hsl, //Montant en devise société
acdoca.rhcur, //Devise société
acdoca.netdt, //Date echéance nette
bseg.madat, //Data de la dernière relance
bseg.mansp, //Blocage relance
bseg.manst, //Niveau de relance
bseg.zterm, //Conditions de paiement
but000.bu_group, //le regroupement du client
bseg.valut, //Date valeur delais
bseg.sgtxt, //Texte descriptif postes
acdoca.drcrk, //type debit/credit (return H ou S)
case acdoca.drcrk when 'H' then acdoca.hsl else 0 end as debit,
case acdoca.drcrk when 'S' then acdoca.hsl else 0 end as credit
}'

How to get value on one field based on two different fields

So Im creating a hotel management module . I have the option to filter rooms based on bed_type and tag. Tag contains different facilities like AC, TV etc. So an user will come and select a bed_type and the facilities he wants and in the third field it should show the rooms that have the given configuration if not available an error messages should come. SO i created a onchange function to do this , but i dint know how to include the tags in it. Im doing it on odoo v14. m
This is the model for the room
from odoo import api, fields, models, _
class HotelRoom(models.Model):
_name = 'hotel.room'
_description = 'hotel room'
_rec_name = 'room_number'
room_number = fields.Char('Room Number', required=True)
room_rent = fields.Monetary('Room Rent')
tag = fields.Many2many('hotel.tags', string='Facilities')
dormitory_count = fields.Integer('Dormitory count')
bed_type = fields.Selection([
('single', 'Single'),
('double', 'Double'),
('dormitory', 'Dormitory')
], required=True, default='other')
This is the model for the reception
class HotelAccommodation(models.Model):
_name = 'accommodation.room'
_description = 'Reception'
bed_type = fields.Selection([
('single', 'Single'),
('double', 'Double'),
('dormitory', 'Dormitory')
], required=True, string= 'Bed type')
state = fields.Selection([
('draft','Draft'),
('check-in','Check-In'),
('check-out', "Check-Out"),
('cancel','Cancel'),
], required=True, default='draft', tracking=True)
tag = fields.Many2many('hotel.tags', string='Facilities')
room_id = fields.Many2one('hotel.room', string='Room')
Using this I can filter the rooms based on the bed_type but I need to have the tags as well.I tried giving it inside the domain but its not working .
#api.onchange('bed_type')
def filter_room(self):
for rec in self:
return {'domain': {'room_id': [('bed_type', '=', rec.bed_type)]}}
You need also to add the tag field to the domain and to the onchange decorator, so the method will be called when the tag field is modified.
The method is invoked on a pseudo-record that contains the values present in the form, you do not need to loop over self.
Try the following example:
#api.onchange('bed_type', 'tag')
def filter_room(self):
return {'domain': {'room_id': [('bed_type', '=', self.bed_type), ('tag', 'in', self.tag.ids)]}}
You can use _compute fields with the store option = True
take a look https://www.odoo.com/documentation/14.0/reference/orm.html#computed-fields

Change a many2one field content in onchange from another field?

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.

Why does this HABTM relationship defined in the fixtures does not run properly in this test?

I'm using Rails 3.0.9.
I have this fixtures defined:
treatments.yml
treatment5:
id: 5
code: T2
description: "Inclusión en la política de seguridad directrices para el teletrabajo"
reduction: 0.2
document: "D01_Politica_Seguridad"
account_id: 2
soa_lines: soa_line5
soa_lines.yml
soa_line5:
account_id: 2
id: 5
justification: "El teletrabajo introduce riesgos adicionales que deben gestionarse"
control_id: 2
applicability: true
treatments: treatment5
And models have:
treatment.rb
has_and_belongs_to_many :soa_lines
soa_line.rb
has_and_belongs_to_many :treatments
But in test,
treatment = treatments(:treatment5)
treatment.soa_lines # Returns []
Why does treatment.soa_lines return []? Is the HABTM no well defined in the fixtures?
Because you can't set an id on your model if you want to use the named fixtures on HABTM:
treatment5:
code: T2
description: "Inclusión en la política de seguridad directrices para el teletrabajo"
reduction: 0.2
document: "D01_Politica_Seguridad"
account_id: 2
soa_lines: soa_line5
soa_line5:
account_id: 2
justification: "El teletrabajo introduce riesgos adicionales que deben gestionarse"
control_id: 2
applicability: true
treatments: treatment5