forked from OCA/account-invoicing
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathstock.py
67 lines (59 loc) · 2.72 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
# -*- 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, _
from openerp.exceptions import Warning
class StockPicking(models.Model):
_inherit = "stock.picking"
@api.model
def _get_partner_to_invoice(self, picking):
partner_obj = self.env['res.partner']
partner = super(StockPicking, self)._get_partner_to_invoice(picking)
if isinstance(partner, int):
partner = partner_obj.browse(partner)
if picking.partner_id.id != partner.id:
# if someone else modified invoice partner, I use it
return partner.id
return partner.address_get(
['invoice'])['invoice']
@api.multi
def set_to_be_invoiced(self):
for picking in self:
if picking.invoice_state == '2binvoiced':
raise Warning(_("Can't update invoice control for picking %s: "
"It's 'to be invoiced' yet") % picking.name)
if picking.invoice_state in ('none', 'invoiced'):
if picking.invoice_id:
raise Warning(_('Picking %s has linked invoice %s') %
(picking.name, picking.invoice_id.number))
picking.invoice_state = '2binvoiced'
return True
class StockMove(models.Model):
_inherit = 'stock.move'
@api.model
def _get_master_data(self, move, company):
data = super(StockMove, self)._get_master_data(move, company)
if move.picking_id.partner_id.id != data[0].id:
# if someone else modified invoice partner, I use it
return data
partner_invoice_id = move.picking_id.partner_id.address_get(
['invoice'])['invoice']
partner = self.env['res.partner'].browse(partner_invoice_id)
new_data = partner, data[1], data[2]
return new_data