Repository navigation
Conversation
|
Hi @appstogrow, |
… company `hr.salary.rule.account_debit` and `account_credit` are company-dependent fields, but `action_payslip_done` read them off the bare recordset, i.e. in `self.env.company`. Confirming a payslip while working in another company therefore silently produced an entry with the wrong accounts -- or, when the rule has no value configured for that company, no accounting entry at all and no error. Every read of the rule's accounting configuration now goes through `with_company(<the payslip's company>)`, and the generated `account.move` carries that company explicitly instead of inheriting it from the environment. Also tightened around the same problem: * `hr.contract.journal_id` and `hr.payslip.run.journal_id` get `check_company` and a company domain, and the batch's default journal is looked up in the active company instead of taking the first `general` journal of any company. * `hr.salary.rule.account_debit` / `account_credit` get `check_company`. * `_get_tax_details` filters the `account.tax.repartition.line` lookups by company, and limits the one whose `.id` is read to a single record -- a tax spread over several repartition lines on the same account made that read raise `Expected singleton`. Tax and tag values are built with `Command`.
…g it Cancelling a payslip deleted its accounting entry outright -- posted or not -- with `force_delete=True`, unless the journal happened to have the hash table restriction enabled. That destroys the audit trail: a posted entry disappears from the books with no trace, and leaves a hole in the journal's sequence. The deletion also ran BEFORE `super()`, which can still refuse the cancellation, so a refused cancel could leave a confirmed payslip whose entry had already been destroyed. The entry is now always reversed, after `super()` has accepted the cancellation, with an explicit reversal date (the entry's own date, or today when the entry is backdated) so that nothing is posted before the entry it reverses. An entry that was never posted is still simply deleted -- nothing ever reached the books. Confirming a payslip twice created a second entry and doubled every amount in the books, because nothing checked for an existing `move_id`. It is now a no-op, logged. So that cancelling and confirming again still generates a fresh entry, the reversed pair is moved to a new `cancelled_move_ids` field, which is also where the audit trail now lives. Finally, a payslip that still carries a posted entry can no longer be deleted: it has to be cancelled first, so that its entry is reversed.
…mirror of the contract `hr.payslip.journal_id` was a stored *related* field on `contract_id.journal_id`. Being related it is readonly, so the form -- which marks it `required="1"` -- offered a field nobody could fill in: a payslip whose contract has no journal could not be confirmed and had no way out. Being related it was also recomputed from the contract, with three consequences: * the batch's journal was ignored. `hr.payslip.employees.compute_sheet` injects `default_journal_id` from the batch precisely so the payslips of a batch land in the batch's journal; the related field overwrote it with the contract's on the spot; * the same happened to any journal set by hand or by another module; * editing a contract's journal rewrote the journal of payslips that were already confirmed and posted, after the fact. It becomes an ordinary stored computed field with `readonly=False`, depending on `contract_id` and `payslip_run_id` themselves rather than on their journal: it proposes a journal when the contract or the batch changes and never overwrites the payslip afterwards. The batch's journal wins over the contract's. `check_company` and a company domain were added while the field was being redefined. The `onchange_contract` override goes away: it existed to work around the related field, and the compute now covers it.
…s and fixtures * `readme/CONFIGURE.md` was mangled -- its list markers were escaped, so the whole thing rendered as one paragraph starting with a stray `#`. Rewritten, and it now says what the module actually does: debit/credit per rule and that both are company-dependent, the partner rule per account type, the analytic precedence (contract over rule), and the journal's default account as the adjustment plug. * Added `readme/USAGE.md`: one entry per payslip, confirming twice is a no-op, cancel reverses rather than deletes, refunds invert the sides. * The payslip form showed the accounting entry as a bare readonly Many2one. It is a smart button now, next to the payslip lines one. * The two "no default account" errors named an *Expense Journal* and a *Credit/Debit Account* that exist nowhere in the module. They now name the salary journal and its default account, and say what the account is used for. * `logger.info` was called with an f-string; it takes lazy arguments now. * Dropped the `_description` on the `hr.contract` extension: `_inherit` already carries the base model's. * Test fixtures: `hr.employee.bank_account_id` was given the id of a `res.bank`, not of the `res.partner.bank` created right above it; the employee's bank account was therefore an unrelated record, and the bank-account branch of `_get_partner_id` was never really exercised. Fixed, and covered by a test. The fixture also moved to `setUpClass`.
59d71a6 to
6af5ec9
Compare
|
Friendly ping, could someone take a look at this one? It's been a couple of weeks. Thanks. |
|
Thanks for this, it fixes the empty journal we hit on 18.0 when the payslip is created from the form. One case is still left: a payslip with no batch and a contract without |
|
Thanks @mileo, good catch. Added here instead of a follow-up, in bf82060:
Small note for the record: in 16.0 this was an inline @mileo @appstogrow @CristianoMafraJunior @SirPyTech @marcelsavegnago @dreispt a review would be much appreciated. Thanks! |
dreispt
left a comment
There was a problem hiding this comment.
I have concerns with:
- Possibly unneeded message rewrites, breaking translations.
- Excessive low level uses of
with_companytriggering inefficient records rebrowse
A payslip with no batch and a contract without journal kept journal_id empty, and confirming it failed later when creating the account.move. When neither the batch nor the contract has a journal, propose the first general journal of the payslip's own company, as the batch already does by default. A journal of another company is no longer kept when the payslip's company changes. If the payslip still has no journal when it is confirmed, raise a clear UserError before building the entry.
… entry to post The check added to action_payslip_done raised whenever the payslip had no journal, before the move lines were built. A company without accounting (no chart of accounts, no general journal) whose salary rules have no accounts could no longer confirm any payslip, although there is nothing to post. Raise the "no salary journal" error only when the payslip generated move lines; the adjustment lines that need the journal's default account can only exist then too. A payslip without journal and without accounted lines confirms again and creates no entry.
When neither the batch nor the contract has a journal, the payslip falls back to the first general journal of its company. That fallback was inlined in _compute_journal_id, so a submodule that lets each company configure its salary journal could only fill the gap after super() had already chosen a general journal, and never got a say. Move the fallback to _get_default_salary_journal, which submodules can override to propose a company-configured journal and call super() when there is none.
Rewording the two "no default account" errors broke their existing translations. Restore the original strings.
Calling `with_company` on every salary rule of every line re-read the records each time. The payslip is now switched to its accounting company once, at the start of the loop in `action_payslip_done`, so its lines and their salary rules are read in that company, and the line helpers no longer switch it themselves. The values of the `account.move` are built by a new `_prepare_account_move_vals` hook.
It no longer requires a single record: it skips the payslips without an entry, reverses or drops the others, and returns the reversals it created. `action_payslip_cancel` just calls it on `self`.
…n entry Confirming a payslip that still carries an accounting entry was logged and skipped. That entry may not match what the payslip computes now, so keeping it silently hides a difference in the books. Raise a UserError instead, and let the user cancel the payslip (which reverses the entry) or correct it by hand.
The journal is the batch's, else the contract's, else the one proposed by `_get_default_salary_journal`. The step that kept the payslip's current journal when it belonged to the payslip's company is gone: the compute only runs when the batch, the contract or the company changes.
a925f7e to
886bf9b
Compare
|
Thanks for the review @dreispt. Pushed the changes:
|
|
On 8. good point, you're right. payroll_account/models/hr_payslip.py:R65-68 Custom salary journal silently replaced When a payslip changes contracts or batches without a configured journal, I see one more thing worth investigating: payroll_account/models/hr_payslip.py:R178 Wrong partner on cross-company payroll entries When account types differ across companies, A salary rule has company-dependent debit and credit accounts. The entry builder now reads them with the payslip's company, but _get_partner_id reads the same fields from the original payslip line in the active company. Partner selection therefore can disagree with the account actually posted. This matters for payable, receivable, and current-liability accounts, whose partner is chosen from either the contribution register or the employee. Example: Company A's credit account is an expense and company B's credit account is payable. A user active in A confirms a B payslip; its move uses B's payable account, but partner selection sees A's expense account and assigns no register partner. |
…as none Reverts the simplification of the journal compute: without the step that keeps the payslip's current journal, moving a payslip to a contract without a journal replaced a journal chosen by hand with the company's fallback journal, silently, and the entry was then posted in the wrong journal. The precedence is again: the batch's journal, the contract's, the payslip's current journal when it belongs to the payslip's company, and last `_get_default_salary_journal`. Tests cover the hand-picked journal and the journal of another company that must not be kept.
…ntry The partner of each journal item depends on the type of its account, and the debit/credit accounts are company-dependent. Cover a payslip of one company confirmed from another, with different account types per company: the register and employee partners follow the payslip's company.
|
Thanks @dreispt!
|
payslip's own company instead of the confirming user's active company.
confirming twice no longer duplicates the accounting entry.
journal_idis a real computed/editable field (batch > contract) insteadof a readonly mirror of the contract's journal.
messages, and fixes a broken test fixture.