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

8.0 sale_sourced_by_line - Fix is_shipped method #68

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 22 additions & 4 deletions sale_sourced_by_line/model/sale.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,33 @@ def action_ship_create(self, cr, uid, ids, context=None):
# OVERRIDE to use sale.order.line's procurement_group_id from lines
###
def _get_shipped(self, cr, uid, ids, name, args, context=None):
""" As procurement is per sale line basis, we check each line

If at least a line has no procurement group defined, it means it
isn't shipped yet.

Only when all procurement are done or cancelled, we consider
the sale order as being shipped.

And if there is no line, we have nothing to ship, thus it isn't
shipped.

"""
res = {}
for sale in self.browse(cr, uid, ids, context=context):
if not sale.order_line:
res[sale.id] = False
continue

groups = set([line.procurement_group_id
for line in sale.order_line])
is_shipped = False
is_shipped = True
for group in groups:
if group:
is_shipped &= all([proc.state in ['cancel', 'done']
for proc in group.procurement_ids])
if not group:
is_shipped = False
break
is_shipped &= all([proc.state in ['cancel', 'done']
for proc in group.procurement_ids])
res[sale.id] = is_shipped
return res

Expand Down