Hello, I want to inherit the hr.expense and change the existing fields.
for example, I want the tax_ids field (Many2many) to be limited to 1. The user can only select one tax type.
Also, how can I set the default account for the expense. I want to set a particular account for expenses that I have created in the chart of accounts to be the default one for my model
Please help me on this
Thank you
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Kirjanpito
- Varastointi
- PoS
- Project
- MRP
Tämä kysymys on merkitty
Hi
You can use api.constrains decorator, it will help to limit the tax to 1
check the following code
class HrExpense(models.Model):
_inherit ='hr.expense'
@api.constrains('tax_ids')
def _check_tax_ids_lines(self):
for record in self:
if len(record.tax_ids) > 1:
raise ValidationError('You can have only one tax.')
Regards
Thank you!
Hi,
To assign a default expense account, add a default attribute to the corresponding field, and add constraints for tax fields to prevent adding more than one tax to form.
class HrExpense(models.Model):
_inherit ='hr.expense'
def _default_account_id(self):
return self.env['account.account'].search([
('account_type', 'not in', ('asset_receivable', 'liability_payable', 'asset_cash', 'liability_credit_card')),
('company_id', '=', company_id)], limit=1).id
account_id = fields.Many2one( 'account.account', compute='_compute_account_id',store=True,
readonly=False, precompute=True, string='Account', default=_default_account_id,
domain="[('account_type', 'not in', ('asset_receivable',
'liability_payable', 'asset_cash', 'liability_credit_card')),
('company_id', '=', company_id)]", help="An expense account is
expected" )
@api.constrains('tax_ids')
def _check_tax_ids(self):
for record in self:
if len(record.tax_ids) > 1:
raise ValidationError('You can add only one tax.')
Hope it helps,
Nautitko keskustelusta? Älä vain lue, vaan osallistu!
Luo tili jo tänään nauttiaksesi yksinoikeusominaisuuksista ja osallistuaksesi mahtavaan yhteisöömme!
RekisteröidyAiheeseen liittyviä artikkeleita | Vastaukset | Näkymät | Toimenpide | |
---|---|---|---|---|
|
2
heinäk. 24
|
1583 | ||
|
2
tammik. 21
|
5967 | ||
|
1
heinäk. 19
|
6578 | ||
many2many default disappear
Ratkaistu
|
|
3
kesäk. 15
|
5619 | |
|
0
helmik. 21
|
3847 |