UI with line items

  • Step 1:

    1. master model

    
                   from odoo import models, fields, api
    
    
                   class document_entry(models.Model):
                        _name = 'csms.document_entry'
                        _description = 'csms.document_entry'
    
                        company_id = fields.Many2one('res.company', string='Branch', required=True)
                        country_id = fields.Many2one('csms.country', string='Country', required=True)
                        customer_id = fields.Many2one('res.partner', string='Customer', required=True)
                        email = fields.Char()
                      
                      
                        document_item_ids = fields.One2many(
                            'csms.document_item',
                            'entry_id',
                            string='Documents'
                        )
    
                        
    1. note document_item_ids
    2. entry_id is relation id in the model document_item
    3. document_item_ids is One2many in master model

    2. line item model

    
    
                                        
                      from odoo import models, fields, api
    
    
                      class document_item(models.Model):
                          _name = 'csms.document_item'
                          _description = 'csms.document_item'
    
                        
                          document_name = fields.Char()
                          university = fields.Char()
                          rate = fields.Char()
                          quantity = fields.Char()
                          total = fields.Char()   
                          entry_id = fields.Many2one(
                                  'csms.document_entry'
                          )
    
                      
    entry_id is Many2one

    3. menu

    
                                  <menuitem name="csms" id="csms.menu_root"/>
    
                                  <!-- menu categories -->
    
                                  <menuitem name="Activities" id="csms.menu_1" parent="csms.menu_root"/>
                                 
                                  <!-- actions -->
    
                                  <menuitem name="Documents" id="csms.menu_1_list" parent="csms.menu_1"
                                            action="document_entry_action_window"/>
    
                          

    4. action window

    
                            <record model="ir.actions.act_window" id="document_entry_action_window">
                              <field name="name">Document Entry</field>
                              <field name="res_model">csms.document_entry</field>
                              <field name="view_mode">tree,form</field>
                            </record>
                          

    5. add permission to security

    E:\odoo\16\server\addons\csms\security\ir.model.access.csv

    
                         access_csms_document_entry,csms.document_entry,model_csms_document_entry,base.group_user,1,1,1,1
                          access_csms_document_item,csms.document_item,model_csms_document_item,base.group_user,1,1,1,1
                          
  • Step 2: Customization

    1. Master UI customization

    
                            <record id="document_entry_view_form" model="ir.ui.view">
                                  <field name="name">csms.document_entry</field>
                                  <field name="model">csms.document_entry</field>
                                  <field name="arch" type="xml">
                    <form string="Planning">
                       
                        <sheet>
                            <group>
                                <group>
                                      <field name="company_id"/>
                                    <field name="country_id"/>
                                    
                                  </group>
                                  <group>
                                      
                                      <field name="customer_id"/>
                                    
                                  </group>
                            </group>
                            <notebook>
                                <page string="Activities To Generate">
                                    <field name="document_item_ids" nolabel="1">
                                        <tree>
                                            <field name="document_name" />
                                            <field name="university"/>
                                            <field name="rate"/>
                                            <field name="quantity"/>
                                            <field name="total" />
                                           
                                        </tree>
                                    </field>
                                </page>
                            </notebook>
                        </sheet>
                    </form>
                </field>
            </record>
    
                          
    1. note sheet, group , nested group, notebook

    2. line item form

    
                        <record id="document_item_view_form" model="ir.ui.view">
                            <field name="name">csms.document_item</field>
                            <field name="model">csms.document_item</field>
                            <field name="arch" type="xml">
                                <form string="Activity">
                                  
                                    <sheet>
                                        <group>
                                            <field name="document_name"/>
                                            <field name="university"/>
                                          
                                        </group>
                                    </sheet>
                                </form>
                            </field>
                        </record>