Skip to Content
Menú
This question has been flagged
2 Respostes
4181 Vistes

I have created a custom sale settings under sale.config.settings, to select a journal when the custom field show_separate_invoice is checked. The fields are visible in the UI, but when I choose a value for the is show_separate_invoice, and click on apply, the fields again become blank. What else am I missing?

.py

class CustomSettings(models.TransientModel):
 _inherit = 'sale.config.settings'
 show_separate_invoice = fields.Boolean('separate_invoice', help='Show separate invoice based on product type', default=False store=True)
 journal_to_invoice = fields.Many2one('account.journal', string='journal', store=True)

.xml

<record id="custom_invoice_settings" model="ir.ui.view">
 <field name="name">sale.settings.inherited</field>
 <field name="model">sale.config.settings</field>
 <field name="inherit_id" ref="sales_team.view_sale_config_settings"/>
 <field name="arch" type="xml">
  <xpath expr="//div[@id='main']" position="inside">
  <group string="Invoicing">
  <field name="show_separate_invoice"/>
  <field name="journal_to_invoice" domain="[('type', '=', 'sale')]" attrs="{'invisible':[('show_separate_invoice','=',False)],'required':[('show_separate_invoice','=',True)]}"/>
 </group>
</xpath>
 </field>
</record>



Avatar
Descartar
Best Answer

Hi Tony,

in your case,


@api.model

def get_default_show_separate_invoice(self, fields):

IrConfigParam = self.env['ir.config_parameter']

return {

'show_separate_invoice': safe_eval(IrConfigParam.get_param('your_custom_module_name.show_separate_invoice', 'False')),

}


@api.multi

def set_default_show_separate_invoice(self):

self.ensure_one()

IrConfigParam = self.env['ir.config_parameter']

IrConfigParam.set_param('your_custom_module_name.show_separate_invoice', repr(self.show_separate_invoice))

Avatar
Descartar
Autor

thanks for your reply. I added code to show the journal_to_invoice field also, which would otherwise not work.

@api.multi

def set_default_journal_to_invoice(self):

return self.env['ir.values'].sudo().set_default('sale.config.settings', 'journal_to_invoice', self.journal_to_invoice.id)

Hello,

your above code is proper as per standard Odoo Addons, so you can try after upgrade your custom module, and set again value in "journal_to_invoice" field and check.

Thanks

Best Answer

Hi,

You have to add two more functions for it, see sample code

 @api.multi
    def set_params(self):
        self.ensure_one()

        for field_name, key_name in PARAMS:
            value = getattr(self, field_name, '').strip()
            self.env['ir.config_parameter'].set_param(key_name, value)
def get_default_params(self, cr, uid, fields, context=None):
        res = {}
        for field_name, key_name in PARAMS:
            res[field_name] = self.env['ir.config_parameter'].get_param(key_name, '').strip()
        return res

See this link : http://odoo-development.readthedocs.io/en/latest/dev/py/res.config.settings.html

Thanks

Avatar
Descartar
Related Posts Respostes Vistes Activitat
0
de gen. 17
4599
2
de març 24
10840
2
d’abr. 23
3803
0
de nov. 20
2379
4
d’ag. 20
5093