@ -0,0 +1,49 @@ |
|||
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.svg |
|||
:target: https://www.gnu.org/licenses/agpl-3.0-standalone.html |
|||
:alt: License: AGPL-3 |
|||
|
|||
Purchase Down Payment |
|||
======================= |
|||
This module helps to register down payment against the purchase order. |
|||
|
|||
Configuration |
|||
============= |
|||
No additional configuration |
|||
|
|||
Company |
|||
------- |
|||
* `Cybrosys Techno Solutions <https://cybrosys.com/>`__ |
|||
|
|||
License |
|||
======= |
|||
GNU AFFERO GENERAL PUBLIC LICENSE, Version 3 (AGPLv3) |
|||
(https://www.gnu.org/licenses/agpl-3.0-standalone.html) |
|||
|
|||
Credits |
|||
------- |
|||
Developer: V16 - Aswathi PN |
|||
V17 - Gayathri V |
|||
V18 - Ashwin T |
|||
Contact: odoo@cybrosys.com |
|||
|
|||
Contacts |
|||
-------- |
|||
* Mail Contact : odoo@cybrosys.com |
|||
* Website : https://cybrosys.com |
|||
|
|||
Bug Tracker |
|||
----------- |
|||
Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. |
|||
|
|||
Maintainer |
|||
========== |
|||
.. image:: https://cybrosys.com/images/logo.png |
|||
:target: https://cybrosys.com |
|||
|
|||
This module is maintained by Cybrosys Technologies. |
|||
|
|||
For support and more information, please visit `Our Website <https://cybrosys.com/>`__ |
|||
|
|||
Further information |
|||
=================== |
|||
HTML Description: `<static/description/index.html>`__ |
@ -0,0 +1,21 @@ |
|||
# -*- coding: utf-8 -*- |
|||
################################################################################ |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>). |
|||
# Author: Ashwin T(odoo@cybrosys.com) |
|||
# |
|||
# You can modify it under the terms of the GNU AFFERO |
|||
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
|||
# |
|||
# 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 (AGPL v3) for more details. |
|||
# |
|||
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
|||
# (AGPL v3) along with this program. |
|||
############################################################################## |
|||
from . import models |
|||
from . import wizard |
@ -0,0 +1,45 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################### |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>). |
|||
# Author: Ashwin T (<https://www.cybrosys.com>) |
|||
# |
|||
# You can modify it under the terms of the GNU AFFERO |
|||
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
|||
# |
|||
# 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 (AGPL v3) for more details. |
|||
# |
|||
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
|||
# (AGPL v3) along with this program. |
|||
############################################################################## |
|||
{ |
|||
'name': 'Purchase Down Payment', |
|||
'version': '18.0.1.0.0', |
|||
'summary': """Down payment with purchase order""", |
|||
'description': 'This module provides easy feature to register down payment' |
|||
'against the purchase order. User will be able to register ' |
|||
'downpayment in percentage and amount that would deduct from' |
|||
'vendor bill.', |
|||
'category': 'Purchase', |
|||
'author': 'Cybrosys Techno Solutions', |
|||
'company': 'Cybrosys Techno Solutions', |
|||
'maintainer': 'Cybrosys Techno Solutions', |
|||
'website': "https://www.cybrosys.com", |
|||
'depends': ['purchase', 'sale'], |
|||
'data': [ |
|||
'security/ir.model.access.csv', |
|||
'wizard/purchase_order_advance_payment_views.xml', |
|||
'views/purchase_order_views.xml', |
|||
'views/res_config_settings_views.xml', |
|||
], |
|||
'images': ['static/description/banner.png'], |
|||
'license': 'AGPL-3', |
|||
'installable': True, |
|||
'auto_install': False, |
|||
'application': False, |
|||
} |
@ -0,0 +1,7 @@ |
|||
## Module <purchase_down_payment> |
|||
|
|||
#### 27.12.2024 |
|||
#### Version 18.0.1.0.0 |
|||
#### ADD |
|||
|
|||
- Initial commit for Purchase Down Payment |
@ -0,0 +1,22 @@ |
|||
# -*- coding: utf-8 -*- |
|||
################################################################################ |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>). |
|||
# Author: Ashwin T (odoo@cybrosys.com) |
|||
# |
|||
# You can modify it under the terms of the GNU AFFERO |
|||
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
|||
# |
|||
# 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 (AGPL v3) for more details. |
|||
# |
|||
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
|||
# (AGPL v3) along with this program. |
|||
############################################################################## |
|||
from . import purchase_order |
|||
from . import purchase_order_line |
|||
from . import res_config_settings |
@ -0,0 +1,201 @@ |
|||
# -*- coding: utf-8 -*- |
|||
################################################################################ |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>). |
|||
# Author: Ashwin T (odoo@cybrosys.com) |
|||
# |
|||
# You can modify it under the terms of the GNU AFFERO |
|||
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
|||
# |
|||
# 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 (AGPL v3) for more details. |
|||
# |
|||
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
|||
# (AGPL v3) along with this program. |
|||
############################################################################## |
|||
from odoo import api, models, _ |
|||
from odoo.tools import float_is_zero |
|||
from itertools import groupby |
|||
from odoo.exceptions import UserError |
|||
|
|||
|
|||
class PurchaseOrder(models.Model): |
|||
""" |
|||
This class is created for inherited model Purchase Order. |
|||
|
|||
Methods: _nothing_to_invoice_error(self): Function for showing the |
|||
user error while there is no products are received for the purchase |
|||
order. |
|||
|
|||
_deduct_payment(self): This function is for deducting the down |
|||
payment amount from next down payment invoice. |
|||
|
|||
_prepare_down_payment_section_line(self): Function for creating |
|||
dict of values to create a new purchase down payment section. |
|||
|
|||
_get_invoiceable_lines(self): |
|||
Function for returning the orders invoiceable lines. |
|||
|
|||
""" |
|||
_inherit = 'purchase.order' |
|||
|
|||
@api.model |
|||
def _nothing_to_invoice_error(self): |
|||
"""Function to showing user error while there is no products are |
|||
received for the purchase order""" |
|||
return UserError(_( |
|||
"There is nothing to bill!\n\n" |
|||
"Reason(s) of this behavior could be:\n" |
|||
"- You should recieve your products before billing them: " |
|||
"Click on the \"truck\" icon " |
|||
"(top-right of your screen) and follow instructions.\n" |
|||
"- You should modify the control policy of your product: Open the " |
|||
"product, go to the " |
|||
"\"Purchase\" tab and modify control policy from \"On received " |
|||
"quantities\" to \"On ordered" |
|||
"quantities\"." |
|||
)) |
|||
|
|||
def _deduct_payment(self, grouped=False, final=False, date=None): |
|||
""" |
|||
Create the Bill associated to the PO. |
|||
:returns: list of created invoices |
|||
""" |
|||
invoice_vals_list = [] |
|||
invoice_item_sequence = 0 # Incremental sequencing to keep the lines |
|||
# order on the invoice. |
|||
for order in self: |
|||
order = order.with_company(order.company_id) |
|||
invoice_vals = order._prepare_invoice() |
|||
invoiceable_lines = order._get_invoiceable_lines(final) |
|||
if not any(not line.display_type for line in invoiceable_lines): |
|||
continue |
|||
invoice_line_vals = [] |
|||
down_payment_section_added = False |
|||
for line in invoiceable_lines: |
|||
if not down_payment_section_added and line.is_downpayment: |
|||
invoice_line_vals.append( |
|||
(0, 0, order._prepare_down_payment_section_line( |
|||
sequence=invoice_item_sequence, |
|||
)), |
|||
) |
|||
down_payment_section_added = True |
|||
invoice_item_sequence += 1 |
|||
invoice_line_vals.append( |
|||
(0, 0, line._prepare_invoice_line( |
|||
sequence=invoice_item_sequence, |
|||
)), |
|||
) |
|||
invoice_item_sequence += 1 |
|||
invoice_vals['invoice_line_ids'] += invoice_line_vals |
|||
invoice_vals_list.append(invoice_vals) |
|||
if not invoice_vals_list: |
|||
raise self._nothing_to_invoice_error() |
|||
if not grouped: |
|||
new_invoice_vals_list = [] |
|||
invoice_grouping_keys = self._get_invoice_grouping_keys() |
|||
invoice_vals_list = sorted( |
|||
invoice_vals_list, |
|||
key=lambda x: [ |
|||
x.get(grouping_key) for grouping_key in |
|||
invoice_grouping_keys |
|||
] |
|||
) |
|||
for grouping_keys, invoices in groupby(invoice_vals_list, |
|||
key=lambda x: [ |
|||
x.get(grouping_key) for |
|||
grouping_key in |
|||
invoice_grouping_keys]): |
|||
origins = set() |
|||
payment_refs = set() |
|||
refs = set() |
|||
ref_invoice_vals = None |
|||
for invoice_vals in invoices: |
|||
if not ref_invoice_vals: |
|||
ref_invoice_vals = invoice_vals |
|||
else: |
|||
ref_invoice_vals['invoice_line_ids'] += invoice_vals[ |
|||
'invoice_line_ids'] |
|||
origins.add(invoice_vals['invoice_origin']) |
|||
payment_refs.add(invoice_vals['payment_reference']) |
|||
refs.add(invoice_vals['ref']) |
|||
ref_invoice_vals.update({ |
|||
'ref': ', '.join(refs)[:2000], |
|||
'invoice_origin': ', '.join(origins), |
|||
'payment_reference': len( |
|||
payment_refs) == 1 and payment_refs.pop() or False, |
|||
}) |
|||
new_invoice_vals_list.append(ref_invoice_vals) |
|||
invoice_vals_list = new_invoice_vals_list |
|||
if len(invoice_vals_list) < len(self): |
|||
PurchaseOrderLine = self.env['purchase.order.line'] |
|||
for invoice in invoice_vals_list: |
|||
sequence = 1 |
|||
for line in invoice['invoice_line_ids']: |
|||
line[2][ |
|||
'sequence'] = PurchaseOrderLine._get_invoice_line_sequence( |
|||
new=sequence, |
|||
old=line[2]['sequence']) |
|||
sequence += 1 |
|||
moves = self.env['account.move'].sudo().with_context( |
|||
default_move_type='out_invoice').create(invoice_vals_list) |
|||
return moves |
|||
|
|||
@api.model |
|||
def _prepare_down_payment_section_line(self, **optional_values): |
|||
""" |
|||
Prepare the dict of values to create a new down payment section for a |
|||
purchase order line. :param optional_values: any parameter that |
|||
should be added to the returned down payment section |
|||
""" |
|||
context = {'lang': self.partner_id.lang} |
|||
down_payments_section_line = { |
|||
'display_type': 'line_section', |
|||
'name': _('Down Payments'), |
|||
'product_id': False, |
|||
'product_uom_id': False, |
|||
'quantity': 0, |
|||
'discount': 0, |
|||
'price_unit': 0, |
|||
'account_id': False |
|||
} |
|||
del context |
|||
if optional_values: |
|||
down_payments_section_line.update(optional_values) |
|||
return down_payments_section_line |
|||
|
|||
def _get_invoice_grouping_keys(self): |
|||
"""Return invoice grouping keys""" |
|||
return ['company_id', 'partner_id', 'currency_id'] |
|||
|
|||
def _get_invoiceable_lines(self, final=False): |
|||
"""Return the invoiceable lines for order `self`.""" |
|||
down_payment_line_ids = [] |
|||
invoiceable_line_ids = [] |
|||
pending_section = None |
|||
precision = self.env['decimal.precision'].precision_get( |
|||
'Product Unit of Measure') |
|||
for line in self.order_line: |
|||
line.display_type = '' |
|||
if line.display_type == 'line_section': |
|||
pending_section = line |
|||
continue |
|||
if line.display_type != 'line_note' and float_is_zero( |
|||
line.qty_to_invoice, precision_digits=precision): |
|||
continue |
|||
if (line.qty_to_invoice > 0 or ( |
|||
line.qty_to_invoice < 0 and final) or line.display_type == |
|||
'line_note'): |
|||
if line.is_downpayment: |
|||
down_payment_line_ids.append(line.id) |
|||
continue |
|||
if pending_section: |
|||
invoiceable_line_ids.append(pending_section.id) |
|||
pending_section = None |
|||
invoiceable_line_ids.append(line.id) |
|||
return self.env['purchase.order.line'].browse( |
|||
invoiceable_line_ids + down_payment_line_ids) |
@ -0,0 +1,61 @@ |
|||
# -*- coding: utf-8 -*- |
|||
################################################################################ |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>). |
|||
# Author: Ashwin T(odoo@cybrosys.com) |
|||
# |
|||
# You can modify it under the terms of the GNU AFFERO |
|||
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
|||
# |
|||
# 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 (AGPL v3) for more details. |
|||
# |
|||
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
|||
# (AGPL v3) along with this program. |
|||
############################################################################## |
|||
from odoo import fields, models |
|||
|
|||
|
|||
class PurchaseOrderLine(models.Model): |
|||
""" |
|||
The class is created for inherited the model purchase.order.line. |
|||
|
|||
Methods: |
|||
_prepare_invoice_line(): |
|||
Function to add the invoice lines of down payment |
|||
""" |
|||
_inherit = 'purchase.order.line' |
|||
|
|||
is_downpayment = fields.Boolean( |
|||
string="Is a down payment", help="Down payments are made when " |
|||
"creating Bills from a purchase order." |
|||
"They are not copied when " |
|||
"duplicating a purchase order.") |
|||
|
|||
def _prepare_invoice_line(self, **optional_values): |
|||
""" |
|||
Prepare the dict of values to create the new bill line for a purchase |
|||
order line. :param qty: float quantity to bill :param |
|||
optional_values: any parameter that should be added to the returned |
|||
bill line |
|||
""" |
|||
self.ensure_one() |
|||
res = { |
|||
'display_type': 'product', |
|||
'sequence': self.sequence, |
|||
'name': self.name, |
|||
'product_id': self.product_id.id, |
|||
'product_uom_id': self.product_uom.id, |
|||
'quantity': self.qty_to_invoice, |
|||
'price_unit': self.price_unit, |
|||
'purchase_line_id': self.id, |
|||
} |
|||
if optional_values: |
|||
res.update(optional_values) |
|||
if self.display_type: |
|||
res['account_id'] = False |
|||
return res |
@ -0,0 +1,32 @@ |
|||
# -*- coding: utf-8 -*- |
|||
################################################################################ |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>). |
|||
# Author: Ashwin T (odoo@cybrosys.com) |
|||
# |
|||
# You can modify it under the terms of the GNU AFFERO |
|||
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
|||
# |
|||
# 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 (AGPL v3) for more details. |
|||
# |
|||
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
|||
# (AGPL v3) along with this program. |
|||
############################################################################## |
|||
from odoo import fields, models |
|||
|
|||
|
|||
class ResConfigSettings(models.TransientModel): |
|||
"""The class is to created for inherited the model Res Config Settings""" |
|||
_inherit = 'res.config.settings' |
|||
|
|||
po_deposit_default_product_id = fields.Many2one( |
|||
'product.product', |
|||
'PO Deposit Product', |
|||
domain="[('type', '=', 'service')]", |
|||
config_parameter='purchase_down_payment.po_deposit_default_product_id', |
|||
help='Default product used for payment advances in purchase order') |
|
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 210 KiB |
After Width: | Height: | Size: 209 KiB |
After Width: | Height: | Size: 109 KiB |
After Width: | Height: | Size: 495 B |
After Width: | Height: | Size: 1.0 KiB |
After Width: | Height: | Size: 624 B |
After Width: | Height: | Size: 136 KiB |
After Width: | Height: | Size: 214 KiB |
After Width: | Height: | Size: 36 KiB |
After Width: | Height: | Size: 3.6 KiB |
After Width: | Height: | Size: 310 B |
After Width: | Height: | Size: 929 B |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 3.3 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 17 KiB |
After Width: | Height: | Size: 542 B |
After Width: | Height: | Size: 576 B |
After Width: | Height: | Size: 733 B |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 4.0 KiB |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 343 KiB |
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 911 B |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 600 B |
After Width: | Height: | Size: 673 B |
After Width: | Height: | Size: 2.0 KiB |
After Width: | Height: | Size: 462 B |
After Width: | Height: | Size: 2.1 KiB |
After Width: | Height: | Size: 926 B |
After Width: | Height: | Size: 9.0 KiB |
After Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 7.0 KiB |
After Width: | Height: | Size: 878 B |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 653 B |
After Width: | Height: | Size: 800 B |
After Width: | Height: | Size: 905 B |
After Width: | Height: | Size: 189 KiB |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 839 B |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 5.9 KiB |
After Width: | Height: | Size: 1.6 KiB |
After Width: | Height: | Size: 34 KiB |
After Width: | Height: | Size: 26 KiB |
After Width: | Height: | Size: 3.8 KiB |
After Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 427 B |
After Width: | Height: | Size: 627 B |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 988 B |
After Width: | Height: | Size: 3.7 KiB |
After Width: | Height: | Size: 5.0 KiB |
After Width: | Height: | Size: 875 B |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 767 KiB |
After Width: | Height: | Size: 138 KiB |
After Width: | Height: | Size: 760 KiB |
After Width: | Height: | Size: 92 KiB |
After Width: | Height: | Size: 697 KiB |
After Width: | Height: | Size: 1.1 MiB |
After Width: | Height: | Size: 122 KiB |
After Width: | Height: | Size: 123 KiB |
After Width: | Height: | Size: 126 KiB |
After Width: | Height: | Size: 124 KiB |
After Width: | Height: | Size: 120 KiB |
After Width: | Height: | Size: 121 KiB |
After Width: | Height: | Size: 116 KiB |
After Width: | Height: | Size: 121 KiB |
After Width: | Height: | Size: 116 KiB |
After Width: | Height: | Size: 135 KiB |
After Width: | Height: | Size: 92 KiB |
After Width: | Height: | Size: 12 KiB |
@ -0,0 +1,20 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<odoo> |
|||
<!-- Inherited the Purchase Order form view to add a new button --> |
|||
<record id="purchase_order_form" model="ir.ui.view"> |
|||
<field name="name"> |
|||
purchase.order.view.form.inherit.purchase.down.payment |
|||
</field> |
|||
<field name="model">purchase.order</field> |
|||
<field name="inherit_id" ref="purchase.purchase_order_form"/> |
|||
<field name="arch" type="xml"> |
|||
<xpath expr="//header/button[@name='action_create_invoice']" |
|||
position="replace"> |
|||
<button name="%(purchase_down_payment.purchase_order_advance_payment_action)d" |
|||
string="Create Bill" |
|||
invisible="state not in ('purchase', 'done') or invoice_status in ('no', 'invoiced')" |
|||
type="action" data-hotkey="w"/> |
|||
</xpath> |
|||
</field> |
|||
</record> |
|||
</odoo> |
@ -0,0 +1,28 @@ |
|||
<?xml version="1.0" encoding="UTF-8" ?> |
|||
<odoo> |
|||
<!-- Inherited the Res Config Settings to add new field on it--> |
|||
<record id="res_config_settings_view_form_purchase" model="ir.ui.view"> |
|||
<field name="name"> |
|||
res.config.settings.view.form.inherit.purchase.down.payment |
|||
</field> |
|||
<field name="model">res.config.settings</field> |
|||
<field name="priority" eval="95"/> |
|||
<field name="inherit_id" ref="purchase.res_config_settings_view_form_purchase"/> |
|||
<field name="arch" type="xml"> |
|||
<xpath expr="//block[@name='invoicing_settings_container']" position="inside"> |
|||
<div class="col-12 col-lg-6 o_setting_box"> |
|||
<div class="o_setting_left_pane"/> |
|||
<div class="o_setting_right_pane"> |
|||
<span class="o_form_label">Down Payment</span> |
|||
<div class="text-muted"> |
|||
Product used for down payments in purchase bill |
|||
</div> |
|||
<div class="text-muted"> |
|||
<field name="po_deposit_default_product_id"/> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</xpath> |
|||
</field> |
|||
</record> |
|||
</odoo> |
@ -0,0 +1,20 @@ |
|||
# -*- coding: utf-8 -*- |
|||
################################################################################ |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>). |
|||
# Author: Ashwin T(odoo@cybrosys.com) |
|||
# |
|||
# You can modify it under the terms of the GNU AFFERO |
|||
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
|||
# |
|||
# 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 (AGPL v3) for more details. |
|||
# |
|||
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
|||
# (AGPL v3) along with this program. |
|||
############################################################################## |
|||
from . import purchase_order_advance_payment |
@ -0,0 +1,241 @@ |
|||
# -*- coding: utf-8 -*- |
|||
################################################################################ |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>). |
|||
# Author: Ashwin T (odoo@cybrosys.com) |
|||
# |
|||
# You can modify it under the terms of the GNU AFFERO |
|||
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
|||
# |
|||
# 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 (AGPL v3) for more details. |
|||
# |
|||
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
|||
# (AGPL v3) along with this program. |
|||
############################################################################## |
|||
import time |
|||
from datetime import datetime |
|||
|
|||
from odoo import api, fields, models, _ |
|||
from odoo.exceptions import UserError |
|||
from odoo.fields import Command |
|||
|
|||
|
|||
class PurchaseOrderAdvancePayment(models.TransientModel): |
|||
"""The class is created to creating a new model purchase order advance |
|||
payment.""" |
|||
_name = 'purchase.order.advance.payment' |
|||
_description = 'Purchase Order Advance Payment Bill' |
|||
|
|||
@api.model |
|||
def _default_product_id(self): |
|||
"""Function to fetch the purchase down payment default product""" |
|||
product_id = self.env['ir.config_parameter'].sudo().get_param( |
|||
'purchase_down_payment.po_deposit_default_product_id') |
|||
return self.env['product.product'].browse(int(product_id)).exists() |
|||
|
|||
@api.model |
|||
def _default_currency_id(self): |
|||
"""Function to fetch the currency_id from purchase order""" |
|||
if self._context.get( |
|||
'active_model') == 'purchase.order' and self._context.get( |
|||
'active_id', False): |
|||
purchase_order = self.env['purchase.order'].browse( |
|||
self._context.get('active_id')) |
|||
return purchase_order.currency_id |
|||
|
|||
@api.model |
|||
def _default_has_down_payment(self): |
|||
"""Function to check the Purchase order has down payment or not""" |
|||
if self._context.get( |
|||
'active_model') == 'purchase.order' and self._context.get( |
|||
'active_id', False): |
|||
purchase_order = self.env['purchase.order'].browse( |
|||
self._context.get('active_id')) |
|||
return purchase_order.order_line.filtered( |
|||
lambda purchase_order_line: purchase_order_line.is_downpayment |
|||
) |
|||
return False |
|||
|
|||
advance_payment_method = fields.Selection([ |
|||
('delivered', 'Regular bill'), |
|||
('percentage', 'Down payment (percentage)'), |
|||
('fixed', 'Down payment (fixed amount)') |
|||
], string='Create Bill', default='delivered', required=True, |
|||
help="A standard bill is issued with all the order lines ready " |
|||
"for billing, \ |
|||
according to their billing policy (based on ordered or delivered " |
|||
"quantity).") |
|||
has_down_payments = fields.Boolean(string='Has down payments', |
|||
default=_default_has_down_payment, |
|||
readonly=True, |
|||
help='To check the invoice in down ' |
|||
'payment or not') |
|||
product_id = fields.Many2one('product.product', |
|||
string='Down Payment Product', |
|||
domain=[('type', '=', 'service')], |
|||
default=_default_product_id, |
|||
help='To add the down payment product') |
|||
deduct_down_payments = fields.Boolean(string='Deduct down payments', |
|||
default=False, |
|||
help='To mention the down payment ' |
|||
'amount deduct to next invoice') |
|||
amount = fields.Float(string='Down Payment Amount', digits='Account', |
|||
help="The percentage of amount to be bill in " |
|||
"advance, taxes excluded.") |
|||
currency_id = fields.Many2one('res.currency', string='Currency', |
|||
default=_default_currency_id, |
|||
help='Default company currency') |
|||
fixed_amount = fields.Monetary(string='Down Payment Amount (Fixed)', |
|||
help="The fixed amount to be bill in " |
|||
"advance, taxes excluded.") |
|||
deposit_account_id = fields.Many2one('account.account', |
|||
string="Income Account", |
|||
domain=[('deprecated', '=', False)], |
|||
help="Account used for deposits") |
|||
deposit_taxes_ids = fields.Many2many('account.tax', |
|||
string="Customer Taxes", |
|||
domain=[ |
|||
('type_tax_use', '=', 'purchase')], |
|||
help="Taxes used for deposits") |
|||
|
|||
def _get_advance_details(self, order): |
|||
"""Function to find get the down payment amount and purchase order""" |
|||
if self.advance_payment_method == 'percentage': |
|||
if all(self.product_id.taxes_id.mapped('price_include')): |
|||
amount = order.amount_total * self.amount / 100 |
|||
else: |
|||
amount = order.amount_untaxed * self.amount / 100 |
|||
name = _("Down payment of %s%%") % (self.amount) |
|||
else: |
|||
amount = self.fixed_amount |
|||
name = _('Down Payment') |
|||
context = {'lang': order.partner_id.lang} |
|||
del context |
|||
return amount, name |
|||
|
|||
def _prepare_po_line(self, order, tax_ids, amount): |
|||
"""Function to getting the purchase order line data""" |
|||
context = {'lang': order.partner_id.lang} |
|||
po_values = { |
|||
'name': _('Down Payment: %s / %s') % ( |
|||
time.strftime('%m-%Y-%d'), order.name), |
|||
'price_unit': amount, |
|||
'product_uom_qty': 0.0, |
|||
'product_qty': 0.0, |
|||
'order_id': order.id, |
|||
'product_uom': self.product_id.uom_id.id, |
|||
'product_id': self.product_id.id, |
|||
'taxes_id': [(6, 0, tax_ids)], |
|||
'is_downpayment': True, |
|||
'sequence': order.order_line and order.order_line[ |
|||
-1].sequence + 1 or 10, |
|||
'date_planned': datetime.today(), |
|||
} |
|||
del context |
|||
return po_values |
|||
|
|||
def _prepare_invoice_values(self, order, name, amount, so_line): |
|||
"""Function for take invoice values""" |
|||
invoice_vals = { |
|||
'ref': order.partner_ref or '', |
|||
'move_type': 'in_invoice', |
|||
'invoice_origin': order.name, |
|||
'invoice_user_id': order.user_id.id, |
|||
'narration': order.notes, |
|||
'partner_id': order.partner_id.id, |
|||
'fiscal_position_id': ( |
|||
order.fiscal_position_id or |
|||
order.fiscal_position_id._get_fiscal_position( |
|||
order.partner_id)).id, |
|||
'currency_id': order.currency_id.id, |
|||
'payment_reference': order.partner_ref or '', |
|||
'invoice_payment_term_id': order.payment_term_id.id, |
|||
'partner_bank_id': order.company_id.partner_id.bank_ids[:1].id, |
|||
'invoice_line_ids': [(0, 0, { |
|||
'name': name, |
|||
'price_unit': amount, |
|||
'quantity': 1.0, |
|||
'product_id': self.product_id.id, |
|||
'purchase_line_id': so_line.id, |
|||
'product_uom_id': so_line.product_uom.id, |
|||
})], |
|||
} |
|||
return invoice_vals |
|||
|
|||
def _create_bill(self, order, so_line, amount): |
|||
"""Function for creating the purchase bill""" |
|||
if ( |
|||
self.advance_payment_method == 'percentage' and self.amount <= |
|||
0.00) or ( |
|||
self.advance_payment_method == 'fixed' and self.fixed_amount <= |
|||
0.00): |
|||
raise UserError( |
|||
_('The value of the down payment amount must be positive.')) |
|||
amount, name = self._get_advance_details(order) |
|||
invoice_vals = self._prepare_invoice_values(order, name, amount, |
|||
so_line) |
|||
if order.fiscal_position_id: |
|||
invoice_vals['fiscal_position_id'] = order.fiscal_position_id.id |
|||
invoice = self.env['account.move'].with_company(order.company_id) \ |
|||
.sudo().create(invoice_vals).with_user(self.env.uid) |
|||
return invoice |
|||
|
|||
def _prepare_down_payment_product_values(self): |
|||
return { |
|||
'name': _('Down payment'), |
|||
'type': 'service', |
|||
'invoice_policy': 'order', |
|||
'company_id': False, |
|||
'property_account_income_id': self.deposit_account_id.id, |
|||
'taxes_id': [Command.set(self.deposit_taxes_ids.ids)], |
|||
} |
|||
|
|||
def action_create_advance_bill(self): |
|||
"""Function for creating purchase down payment bill""" |
|||
purchase_order = self.env['purchase.order'].browse( |
|||
self._context.get('active_ids', [])) |
|||
if self.advance_payment_method == 'delivered': |
|||
if self.deduct_down_payments: |
|||
purchase_order._deduct_payment(final=self.deduct_down_payments) |
|||
else: |
|||
purchase_order.action_create_invoice() |
|||
else: |
|||
if not self.product_id: |
|||
vals = self._prepare_down_payment_product_values() |
|||
self.product_id = self.env['product.product'].create(vals) |
|||
self.env['ir.config_parameter'].sudo().set_param( |
|||
'purchase_down_payment.po_deposit_default_product_id', |
|||
self.product_id.id) |
|||
purchase_line_obj = self.env['purchase.order.line'] |
|||
for order in purchase_order: |
|||
amount, name = self._get_advance_details(order) |
|||
if self.product_id.invoice_policy != 'order': |
|||
raise UserError( |
|||
_('The product used to invoice a down payment should ' |
|||
'have an invoice policy set to "Ordered ' |
|||
'quantities". Please update your deposit product to ' |
|||
'be able to create a deposit invoice.')) |
|||
if self.product_id.type != 'service': |
|||
raise UserError( |
|||
_("The product used to invoice a down payment should " |
|||
"be of type 'Service'. Please use another product " |
|||
"or update this product.")) |
|||
taxes = self.product_id.taxes_id.filtered( |
|||
lambda |
|||
r: not order.company_id or r.company_id == order.company_id) |
|||
tax_ids = order.fiscal_position_id.map_tax(taxes).ids |
|||
po_line_values = self._prepare_po_line(order, |
|||
tax_ids, amount) |
|||
po_line = purchase_line_obj.create(po_line_values) |
|||
self._create_bill(order, po_line, amount) |
|||
if self._context.get('open_invoices', False): |
|||
return purchase_order.action_view_invoice() |
|||
return {'type': 'ir.actions.act_window_close'} |
|||
if self._context.get('open_invoices', False): |
|||
return purchase_order.action_view_invoice() |
|||
return {'type': 'ir.actions.act_window_close'} |
@ -0,0 +1,71 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<odoo> |
|||
<!-- Purchase Order Advance Payment Wizard--> |
|||
<record id="purchase_order_advance_payment_view_form" model="ir.ui.view"> |
|||
<field name="name">purchase.order.advance.payment.view.form</field> |
|||
<field name="model">purchase.order.advance.payment</field> |
|||
<field name="arch" type="xml"> |
|||
<form string="Purchase Order Advance Bill"> |
|||
<p class="oe_grey"> |
|||
Bills will be created in draft so that you can review them |
|||
before validation. |
|||
</p> |
|||
<group> |
|||
<field name="advance_payment_method" class="oe_inline" |
|||
widget="radio"/> |
|||
<field name="has_down_payments" invisible="1"/> |
|||
<label for="deduct_down_payments" string="" |
|||
invisible="has_down_payments == False or advance_payment_method != 'delivered'"/> |
|||
<div invisible="has_down_payments == False or advance_payment_method != 'delivered'" |
|||
id="down_payment_details"> |
|||
<field name="deduct_down_payments" nolabel="1"/> |
|||
<label for="deduct_down_payments"/> |
|||
</div> |
|||
<label for="amount" |
|||
invisible="advance_payment_method not in ('fixed','percentage')"/> |
|||
<div invisible="advance_payment_method not in ('fixed','percentage')" |
|||
id="payment_method_details"> |
|||
<field name="currency_id" invisible="1"/> |
|||
<field name="fixed_amount" |
|||
required="advance_payment_method == 'fixed'" |
|||
invisible="advance_payment_method != 'fixed'" |
|||
class="oe_inline"/> |
|||
<field name="amount" |
|||
required="advance_payment_method == 'percentage'" |
|||
invisible="advance_payment_method != 'percentage'" |
|||
class="oe_inline"/> |
|||
<span |
|||
invisible="advance_payment_method != 'percentage'" |
|||
class="oe_inline">% |
|||
</span> |
|||
</div> |
|||
<field name="product_id" |
|||
context="{'default_invoice_policy': 'order'}" |
|||
class="oe_inline" |
|||
invisible="advance_payment_method not in ('fixed','percentage')"/> |
|||
</group> |
|||
<footer> |
|||
<button name="action_create_advance_bill" |
|||
string="Create and View Bill" type="object" |
|||
context="{'open_invoices': True}" |
|||
class="btn-primary" data-hotkey="q"/> |
|||
<button name="action_create_advance_bill" id="create_advance_bill" |
|||
string="Create Bill" type="object" |
|||
data-hotkey="w"/> |
|||
<button string="Cancel" class="btn-secondary" |
|||
special="cancel" data-hotkey="z"/> |
|||
</footer> |
|||
</form> |
|||
</field> |
|||
</record> |
|||
<!--Purchase Order Advance Payment Wizard action--> |
|||
<record id="purchase_order_advance_payment_action" model="ir.actions.act_window"> |
|||
<field name="name">Create Bill</field> |
|||
<field name="type">ir.actions.act_window</field> |
|||
<field name="res_model">purchase.order.advance.payment</field> |
|||
<field name="view_mode">form</field> |
|||
<field name="target">new</field> |
|||
<field name="binding_model_id" ref="purchase.model_purchase_order"/> |
|||
<field name="binding_view_types">list</field> |
|||
</record> |
|||
</odoo> |