forked from OCA/stock-logistics-workflow
-
Notifications
You must be signed in to change notification settings - Fork 1
/
stock.py
75 lines (60 loc) · 2.88 KB
/
stock.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (C) 2013-15 Agile Business Group sagl (<http://www.agilebg.com>)
#
# 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
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp import models, api, fields
class StockMove(models.Model):
_inherit = "stock.move"
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 StockPicking(models.Model):
_inherit = "stock.picking"
@api.one
def _get_invoice_view_xmlid(self):
if self.invoice_id:
if self.invoice_id.type in ('in_invoice', 'in_refund'):
self.invoice_view_xmlid = 'account.invoice_supplier_form'
else:
self.invoice_view_xmlid = 'account.invoice_form'
invoice_id = fields.Many2one(comodel_name='account.invoice',
string='Invoice', readonly=True)
invoice_view_xmlid = fields.Char(compute='_get_invoice_view_xmlid',
string="Invoice View XMLID",
readonly=True)
class AccountInvoice(models.Model):
_inherit = "account.invoice"
picking_ids = fields.One2many(
comodel_name='stock.picking', inverse_name='invoice_id',
string='Related Pickings', readonly=True,
copy=False,
help="Related pickings "
"(only when the invoice has been generated from the picking).")
class AccountInvoiceLine(models.Model):
_inherit = "account.invoice.line"
move_line_ids = fields.One2many(
comodel_name='stock.move', inverse_name='invoice_line_id',
string='Related Stock Moves', readonly=True,
help="Related stock moves "
"(only when the invoice has been generated from the picking).")