<?xml version="1.0" encoding="UTF-8"?>
<odoo>
    <!-- Show B1 link fields on the employee form (HR Settings tab) -->
    <record id="view_hr_employee_form_sapb1" model="ir.ui.view">
        <field name="name">hr.employee.form.sapb1</field>
        <field name="model">hr.employee</field>
        <field name="inherit_id" ref="hr.view_employee_form"/>
        <field name="arch" type="xml">
            <xpath expr="//sheet" position="before">
                <header>
                    <button name="action_push_to_b1" type="object"
                            string="Push to SAP B1" class="btn-primary"
                            groups="hr.group_hr_user"/>
                </header>
            </xpath>
            <xpath expr="//notebook" position="inside">
                <page string="SAP B1" name="sapb1">
                    <group>
                        <group string="Link">
                            <field name="b1_employee_id"/>
                            <field name="b1_synced"/>
                        </group>
                        <group string="Payroll / Bank (from B1)">
                            <field name="b1_start_date"/>
                            <field name="b1_salary"/>
                            <field name="b1_bank_account"/>
                        </group>
                    </group>
                </page>
            </xpath>
        </field>
    </record>

    <!-- Server action: import all employees from B1, available in list Actions -->
    <record id="action_server_import_from_b1" model="ir.actions.server">
        <field name="name">Import from SAP B1</field>
        <field name="model_id" ref="hr.model_hr_employee"/>
        <field name="binding_model_id" ref="hr.model_hr_employee"/>
        <field name="binding_view_types">list</field>
        <field name="state">code</field>
        <field name="group_ids" eval="[(4, ref('hr.group_hr_user'))]"/>
        <field name="code">
result = model.action_import_from_b1()
action = {
    'type': 'ir.actions.client',
    'tag': 'display_notification',
    'params': {
        'title': 'SAP B1 Import',
        'message': 'Imported %(total)s employees (%(created)s new, %(updated)s updated).' % result,
        'type': 'success',
        'sticky': False,
    },
}
        </field>
    </record>

    <!-- Server action: explicit bulk push (the only path that pushes
         everyone; see action_push_all_to_b1 for why). -->
    <record id="action_server_push_all_to_b1" model="ir.actions.server">
        <field name="name">Push all employees to SAP B1</field>
        <field name="model_id" ref="hr.model_hr_employee"/>
        <field name="binding_model_id" ref="hr.model_hr_employee"/>
        <field name="binding_view_types">list</field>
        <field name="state">code</field>
        <field name="group_ids" eval="[(4, ref('hr.group_hr_user'))]"/>
        <field name="code">
pushed = model.action_push_all_to_b1()
action = {
    'type': 'ir.actions.client',
    'tag': 'display_notification',
    'params': {
        'title': 'SAP B1 Push',
        'message': 'Pushed %s employees to SAP B1.' % pushed,
        'type': 'success',
        'sticky': False,
    },
}
        </field>
    </record>
</odoo>
