Skip to content

Commit

Permalink
[IMP] stock_dropshipping_dual_invoice: Allow to invoice more than one…
Browse files Browse the repository at this point in the history
… dropshipping pickings + returning view
  • Loading branch information
pedrobaeza committed Jun 9, 2015
1 parent e959b43 commit 88e32bc
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 30 deletions.
8 changes: 3 additions & 5 deletions stock_dropshipping_dual_invoice/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@ Usage
Known issues
------------

When the wizard creates a supplier invoice and a customer invoice, it does not
show them, and instead the wizard is simply closed, going back to the picking.
This is because we cannot easily show a customer and a supplier invoice
together in a tree view, because one of them would not get the correct form
view.
* When the wizard creates a supplier invoice and a customer invoice, the
returned view doesn't allow to show invoices in form view, because the form
wouldn't be correctly displayed.


Bug Tracker
Expand Down
4 changes: 3 additions & 1 deletion stock_dropshipping_dual_invoice/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
'summary':
'Create both Supplier and Customer Invoices from a Dropshipping Delivery',
'version': '0.1',
'author': "Camptocamp,Odoo Community Association (OCA)",
'author': "Camptocamp, "
"Serv. Tecnol. Avanzados - Pedro M. Baeza, "
"Odoo Community Association (OCA)",
'category': 'Warehouse',
'license': 'AGPL-3',
'depends': ['stock_account',
Expand Down
58 changes: 34 additions & 24 deletions stock_dropshipping_dual_invoice/wizard/stock_invoice_onshipping.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Author: Leonardo Pistone
# Copyright 2015 Camptocamp SA
# Contributor: Pedro M. Baeza
# Copyright 2015 Serv. Tecnol. Avanzados
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
Expand Down Expand Up @@ -33,7 +35,6 @@ def _need_two_invoices(self):
po = pick.move_lines[0].purchase_line_id.order_id
if so.order_policy == 'picking' and po.invoice_method == 'picking':
return True

return False

@api.depends('journal_type', 'need_two_invoices')
Expand All @@ -47,34 +48,43 @@ def _get_wizard_title(self):

@api.multi
def open_invoice(self):
action_data = super(StockInvoiceOnshipping, self).open_invoice()
res = super(StockInvoiceOnshipping, self).open_invoice()
if self.need_two_invoices:
# do not show the two invoices, because a form view would be wrong
return True
else:
return action_data
res['view_id'] = self.env.ref('account.invoice_tree').id
res['name'] = _('Invoices')
res['view_mode'] = 'tree'
del res['views']
del res['display_name']
return res

@api.multi
def create_invoice(self):
self.ensure_one()
if self.need_two_invoices:
pick_ids = self.env.context['active_ids']
pick = self.env['stock.picking'].browse(pick_ids)

first_invoice_ids = pick.with_context(
partner_to_invoice_id=pick.partner_id.id,
date_inv=self.invoice_date,
inv_type='in_invoice',
).action_invoice_create(
journal_id=self.journal_id.id,
group=self.group,
type='in_invoice',
)

for move in pick.move_lines:
if move.invoice_state == 'invoiced':
move.invoice_state = '2binvoiced'
second_invoice_ids = pick.with_context(
picking_ids = self.env.context['active_ids']
picking_model = self.env['stock.picking']
pickings = picking_model.browse(picking_ids)
# Group picking by customer
pickings_by_partner = {}
for picking in pickings:
if not pickings_by_partner.get(picking.partner_id):
pickings_by_partner[picking.partner_id] = picking_model
pickings_by_partner[picking.partner_id] += picking
first_invoice_ids = []
for partner, pickings_grouped in pickings_by_partner.iteritems():
first_invoice_ids += pickings_grouped.with_context(
partner_to_invoice_id=partner.id,
date_inv=self.invoice_date,
inv_type='in_invoice',
).action_invoice_create(
journal_id=self.journal_id.id,
group=self.group,
type='in_invoice',
)
# Allow to invoice again
pickings.mapped('move_lines').filtered(
lambda x: x.invoice_state == 'invoiced').write(
{'invoice_state': '2binvoiced'})
second_invoice_ids = pickings.with_context(
date_inv=self.invoice_date,
inv_type='out_invoice',
).action_invoice_create(
Expand Down

0 comments on commit 88e32bc

Please sign in to comment.