Conversation
…n refund invoices
|
Hi @ilyasProgrammer, |
yajo
left a comment
There was a problem hiding this comment.
Code review. Missing functional screenshots/screencast.
marcos-mendez
left a comment
There was a problem hiding this comment.
Automated Review -- Tests Failed
1. Root Cause
The test failure occurs because the AccountInvoiceLineAgent model's _compute_amount method attempts to access inv_line.move_type on a record that has not yet been saved to the database (i.e., it's a NewId), leading to a CacheMiss error when trying to read the journal_id field from an unsaved invoice line.
2. Suggested Fix
In sale_commission_product_criteria_domain/models/account_invoice_line_agent.py, at line 28, the condition if inv_line.move_type and "refund" in inv_line.move_type: should be guarded to ensure inv_line is not a new record before accessing move_type.
Fix:
# Refunds commissions are negative
if inv_line.move_type and "refund" in inv_line.move_type and not inv_line.id:
line.amount = -line.amountOr better yet, check if the record is already saved:
# Refunds commissions are negative
if inv_line.move_type and "refund" in inv_line.move_type and inv_line.id:
line.amount = -line.amountThis prevents accessing move_type on unsaved records.
3. Additional Code Issues
- None of the code changes introduced any new bugs beyond the one described above.
4. Test Improvements
To improve test coverage for this change, consider adding a TransactionCase or SavepointCase test that creates a sale order, confirms it, and then generates an invoice before computing commissions — ensuring the invoice line is saved before accessing move_type.
Example test case suggestion:
def test_refund_invoice_commission_amount(self):
# Create a sale order with a product
so = self.env['sale.order'].create({
'partner_id': self.partner.id,
'order_line': [(0, 0, {
'name': self.product.name,
'product_id': self.product.id,
'product_uom_qty': 1,
'price_unit': 100,
})]
})
so.action_confirm()
# Create invoice
invoice = self._invoice_sale_order(so)
invoice.action_post()
# Create a refund
refund_wizard = self.env['account.move.reversal'].with_context(active_model="account.move", active_ids=invoice.ids).create({
'refund_method': 'refund',
'reason': 'Test refund'
})
refund = refund_wizard.reverse_moves()
# Check that refund commission is negative
agent_line = self.env['account.invoice.line.agent'].search([('invoice_line_id.move_id', '=', refund.id)])
self.assertLess(agent_line.amount, 0)Use SavepointCase if you need more control over database transactions or want to isolate tests.
⏰ This PR has been open for 51 days.
Every ignored PR is a contributor who might not come back. Review time matters. (OCA Aging Report)
Reciprocal Review Request
Hi everyone! I found some test failures on this PR and left detailed feedback above. I am happy to discuss or help debug. In the meantime, if any of you get a chance, I would appreciate a look at my open PR(s):
My open PRs across OCA:
- server-tools#3548 [18.0][MIG] base_kanban_stage: Migration to 18.0
- hr-attendance#262 [16.0][ADD] Hr_attendance_idsecure: iDSecure (ControliD) attendance integration
- stock-logistics-workflow#2276 [16.0][ADD] stock_move_line_devaluation
- stock-logistics-workflow#2275 [16.0][ADD] Stock move line analytic account
- stock-logistics-workflow#2268 [16.0][ADD] stock_move_line_picking_partner
- purchase-workflow#2694 [16.0][IMP]Purchase workflow added to review state & exception fix
Reviewing each other's work helps the whole community move forward. Thank you!
Environment via OCA Neural Reviewer: Minikube + K8s Job + oca-ci/py3.10-odoo16.0 | Odoo 16.0
Automated review by OCA Neural Reviewer + qwen3-coder:30b
When a refund invoice happens on a Commission type of "product" (Product Criteria with Domain), amount in refund invoices are always positive and Settlement Report shows like positive commissions.
With this fix, refund types gaves negative commissions like https://github.com/OCA/commission/blob/16.0/account_commission/models/account_move.py#L217-L219 on model "account.invoice.line.agent".
PR Series
MT-12373 @moduon @pedrobaeza @ilyasProgrammer @rafaelbn @yajo @Gelojr @fcvalgar please review if you want 😄