-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD][sale_credit_card_installment]: Adding sale installment.
- Loading branch information
Showing
9 changed files
with
203 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,4 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from . import models | ||
from . import wizard |
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,16 @@ | ||
# -*- coding: utf-8 -*- | ||
{ | ||
"name": "Implent in sale credit card installment", | ||
"summary": "", | ||
"description": """""", | ||
"author": "Axcelere", | ||
"website": "http://www.axcelere.com", | ||
"category": "sale", | ||
"version": "16.0.0.1", | ||
"depends": ['card_installment', 'sale'], | ||
"data": [ | ||
"security/ir.model.access.csv", | ||
"wizard/choose_payment_method_view.xml", | ||
"views/sale_order_view.xml", | ||
], | ||
} |
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 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from . import sale_order |
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,35 @@ | ||
############################################################################## | ||
# For copyright and license notices, see __manifest__.py file in module root | ||
# directory | ||
############################################################################## | ||
from odoo import models, fields | ||
|
||
|
||
class SaleOrder(models.Model): | ||
_inherit = 'sale.order' | ||
|
||
def action_open_payment_wizard(self): | ||
view_id = self.env.ref('sale_credit_card_installment.choose_payment_view_form').id | ||
# if self.env.context.get('carrier_recompute'): | ||
# name = _('Update shipping cost') | ||
# carrier = self.carrier_id | ||
# else: | ||
# name = _('Add a shipping method') | ||
# carrier = ( | ||
# self.with_company(self.company_id).partner_shipping_id.property_delivery_carrier_id | ||
# or self.with_company( | ||
# self.company_id).partner_shipping_id.commercial_partner_id.property_delivery_carrier_id | ||
# ) | ||
return { | ||
'name': 'Método de pago', | ||
'type': 'ir.actions.act_window', | ||
'view_mode': 'form', | ||
'res_model': 'choose.payment.method', | ||
'view_id': view_id, | ||
'views': [(view_id, 'form')], | ||
'target': 'new', | ||
'context': { | ||
'default_order_id': self.id, | ||
# 'default_carrier_id': carrier.id, | ||
} | ||
} |
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_choose_payment_method,sale_credit_card_installment.choose_payment_method,model_choose_payment_method,base.group_user,1,1,1,1 |
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,52 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<odoo> | ||
<record id="view_order_form_with_payment" model="ir.ui.view"> | ||
<field name="name">view.order.form.with.payment</field> | ||
<field name="model">sale.order</field> | ||
<field name="inherit_id" ref="sale.view_order_form"/> | ||
<field name="arch" type="xml"> | ||
<data> | ||
<!-- <xpath expr="//field[@name='partner_id']" position='after'>--> | ||
<!-- <field name="delivery_set" invisible="1"/>--> | ||
<!-- <field name="is_all_service" invisible="1"/>--> | ||
<!-- <field name="recompute_delivery_price" invisible="1"/>--> | ||
<!-- </xpath>--> | ||
<xpath expr="//group[@name='note_group']" position="before"> | ||
<div class="oe_right"> | ||
<button | ||
string="Método de pago" | ||
name="action_open_payment_wizard" | ||
type="object" | ||
/> | ||
<!-- <button--> | ||
<!-- string="Update shipping cost"--> | ||
<!-- name="action_open_delivery_wizard"--> | ||
<!-- context="{'carrier_recompute':True}"--> | ||
<!-- type="object"--> | ||
<!-- class="text-warning btn-secondary"--> | ||
<!-- attrs="{'invisible': ['|', '|',('is_all_service', '=', True), ('recompute_delivery_price', '=', False), ('delivery_set', '=', False)]}"--> | ||
<!-- />--> | ||
<!-- <button--> | ||
<!-- string="Update shipping cost"--> | ||
<!-- name="action_open_delivery_wizard"--> | ||
<!-- context="{'carrier_recompute':True}"--> | ||
<!-- type="object"--> | ||
<!-- attrs="{'invisible': ['|', '|',('is_all_service', '=', True), ('recompute_delivery_price', '=', True), ('delivery_set', '=', False)]}"--> | ||
<!-- />--> | ||
</div> | ||
</xpath> | ||
<!-- <xpath expr="//field[@name='order_line']/form/group/group/field[@name='price_unit']" position="before">--> | ||
<!-- <field name="recompute_delivery_price" invisible="1"/>--> | ||
<!-- <field name="is_delivery" invisible="1"/>--> | ||
<!-- </xpath>--> | ||
<!-- <xpath expr="//field[@name='order_line']/tree/field[@name='price_unit']" position="before">--> | ||
<!-- <field name="recompute_delivery_price" invisible="1"/>--> | ||
<!-- <field name="is_delivery" invisible="1"/>--> | ||
<!-- </xpath>--> | ||
<!-- <xpath expr="//field[@name='order_line']/tree" position="attributes">--> | ||
<!-- <attribute name="decoration-warning">recompute_delivery_price and is_delivery</attribute>--> | ||
<!-- </xpath>--> | ||
</data> | ||
</field> | ||
</record> | ||
</odoo> |
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 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from . import choose_payment_method |
61 changes: 61 additions & 0 deletions
61
sale_credit_card_installment/wizard/choose_payment_method.py
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,61 @@ | ||
############################################################################## | ||
# For copyright and license notices, see __manifest__.py file in module root | ||
# directory | ||
############################################################################## | ||
from odoo import models, fields, api | ||
|
||
|
||
class ChoosePaymentMethod(models.TransientModel): | ||
_name = 'choose.payment.method' | ||
_description = 'Choose payment method Wizard' | ||
|
||
order_id = fields.Many2one('sale.order', required=True, ondelete="cascade") | ||
journal_id = fields.Many2one('account.journal', string='Diario', required=True) | ||
available_payment_method_line_ids = fields.Many2many('account.payment.method.line', | ||
compute='_compute_payment_method_line_fields') | ||
payment_method_line_id = fields.Many2one('account.payment.method.line', domain="[('id', 'in', available_payment_method_line_ids)]", string='Método de pago', required=True) | ||
|
||
available_installment_ids = fields.Many2many('account.card.installment', | ||
compute='_compute_installment_ids') | ||
|
||
installment_id = fields.Many2one('account.card.installment', domain="[('id', 'in', available_installment_ids)]", string='Cuota', required=True) | ||
amount_surcharge = fields.Float( | ||
string="Recargo financiero", | ||
compute='_compute_amount' | ||
) | ||
total_amount = fields.Float( | ||
string="Total a pagar", | ||
compute='_compute_amount' | ||
) | ||
|
||
@api.depends('installment_id') | ||
def _compute_amount(self): | ||
for rec in self: | ||
amount = rec.order_id.amount_total | ||
installment = rec.installment_id.financial_surcharge | ||
amount_surcharge = amount * installment | ||
rec.amount_surcharge = amount_surcharge | ||
rec.total_amount = amount + amount_surcharge | ||
|
||
@api.depends('payment_method_line_id') | ||
def _compute_installment_ids(self): | ||
for rec in self: | ||
payment_method_line_id = rec.payment_method_line_id | ||
payment_id = rec.journal_id.inbound_payment_method_line_ids.filtered(lambda tx: tx.payment_method_id.id == payment_method_line_id.id) | ||
rec.available_installment_ids = payment_id.available_card_ids.mapped('installment_ids').ids | ||
|
||
@api.depends('journal_id') | ||
def _compute_payment_method_line_fields(self): | ||
for rec in self: | ||
rec.available_payment_method_line_ids = rec.journal_id.inbound_payment_method_line_ids.mapped('payment_method_id').ids | ||
|
||
def button_confirm(self): | ||
for rec in self: | ||
product_id = self.env['product.product'].search([('is_financial_charge', '=', True)], limit=1) | ||
vals = { | ||
'product_id': product_id.id, | ||
'product_uom_qty': 1, | ||
'price_unit': rec.amount_surcharge, | ||
'order_id': rec.order_id.id, | ||
} | ||
self.env['sale.order.line'].create(vals) |
27 changes: 27 additions & 0 deletions
27
sale_credit_card_installment/wizard/choose_payment_method_view.xml
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,27 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<odoo> | ||
<record id="choose_payment_view_form" model="ir.ui.view"> | ||
<field name="name">choose.payment.form</field> | ||
<field name="model">choose.payment.method</field> | ||
<field name="arch" type="xml"> | ||
<form> | ||
<group> | ||
<group> | ||
<field name="available_payment_method_line_ids" invisible="1"/> | ||
<field name="available_installment_ids" invisible="1"/> | ||
<field name="journal_id" domain="[('type', 'in', ['cash', 'bank'])]"/> | ||
<field name="payment_method_line_id"/> | ||
<field name="installment_id"/> | ||
<field name="amount_surcharge"/> | ||
<field name="total_amount"/> | ||
</group> | ||
</group> | ||
<footer> | ||
<button name="button_confirm" type="object" string="Update" class="btn-primary" data-hotkey="q"/> | ||
<!-- <button name="button_confirm" ype="object" string="Add" class="btn-primary" data-hotkey="q"/>--> | ||
<button string="Discard" special="cancel" data-hotkey="z" class="btn-secondary"/> | ||
</footer> | ||
</form> | ||
</field> | ||
</record> | ||
</odoo> |