mirror of
https://github.com/bringout/oca-ocb-core.git
synced 2026-04-24 07:52:04 +02:00
Initial commit: Core packages
This commit is contained in:
commit
12c29a983b
9512 changed files with 8379910 additions and 0 deletions
|
|
@ -0,0 +1,55 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import fields, models, tools
|
||||
from odoo.tools import formatLang
|
||||
|
||||
class PurchaseBillUnion(models.Model):
|
||||
_name = 'purchase.bill.union'
|
||||
_auto = False
|
||||
_description = 'Purchases & Bills Union'
|
||||
_order = "date desc, name desc"
|
||||
_rec_names_search = ['name', 'reference']
|
||||
|
||||
name = fields.Char(string='Reference', readonly=True)
|
||||
reference = fields.Char(string='Source', readonly=True)
|
||||
partner_id = fields.Many2one('res.partner', string='Vendor', readonly=True)
|
||||
date = fields.Date(string='Date', readonly=True)
|
||||
amount = fields.Float(string='Amount', readonly=True)
|
||||
currency_id = fields.Many2one('res.currency', string='Currency', readonly=True)
|
||||
company_id = fields.Many2one('res.company', 'Company', readonly=True)
|
||||
vendor_bill_id = fields.Many2one('account.move', string='Vendor Bill', readonly=True)
|
||||
purchase_order_id = fields.Many2one('purchase.order', string='Purchase Order', readonly=True)
|
||||
|
||||
def init(self):
|
||||
tools.drop_view_if_exists(self.env.cr, 'purchase_bill_union')
|
||||
self.env.cr.execute("""
|
||||
CREATE OR REPLACE VIEW purchase_bill_union AS (
|
||||
SELECT
|
||||
id, name, ref as reference, partner_id, date, amount_untaxed as amount, currency_id, company_id,
|
||||
id as vendor_bill_id, NULL as purchase_order_id
|
||||
FROM account_move
|
||||
WHERE
|
||||
move_type='in_invoice' and state = 'posted'
|
||||
UNION
|
||||
SELECT
|
||||
-id, name, partner_ref as reference, partner_id, date_order::date as date, amount_untaxed as amount, currency_id, company_id,
|
||||
NULL as vendor_bill_id, id as purchase_order_id
|
||||
FROM purchase_order
|
||||
WHERE
|
||||
state in ('purchase', 'done') AND
|
||||
invoice_status in ('to invoice', 'no')
|
||||
)""")
|
||||
|
||||
def name_get(self):
|
||||
result = []
|
||||
for doc in self:
|
||||
name = doc.name or ''
|
||||
if doc.reference:
|
||||
name += ' - ' + doc.reference
|
||||
amount = doc.amount
|
||||
if doc.purchase_order_id and doc.purchase_order_id.invoice_status == 'no':
|
||||
amount = 0.0
|
||||
name += ': ' + formatLang(self.env, amount, monetary=True, currency_obj=doc.currency_id)
|
||||
result.append((doc.id, name))
|
||||
return result
|
||||
Loading…
Add table
Add a link
Reference in a new issue