Skip to Content
Menu
This question has been flagged

Hi,

I am new to Odoo. I have customized "Asset" in "accounting" i have added 3 columns "asset_assign_to", "employee_id", "department_id" Now i am customizing report I wanted to add these 3 columns in it what I have done so far is extended "AssetAssetReport" and created column in "asset_asset_report" view:

class AssetAssetReport(models.Model):

    _inherit = "asset.asset.report"

    employee_id = fields.Many2one('account.asset.asset', string='Employee Name', track_visibility='onchange')

    department_id = fields.Many2one('account.asset.asset', string='Department Name', track_visibility='onchange')

    asset_assign_to = fields.Selection(

        [('department', 'Department'), ('employee', 'Employee'), ('other', 'Other')],

        string='Used By',

        required=True,

        default='employee')

Then inherited init method and modified it to display my custom columns too:

@api.model_cr

    def init(self):

        rec = super(AssetAssetReport, self).init()

        tools.drop_view_if_exists(self._cr, 'asset_asset_report')

        self._cr.execute("""

                    create or replace view asset_asset_report as (

                        select

                            min(dl.id) as id,

                            dl.name as name,

                            dl.depreciation_date as depreciation_date,

                            a.date as date,

                            (CASE WHEN dlmin.id = min(dl.id)

                              THEN a.value

                              ELSE 0

                              END) as gross_value,

                            dl.amount as depreciation_value,

                            dl.amount as installment_value,

                            (CASE WHEN dl.move_check

                              THEN dl.amount

                              ELSE 0

                              END) as posted_value,

                            (CASE WHEN NOT dl.move_check

                              THEN dl.amount

                              ELSE 0

                              END) as unposted_value,

                            dl.asset_id as asset_id,

                            dl.move_check as move_check,

                            a.category_id as asset_category_id,

                            a.partner_id as partner_id,

                            a.asset_assign_to as asset_assign_to,

                            a.employee_id as employee_id,

                            a.department_id as department_id,

                            a.state as state,

                            count(dl.*) as installment_nbr,

                            count(dl.*) as depreciation_nbr,

                            a.company_id as company_id

                        from account_asset_depreciation_line dl

                            left join account_asset_asset a on (dl.asset_id=a.id)

                            left join (select min(d.id) as id,ac.id as ac_id from account_asset_depreciation_line as d inner join account_asset_asset as ac ON (ac.id=d.asset_id) group by ac_id) as dlmin on dlmin.ac_id=a.id

                        group by

                            dl.amount,dl.asset_id,dl.depreciation_date,dl.name,

                            a.date, dl.move_check, a.state, a.category_id, a.partner_id, a.company_id,

                            a.value, a.id, a.salvage_value, dlmin.id

                )""")

        return rec

AssetAssetReport()

and here is the extended view:

<record model="ir.ui.view" id="action_account_asset_report_pivot">

<field name="name">asset.asset.report.pivot</field>

<field name="model">asset.asset.report</field>

    <field name="inherit_id" ref="account_asset.action_account_asset_report_pivot"/>

<field name="arch" type="xml">

    <xpath expr="//field[@name='unposted_value']" position="after">

      <field name="employee_id" type="measure"/>

    </xpath>

</field>

</record>

my custom columns are not showing data while there is data in the report view

I have separately executed query it is showing correct columns and data please guide me what i am doing wrong..

I also wanted to ask how can add something in measure list but not hardcore it in view :

I want it like "# of Installment Lines" ,"Amount of Installment Lines "

Avatar
Discard
Related Posts Replies Views Activity
2
Feb 24
2639
1
Oct 23
2188
1
Feb 24
581
1
Mar 15
3547
5
Feb 24
7339