Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix _compute_invoice_state method #6

Open
wants to merge 2 commits into
base: 8.0-holding-invoicing
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions multi_company_holding_invoicing/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
from . import sale
from . import invoice
from . import model
from . import stock_picking
15 changes: 10 additions & 5 deletions multi_company_holding_invoicing/models/sale.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,33 @@ class SaleOrder(models.Model):
readonly=True,
copy=False,
store=True)

holding_invoice_id = fields.Many2one(
'account.invoice',
string='Holding Invoice',
copy=False,
readonly=True)

invoice_state = fields.Selection([
('none', 'Not Applicable'),
('not_ready', 'Not Ready'),
('invoiceable', 'Invoiceable'),
('pending', 'Pending'),
('invoiced', 'Invoiced'),
], string='Invoice State',
], string='Invoice State',
copy=False,
compute='_compute_invoice_state',
store=True)

@api.multi
@api.depends('shipped', 'section_id.holding_company_id')
@api.depends('picking_ids', 'section_id.holding_company_id')
def _compute_invoice_state(self):
# Note for perf issue the 'holding_invoice_id.state' is not set here
# as a dependency. Indeed the dependency is manually triggered when
# the holding_invoice is generated or the state is changed
# Note because the 'picking_ids' field is not stored,
# the 'picking_ids.state' is not set here as a dependency.
# Indeed, the dependency is automatically triggered when
# the state of picking is changed
# (see onchange_state method in stock.picking).
for sale in self:
if not sale.section_id.holding_company_id:
sale.invoice_state = 'none'
Expand All @@ -52,7 +55,9 @@ def _compute_invoice_state(self):
sale.invoice_state = 'invoiced'
else:
sale.invoice_state = 'pending'
elif sale.shipped:
elif (sale.picking_ids and
not sale.picking_ids.filtered(
lambda r: r.state not in ['done', 'cancel'])):
sale.invoice_state = 'invoiceable'
else:
sale.invoice_state = 'not_ready'
Expand Down
16 changes: 16 additions & 0 deletions multi_company_holding_invoicing/models/stock_picking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
# © 2015 Akretion (http://www.akretion.com)
# Sébastien BEAU <[email protected]>
# Chafique Delli <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).


from openerp import models, api


class StockPicking(models.Model):
_inherit = 'stock.picking'

@api.onchange('state')
def onchange_state(self):
return self.env['sale.order']._compute_invoice_state()