Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
2 Відповіді
9779 Переглядів

UPDATE: No anwer has been found, so if you see this and know whats what, please let me know

The sale module creates a button called "Sales" in the partner view which takes you to the current user's Sale Orders. If the partner is a company, this button will list all sale orders from that company's contacts (even though the company itself is not directly connected to the sale orders)

I'm trying to replicate this button for another custom field I have attatched to the partner, namely bookings. Like sale order this is a One2many field


It only works for partners that are contacts to a company, but for the company it just shows an empty list. The company is only linked to the bookings through its contacts, just like sale orders.


How is this link between a company and it's contacts sale orders (or in my case bookings) created?


What am I missing?


This is my code:


class ResPartner(models.Model):
_inherit = 'res.partner'
bookings = fields.One2many('ff.booking', 'partner')

class FFBooking(models.Model):
    _name = 'ff.booking'
partner = fields.Many2one('res.partner')

So I copy the code from the sale order module and edit it to fit my need like this:

<record id="action_res_partner_bookings" model="ir.actions.act_window">
<field name="name">Bookings</field>
<field name="res_model">ff.booking</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form,graph</field>
<field name="context">{'search_default_partner': active_id}</field>
</record>

<record id="view_partner_form_ff" model="ir.ui.view">
<field name="name">view.res.partner.form.ff</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<button name="toggle_active" position="before">
<button
class="oe_stat_button"
type="action"
name="%(action_res_partner_bookings)d"
attrs="{'invisible': [('customer', '=', False)]}"
icon="fa-book">
<field name="bookings_count" widget="statinfo"/>
</button>
</button>
</field>
</record>

Thanks a lot



Аватар
Відмінити
Найкраща відповідь


Alf Olsen, Hello...
 is there any solution for this code. if yes then plz share with me. 

Plz Tell me the use of In .py file where is bookings_count mentioned. Thank you.



 

Аватар
Відмінити
Найкраща відповідь

class ResPartner(models.Model):

    _inherit = 'res.partner'

    bookings = fields.One2many('ff.booking', 'partner_id', string='Booking')


class FfBooking(models.Model):

    _name = 'ff.booking'

    partner_id = fields.Many2one('res.partner', string='Partner')


I think you missed relation for both tables

Аватар
Відмінити
Автор

No, I have that, I just didn't find it relevant to my problem.

Автор

I put it in there now so others wont be confused

Related Posts Відповіді Переглядів Дія
2
бер. 23
2239
2
трав. 22
4210
0
бер. 22
1490
1
трав. 21
4203
1
вер. 20
3447