Technical 보관된 메일 그룹

technical@mail.odoo.com

Avatar

Re: Adding elements to a One2Many relation while the form is open

작성자
joao.jeronimo.pro@gmail.com
- 2019년 06월 06일 06시 44분 39초

Hello.

Actually I noticed that ODOO already has this feature.

The problem was that the contract should be set to "Running" state.

Joao Jerónimo


Às 11:39 de 06/06/19, Sudhir Arya escreveu:
Glad to know that it is working.

On Thu, Jun 6, 2019 at 3:11 PM João Jerónimo <joao.jeronimo.pro@gmail.com> wrote:

Hello.

So, to do this, I needed to create a record using the new() method of the relation, and then add it to the relation using the "+=" operator.

The hr.payslip.worked_days model has a pointer back to the payslip (payslip_id). But when the form is open there is no way to get the id of the payslip (also the payslip may not even be in the database, so self.id is a NewId, not an actual database id). The create() method requires payslip_id to be set when one trie to create the line, so it couldn't be used. The new() method, on the other hand, does not require so, but does not actually add the line to the payslip. To add the line, one needs to add it to the relation:

thisPayslip.worked_days_line_ids += work100_line

Thank you again. It worked.

João Jerónimo


Às 09:59 de 06/06/19, João Jerónimo escreveu:

Hello.

Thank you Sudhir. I will study that code.

Does ODOO use an engine (e.g. pyjamas) to translate python code to Javascript, so that some code is run on client-side? I didn't find any reference to pyjamas in requirements.txt.

Thanks again for the help!

João Jerónimo


Às 09:44 de 06/06/19, Sudhir Arya escreveu:
You should not use create/write/delete functions (functions which are performed on the server side) on onchange because onchange performs on the client side.
You can set the number of records to o2m field in onchange. 

There is similar functionality in the purchase module. When you select a Purchase Order in Vendor Invoice, onchange pull all the data from the purchase order and create the invoice lines (o2m).

Please check the purchase_order_change method for reference.


On Thu, Jun 6, 2019 at 1:46 PM João Jerónimo <joao.jeronimo.pro@gmail.com> wrote:
Hello,

In the Payslip application of ODOO12 I want the Worked Days list to be 
populated with a default WORK100 line when a contract is selected. So I 
created the following inherit class:

> class HrPayslip(models.Model):
>     _inherit = 'hr.payslip'
>
>     @api.onchange('contract_id')
>     def fill_in_work100(self):
>         if not self.contract_id:
>             return
>
>         # Add WORK100 entries to payslip if it does not already have them:
>         for thisPayslip in self:
>             if len(thisPayslip.worked_days_line_ids) == 0:
>                 thisPayslip.write({
>                     'worked_days_line_ids': [
>                         (0, _, {
>                             'name': "Numero de dias pagos a 100%",
>                             'code': 'WORK100',
>                             'number_of_days': 22.0, 'number_of_hours': 
> 22*8,
>                             'contract_id': thisPayslip.contract_id.id
>                         })
>                     ]
>                 })
But this doesn't work. When a change the contract in the form, ODOO says:

"Odoo Server Error - Access Error
The requested operation cannot be completed due to security 
restrictions. Please contact your system administrator.
(Document type: Pay Slip, Operation: write)"

Before this, I tried to do the same from a button in the Payslip Batch 
(hr.payslip.run) form. This one worked:

> class HrPayslipRun(models.Model):
>     _inherit = 'hr.payslip.run'
>
>     @api.multi
>     def assign_default_contracts(self):
>         for thisPayslip in self.slip_ids:
>             # Add WORK100 entries to payslip if it does not already 
> have them:
>             if self.env['hr.payslip.worked_days'].search_count([
>                             ('payslip_id', "=", thisPayslip.id),
>                             ('code', "=", 'WORK100') ]) == 0:
>                 thisPayslip.write({
>                     'worked_days_line_ids': [
>                         (0, _, {
>                             'name': "Numero de dias pagos a 100%",
>                             'code': 'WORK100',
>                             'number_of_days': 22.0, 'number_of_hours': 
> 22*8,
>                             'contract_id': thisPayslip.contract_id.id
>                         })
>                     ]
>                 })
But I want this to work even if the payslip is not in a batch. How can I 
do this?

Note: I don't want attendance data to be filled-in automatically. What I 
want is a form that fills-in default values that can be altered if needed.

Thanks.

João Jerónimo

_______________________________________________
Mailing-List: https://www.odoo.com/groups/technical-62
Post to: mailto:technical@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe



--


Sudhir Arya
Director
ERP Harbor Consulting Services
In the Top 5 Position in Odoo Community Forum
Skype: sudhir@erpharbor.com
Website:  http://www.erpharbor.com


The company accepts no liability for the content of this email, or for the consequences of any actions taken on the basis of the information provided unless that information is subsequently confirmed in writing. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited.

_______________________________________________
Mailing-List: https://www.odoo.com/groups/technical-62
Post to: mailto:technical@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe

_______________________________________________
Mailing-List: https://www.odoo.com/groups/technical-62
Post to: mailto:technical@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe



--


Sudhir Arya
Director
ERP Harbor Consulting Services
In the Top 5 Position in Odoo Community Forum
Skype: sudhir@erpharbor.com
Website:  http://www.erpharbor.com


The company accepts no liability for the content of this email, or for the consequences of any actions taken on the basis of the information provided unless that information is subsequently confirmed in writing. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited.

_______________________________________________
Mailing-List: https://www.odoo.com/groups/technical-62
Post to: mailto:technical@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe

참조