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

[9.0] Migration of stock_picking_invoice_link module - WIP #295

Closed
wants to merge 1 commit into from
Closed
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
11 changes: 7 additions & 4 deletions stock_picking_invoice_link/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
##############################################################################
#
# Copyright (C) 2013-15 Agile Business Group sagl (<http://www.agilebg.com>)
# Copyright (C) 2017 BCIM (<http://www.bcim.be>)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
Expand All @@ -20,18 +21,20 @@

{
'name': 'Stock Picking Invoice Link',
'version': '8.0.1.0.0',
'version': '9.0.1.0.0',
'category': 'Warehouse Management',
'summary': 'Adds link between pickings and generated invoices',
'author': 'Agile Business Group, Odoo Community Association (OCA)',
'author': 'Agile Business Group, '
'BCIM sprl, '
'Odoo Community Association (OCA)',
'website': 'http://www.agilebg.com',
'license': 'AGPL-3',
'depends': ['stock_account'],
'depends': ['sale_stock'],
'data': [
'stock_view.xml',
'account_invoice_view.xml',
],
'demo': [],
'test': [],
'installable': False,
'installable': True,
}
51 changes: 44 additions & 7 deletions stock_picking_invoice_link/stock.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
##############################################################################
#
# Copyright (C) 2013-15 Agile Business Group sagl (<http://www.agilebg.com>)
# Copyright (C) 2017 BCIM (<http://www.bcim.be>)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
Expand All @@ -27,13 +28,49 @@ class StockMove(models.Model):
invoice_line_id = fields.Many2one(comodel_name='account.invoice.line',
string='Invoice Line', readonly=True)

@api.model
def _create_invoice_line_from_vals(self, move, invoice_line_vals):
inv_line_id = super(StockMove, self)._create_invoice_line_from_vals(
move, invoice_line_vals)
move.invoice_line_id = inv_line_id
move.picking_id.invoice_id = invoice_line_vals['invoice_id']
return inv_line_id

class SaleOrderLine(models.Model):
_inherit = "sale.order.line"

@api.multi
def invoice_line_create(self, invoice_id, qty):
res = super(SaleOrderLine, self).invoice_line_create(invoice_id, qty)
self.mapped('procurement_ids') \
.mapped('move_ids') \
.filtered(
lambda x: x.state == 'done' and
not x.location_dest_id.scrap_location and
x.location_dest_id.usage == 'customer') \
.mapped('picking_id') \
.write({'invoice_id': invoice_id})
return res

@api.multi
def _prepare_invoice_line(self, qty):
vals = super(SaleOrderLine, self)._prepare_invoice_line(qty)
# move_ids = self.procurement_ids.mapped('move_ids').filtered(
# lambda x: x.state == 'done' and
# not x.location_dest_id.scrap_location and
# x.location_dest_id.usage == 'customer').ids

# For performance reason, we compute the list of move in SQL
self._cr.execute("""
SELECT stock_move.id FROM stock_move
LEFT JOIN stock_location
ON stock_location.id=stock_move.location_dest_id
LEFT JOIN procurement_order
ON procurement_order.id=stock_move.procurement_id
LEFT JOIN sale_order_line
ON sale_order_line.id=procurement_order.sale_line_id
WHERE stock_move.state='done'
AND stock_location.scrap_location != 't'
AND stock_location.usage = 'customer'
AND sale_order_line.id in %s
""", (tuple(self.ids),))

move_ids = [row[0] for row in self._cr.fetchall()]
vals['move_line_ids'] = [(6, 0, move_ids)]
return vals


class StockPicking(models.Model):
Expand Down
14 changes: 7 additions & 7 deletions stock_picking_invoice_link/stock_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
<record id="view_picking_form" model="ir.ui.view">
<field name="name">stock_picking_invoice_link.stock.picking.form</field>
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock_account.view_picking_inherit_form2"/>
<field name="inherit_id" ref="stock.view_picking_form"/>
<field name="arch" type="xml">
<field name="invoice_state" position="after">
<field name="invoice_id" string="Invoice" groups="account.group_account_invoice" attrs="{'invisible':[('invoice_state', '=', 'none')]}" context="{'form_view_ref': invoice_view_xmlid}"/>
<field name="picking_type_id" position="after">
<field name="invoice_id" string="Invoice" groups="account.group_account_invoice" attrs="{'invisible':[('invoice_id', '=', False)]}" context="{'form_view_ref': invoice_view_xmlid}"/>
<field name="invoice_view_xmlid" invisible="1"/>
</field>
</field>
Expand All @@ -19,9 +19,9 @@
<record id="view_move_form" model="ir.ui.view">
<field name="name">stock_picking_invoice_link.stock.move.form</field>
<field name="model">stock.move</field>
<field name="inherit_id" ref="stock_account.view_move_form_inherit"/>
<field name="inherit_id" ref="stock.view_move_form"/>
<field name="arch" type="xml">
<field name="invoice_state" position="after">
<field name="name" position="after">
<field name="invoice_line_id" groups="account.group_account_invoice"/>
</field>
</field>
Expand All @@ -30,9 +30,9 @@
<record id="view_move_picking_form" model="ir.ui.view">
<field name="name">stock_picking_invoice_link.stock.move.picking.form</field>
<field name="model">stock.move</field>
<field name="inherit_id" ref="stock_account.view_move_picking_from_stockaccount_inherit"/>
<field name="inherit_id" ref="stock.view_move_picking_form"/>
<field name="arch" type="xml">
<field name="invoice_state" position="after">
<field name="name" position="after">
<field name="invoice_line_id" groups="account.group_account_invoice"/>
</field>
</field>
Expand Down