Enable Dark Mode!
how-is-client-action-configured-in-the-odoo-15.jpg
By: Sayanth MK

How is Client Action Configured in the Odoo 15?

Technical Odoo 15

Simple XML menu items with matching widget actions compensate client actions. On this occasion, we'll analyze how to add a menu to the order's menu in sales. Getting, displaying, and then using the sales orders from the menu.
To continue, add a menu to the views/views.xml file in the view's directory.
<record id="sale_action_demo" model="ir.actions.client">
       <field name="name">Sale Custom</field>
       <field name="tag">sale_cust</field>
       <field name="target">new</field>
</record>
   <menuitem id="menu_sale_demo"  action="sale_action_demo"
     name="Sale Custom" parent="sale.sale_order_menu"/>
I'm going to create a Sale Custom record in the ir.actions.client model (We can give any name as we want). Furthermore, when the menu was clicked, I added sale_cust in the tag box, which is the tag used in the widget to load or call the action stated in the widget. This tag will aid in loading or calling the widget's stated action (JS file).
The target field can be used to alter the view size (Client Action), execute any other action, or open as a pop-up window. I gave it to you completely new when I received it. As a result, the client action will display as a pop-up window.
odoo.define('client_act.sale_cust', function (require) {
   'use strict';
   var AbstractAction = require('web.AbstractAction');
   var core = require('web.core');
   var rpc = require('web.rpc');
   var QWeb = core.qweb;
   var SaleCustom = AbstractAction.extend({
   template: 'SaleCust',
       events: {
       },
       init: function(parent, action) {
           this._super(parent, action);
       },
       start: function() {
           var self = this;
           self.load_data();
       },
       load_data: function () {
           var self = this;
                   var self = this;
                   self._rpc({
                       model: 'sale.custom',
                       method: 'get_sale_order',
                       args: [],
                   }).then(function(datas) {
                       self.$('.table_view').html(QWeb.render('SaleTable', {
                                  report_lines : datas,
                       }));
                   });
           },
   });
   core.action_registry.add("sale_cust", SaleCustom);
   return SaleCustom;
});
To make the widget, we're extending the Abstract Action class. When this operation is executed, I have specified a template('SaleCust') that will be presented.
The data is retrieved from the Python code using the load data method from the start function, and the received value is then provided to the template ('SaleTable,' which is then added to the main Template's table view class (SaleCust).
We must now specify the qweb template as well as the python function file that the RPC will use. So, initially, I'm going to make a python file (models/filename.py).
from odoo import models, fields, api
class SaleCustom(models.Model):
   _name = 'sale.custom'
   @api.model
   def get_sale_order(self):
       ret_list = []
       req = (
                   "SELECT sale_order.name, rp.name AS customer, sale_order.amount_total, sale_order.state "
                   "FROM sale_order "
                   "Join res_partner rp ON (sale_order.partner_id=rp.id)")
       self.env.cr.execute(req)
       for rec in self.env.cr.dictfetchall():
           ret_list.append(rec)
       return ret_list
Here, I'm building a new model (sale.custom)[need to give the model security] and defining the function, which runs a basic query and appends each row to a list, which is the final list produced.
As a result, this list will be accessible over RPC, and the data will be provided to the qweb template.
Let's get started by defining the template (in static/src/xml).
<templates>
   <t t-name="SaleCust">
       <div>
           <div>
               <h3>
                   Sale Custom
               </h3>
           </div>
           <div>
               <div class="filter_view_tb"></div>
           </div>
           <br></br>
           <div>
               <div class="table_view"></div>
           </div>
       </div>
   </t>
   <t t-name="SaleTable">
       <div>
           <div class="table_main_view">
               <table cellspacing="0" width="100%">
                   <thead>
                       <tr>
                           <th>Number</th>
                           <th>Customer</th>
                           <th>Amount Total</th>
                           <th>Status</th>
                       </tr>
                   </thead>
                   <tbody>
                       <t t-foreach="report_lines" t-as="data">
                           <tr style="border: 1px solid black;">
                               <td style="border: 0px solid black;">
                                       <t t-esc="data['name']"/>
                               </td>
                               <td>
                                   <t t-esc="data['customer']"/>
                               </td>
                               <td>
                                   <t t-esc="data['amount_total']"/>
                               </td>
                               <td>
                                   <t t-esc="data['state']"/>
                               </td>
                           </tr>
                       </t>
                   </tbody>
               </table>
           </div>
       </div>
   </t>
</templates>
This is the qweb template that receives the data. This is one approach to specifying a client's action.


If you need any assistance in odoo, we are online, please chat with us.



0
Comments



Leave a comment



whatsapp
location

Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635

location

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

location

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message