-
-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
335 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# Project specific | ||
oca.cfg | ||
.pytest_cache/ | ||
/.vscode | ||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
env/ | ||
bin/ | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
*.eggs | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.coverage | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Pycharm | ||
.idea | ||
|
||
# Eclipse | ||
.settings | ||
|
||
# Visual Studio cache/options directory | ||
.vs/ | ||
|
||
# OSX Files | ||
.DS_Store | ||
|
||
# Django stuff: | ||
*.log | ||
|
||
# Mr Developer | ||
.mr.developer.cfg | ||
.project | ||
.pydevproject | ||
|
||
# Rope | ||
.ropeproject | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# Backup files | ||
*~ | ||
*.swp | ||
|
||
# OCA rules | ||
!static/lib/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Copyright 2019 Ecosoft Co., Ltd. (http://ecosoft.co.th) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Copyright 2019 Ecosoft Co., Ltd. (http://ecosoft.co.th) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
'name': 'Purchase Budget Commitment', | ||
'version': '12.0.1.0.0', | ||
'license': 'AGPL-3', | ||
'author': 'Ecosoft,Odoo Community Association (OCA)', | ||
'website': 'https://github.com/OCA/mis-builder', | ||
'depends': [ | ||
'purchase', | ||
'account', | ||
], | ||
'data': [ | ||
'security/ir.model.access.csv', | ||
'views/purchase_view.xml', | ||
], | ||
'installable': True, | ||
'maintainers': ['kittiu'], | ||
'development_status': 'Beta', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Copyright 2019 Ecosoft Co., Ltd. (http://ecosoft.co.th) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
from . import purchase_budget_commit | ||
from . import purchase | ||
from . import account_invoice |
Binary file not shown.
Binary file added
BIN
+1.75 KB
purchase_budget_commit/models/__pycache__/account_invoice.cpython-36.pyc
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+1.56 KB
purchase_budget_commit/models/__pycache__/purchase_budget_commit.cpython-36.pyc
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Copyright 2019 Ecosoft Co., Ltd. (http://ecosoft.co.th) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
from odoo import models, api | ||
|
||
|
||
class AccountInvoice(models.Model): | ||
_inherit = 'account.invoice' | ||
|
||
@api.multi | ||
def _write(self, vals): | ||
"""Uncommit budget for source purchase document.""" | ||
res = super()._write(vals) | ||
if vals.get('state') in ('open', 'cancel'): | ||
self.mapped('invoice_line_ids').uncommit_purchase_budget() | ||
return res | ||
|
||
|
||
class AccountInvoiceLine(models.Model): | ||
_inherit = 'account.invoice.line' | ||
|
||
@api.multi | ||
def uncommit_purchase_budget(self): | ||
"""For vendor bill in valid state, do uncommit for related purchase.""" | ||
for inv_line in self: | ||
inv_state = inv_line.invoice_id.state | ||
inv_type = inv_line.invoice_id.type | ||
if inv_type in ('in_invoice', 'in_refund'): | ||
if inv_state in ('open', 'in_payment', 'paid'): | ||
rev = inv_type == 'in_invoice' and True or False | ||
purchase_line = inv_line.purchase_line_id | ||
if not purchase_line: | ||
continue | ||
qty = inv_line.uom_id._compute_quantity( | ||
inv_line.quantity, purchase_line.product_uom) | ||
# Confirm vendor bill, do uncommit budget) | ||
qty_bf_invoice = purchase_line.qty_invoiced - qty | ||
qty_balance = purchase_line.product_qty - qty_bf_invoice | ||
qty = qty > qty_balance and qty_balance or qty | ||
if qty <= 0: | ||
continue | ||
purchase_line.commit_budget( | ||
qty, reverse=rev, invoice_line_id=inv_line.id) | ||
else: # Cancel or draft, not commitment line | ||
self.env['purchase.budget.commit'].search( | ||
[('invoice_line_id', '=', inv_line.id)]).unlink() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# Copyright 2019 Ecosoft Co., Ltd. (http://ecosoft.co.th) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
from odoo import fields, models, api | ||
|
||
|
||
class PurchaseOrder(models.Model): | ||
_inherit = 'purchase.order' | ||
|
||
budget_commit_ids = fields.One2many( | ||
comodel_name='purchase.budget.commit', | ||
inverse_name='purchase_id', | ||
string='Purchase Budget Commitment', | ||
) | ||
|
||
@api.multi | ||
def recompute_budget_commit(self): | ||
self.mapped('order_line').recompute_budget_commit() | ||
|
||
@api.multi | ||
def _write(self, vals): | ||
""" | ||
- Commit budget when state changes to purchase | ||
- Cancel/Draft document should delete all budget commitment | ||
""" | ||
res = super()._write(vals) | ||
if vals.get('state') in ('purchase', 'cancel', 'draft'): | ||
for purchase_line in self.mapped('order_line'): | ||
purchase_line.commit_budget() | ||
return res | ||
|
||
|
||
class PurchaseOrderLine(models.Model): | ||
_inherit = 'purchase.order.line' | ||
|
||
budget_commit_ids = fields.One2many( | ||
comodel_name='purchase.budget.commit', | ||
inverse_name='purchase_line_id', | ||
string='Purchase Budget Commitment', | ||
) | ||
|
||
@api.multi | ||
def recompute_budget_commit(self): | ||
for purchase_line in self: | ||
purchase_line.budget_commit_ids.unlink() | ||
# Commit on purchase order | ||
purchase_line.commit_budget() | ||
# Uncommitted on invoice confirm | ||
purchase_line.invoice_lines.uncommit_purchase_budget() | ||
|
||
@api.multi | ||
def commit_budget(self, product_qty=False, | ||
reverse=False, invoice_line_id=False): | ||
"""Create budget commit for each purchase.order.line.""" | ||
self.ensure_one() | ||
if self.state in ('purchase', 'done'): | ||
if not product_qty: | ||
product_qty = self.product_qty | ||
fpos = self.order_id.fiscal_position_id | ||
account = self.product_id.product_tmpl_id.\ | ||
get_product_accounts(fpos)['expense'] | ||
company = self.env.user.company_id | ||
amount_currency = product_qty * self.price_unit | ||
date_order = self.order_id.date_order | ||
amount = self.currency_id._convert( | ||
amount_currency, company.currency_id, company, date_order) | ||
self.env['purchase.budget.commit'].create({ | ||
'purchase_line_id': self.id, | ||
'account_id': account.id, | ||
'date': date_order, | ||
'amount_currency': amount_currency, | ||
'debit': not reverse and amount or 0.0, | ||
'credit': reverse and amount or 0.0, | ||
'company_id': company.id, | ||
'invoice_line_id': invoice_line_id, | ||
}) | ||
else: | ||
self.budget_commit_ids.unlink() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# Copyright 2019 Ecosoft Co., Ltd. (http://ecosoft.co.th) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
from odoo import fields, models | ||
|
||
|
||
class PurchaseBudgetCommit(models.Model): | ||
|
||
_name = 'purchase.budget.commit' | ||
_description = 'Purchase Budget Commitment' | ||
|
||
purchase_id = fields.Many2one( | ||
comodel_name='purchase.order', | ||
related='purchase_line_id.order_id', | ||
readonly=True, | ||
store=True, | ||
index=True, | ||
) | ||
purchase_line_id = fields.Many2one( | ||
comodel_name='purchase.order.line', | ||
readonly=True, | ||
index=True, | ||
help="Commit budget for this purchase_line_id", | ||
) | ||
invoice_id = fields.Many2one( | ||
comodel_name='account.invoice', | ||
related='invoice_line_id.invoice_id', | ||
) | ||
invoice_line_id = fields.Many2one( | ||
comodel_name='account.invoice.line', | ||
readonly=True, | ||
index=True, | ||
help="Uncommit budget from this invoice_line_id", | ||
) | ||
date = fields.Date( | ||
required=True, | ||
index=True, | ||
) | ||
account_id = fields.Many2one( | ||
comodel_name='account.account', | ||
string='Account', | ||
auto_join=True, | ||
index=True, | ||
readonly=True, | ||
) | ||
account_analytic_id = fields.Many2one( | ||
comodel_name='account.analytic.account', | ||
string='Analytic account', | ||
auto_join=True, | ||
index=True, | ||
readonly=True, | ||
) | ||
amount_currency = fields.Float( | ||
required=True, | ||
help="Amount in multi currency", | ||
) | ||
credit = fields.Float( | ||
readonly=True, | ||
) | ||
debit = fields.Float( | ||
readonly=True, | ||
) | ||
company_id = fields.Many2one( | ||
'res.company', | ||
string='Company', | ||
required=True, | ||
default=lambda self: self.env.user.company_id.id, | ||
index=True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* Kitti Upariphutthiphong <kittiu@ecosoft.co.th> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
This module will create budget commitment for purchase (to be used as alternate actual source in mis_builder) | ||
|
||
When purchase order is confirmed, purchase.budget.commitment is created, and when | ||
vendor billed is created by purchase order is confirmed, reversed purchase.budget.commitment is created | ||
|
||
A new tab "Budget Commitment" is created on purchase order for budget user to keep track of the committed budget. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink | ||
access_purchase_budget_commit_user,access_purchase_budget_commit_user,model_purchase_budget_commit,,1,1,1,1 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
|
||
<record id="purchase_order_form" model="ir.ui.view"> | ||
<field name="name">purchase.order.form</field> | ||
<field name="model">purchase.order</field> | ||
<field name="inherit_id" ref="purchase.purchase_order_form"/> | ||
<field name="arch" type="xml"> | ||
<xpath expr="/form/sheet/notebook/page[@name='purchase_delivery_invoice']" position="after"> | ||
<page string="Budget Commitment" name="budget_commit"> | ||
<div class="oe_read_only oe_right oe_button_box" name="buttons"> | ||
<button type="object" name="recompute_budget_commit" string="Recompute" icon="fa-refresh" /> | ||
</div> | ||
<field name="budget_commit_ids" readonly="1"> | ||
<tree> | ||
<field name="purchase_line_id"/> | ||
<field name="invoice_id"/> | ||
<field name="write_uid"/> | ||
<field name="write_date"/> | ||
<field name="debit" sum="Total Debit"/> | ||
<field name="credit" sum="Total Credit"/> | ||
</tree> | ||
</field> | ||
</page> | ||
</xpath> | ||
</field> | ||
</record> | ||
|
||
</odoo> |