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
76
77
78
79
80
81
82
83
84
85
86
|
from odoo import fields, models, api, _
from odoo.exceptions import AccessError, UserError, ValidationError
from dateutil.relativedelta import relativedelta
from datetime import datetime, timedelta
import logging
from pytz import timezone, utc
import io
import base64
try:
from odoo.tools.misc import xlsxwriter
except ImportError:
import xlsxwriter
_logger = logging.getLogger(__name__)
class PurchaseOrder(models.Model):
_inherit = 'purchase.order'
automatic_purchase_id = fields.Many2one(
'automatic.purchase',
string='Automatic Purchase Reference',
ondelete='set null',
index=True,
copy=False
)
sale_order_id = fields.Many2one('sale.order', string='Sales Order', copy=False)
move_entry_id = fields.Many2one('account.move', string='Journal Entries', copy=False)
amount_discount = fields.Monetary(
string='Total Discount',
compute='_compute_amount_discount',
store=True
)
biaya_lain_lain = fields.Float(
'Biaya Lain Lain',
default=0.0,
tracking=True,
copy=False
)
source = fields.Selection([
('requisition', 'Requisition'),
('reordering', 'Reordering'),
('purchasing_job', 'Purchasing Job'),
('manual', 'Manual')
], string='Source', default='manual', copy=False)
count_journals = fields.Integer('Count Payment', compute='_compute_count_journals')
def _compute_count_journals(self):
for order in self:
journals = self.env['account.move'].search([
('purchase_order_id', '=', order.id),
('move_type', '!=', 'in_invoice')
])
order.count_journals = len(journals)
def action_view_related_journals(self):
self.ensure_one()
journals = self.env['account.move'].search([
('purchase_order_id', '=', self.id),
('move_type', '!=', 'in_invoice')
])
return {
'name': 'Journals',
'type': 'ir.actions.act_window',
'res_model': 'account.move',
'view_mode': 'tree,form',
'target': 'current',
'domain': [('id', 'in', journals.ids)],
}
@api.depends('order_line.price_total', 'biaya_lain_lain')
def _amount_all(self):
super(PurchaseOrder, self)._amount_all()
for order in self:
amount_total = order.amount_untaxed + order.amount_tax - order.biaya_lain_lain
order.amount_total = order.currency_id.round(amount_total)
@api.depends('order_line.discount_amount')
def _compute_amount_discount(self):
for order in self:
order.amount_discount = sum(line.discount_amount for line in order.order_line)
|