Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[15.0][IMP] Create Payment Flow. #583

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions fieldservice_mobile/models/fsm_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@

from odoo import api, fields, models

PAYMENT_STATE_SELECTION = [
('not_paid', 'Not Paid'),
('in_payment', 'In Payment'),
('paid', 'Paid'),
('partial', 'Partially Paid'),
('reversed', 'Reversed'),
('invoicing_legacy', 'Invoicing App Legacy'),
]


class FSMOrder(models.Model):
_inherit = "fsm.order"
Expand All @@ -21,6 +30,13 @@ def _compute_duration(self):
rec.duration = 0.0
return res

@api.depends("invoice_ids.payment_state")
def _compute_payment_state(self):
for rec in self:
rec.payment_state = "not_paid"
for invoice in rec.invoice_ids:
rec.payment_state = invoice.payment_state

duration = fields.Float(
string="Actual duration",
compute=_compute_duration,
Expand All @@ -30,6 +46,7 @@ def _compute_duration(self):
fsm_stage_history_ids = fields.One2many(
"fsm.stage.history", "order_id", string="Stage History"
)
payment_state = fields.Selection(PAYMENT_STATE_SELECTION, string="Payment State", compute="_compute_payment_state", store=True)

@api.model
def create_fsm_attachment(self, name, datas, res_model, res_id):
Expand All @@ -47,3 +64,54 @@ def create_fsm_attachment(self, name, datas, res_model, res_id):
)
)
return attachment.id

@api.model
def get_so_invoice(self):
invoice_rec = self.env["account.move"].sudo().search([
("invoice_origin", "=", self.sale_id.name),
("partner_id", "=", self.sale_id.partner_id.id)],
order='id desc', limit=1
)
return invoice_rec

@api.model
def generate_invoice_payment_link(self, fsm_order_id):
order = self.env["fsm.order"].browse(fsm_order_id)
if not order.sale_id:
return {'payment_status': False, 'message': 'The sale order is not found related to this FSO.'}

invoice_rec = order.get_so_invoice()
if not invoice_rec:
sale_advance_payment_obj = self.env["sale.advance.payment.inv"].sudo()
advc_payment_wiz = sale_advance_payment_obj.with_context(
{
"active_model": "sale.order",
"active_id": order.sale_id.id,
"active_ids": order.sale_id.ids,
}
).create(
{
"advance_payment_method": "delivered",
"amount": order.sale_id.amount_total,
}
)
advc_payment_wiz.sudo().create_invoices()
invoice_rec = order.get_so_invoice()
if invoice_rec:
payment_link_id = (self.env['payment.link.wizard']
.with_context(
default_res_model='account.move',
default_res_id=invoice_rec.id
)
.sudo().create({
'res_model': 'account.move',
'res_id': invoice_rec.id,
'amount': invoice_rec.amount_total,
'currency_id': invoice_rec.currency_id.id,
'partner_id': invoice_rec.partner_id.id,
'description': order.sale_id.name,
}))
return {
'payment_status': True,
'payment_link': payment_link_id.link
}
4 changes: 3 additions & 1 deletion fieldservice_mobile/security/ir.model.access.csv
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ access_maintenance_equipment_portal,access.maintenance.equipment.portal,maintena
access_ir_attachment_portal,access.ir.attachment.portal,base.model_ir_attachment,base.group_portal,1,0,0,0
access_mobile_feature_mapping_user,mobile.feature.user,fieldservice_mobile.model_fsm_mobile_feature_mapping,base.group_user,1,0,0,0
access_mobile_feature_mapping_manager,mobile.feature.manager,fieldservice_mobile.model_fsm_mobile_feature_mapping,fieldservice.group_fsm_manager,1,1,1,1
access_mobile_feature_mapping_user_portal,mobile.feature.portal,fieldservice_mobile.model_fsm_mobile_feature_mapping,base.group_portal,1,0,0,0
access_mobile_feature_line_user,mobile.feature.line.user,fieldservice_mobile.model_fsm_mobile_feature_line,base.group_user,1,0,0,0
access_mobile_feature_line_manager,mobile.feature.line.manager,fieldservice_mobile.model_fsm_mobile_feature_line,fieldservice.group_fsm_manager,1,1,1,1
access_mobile_feature_line_portal,mobile.feature.line.portal,fieldservice_mobile.model_fsm_mobile_feature_line,base.group_portal,1,0,0,0
access_mobile_feature_mapping_user_portal,mobile.feature.user.portal,fieldservice_mobile.model_fsm_mobile_feature_mapping,base.group_portal,1,0,0,0
access_mobile_feature_mapping_manager_portal,mobile.feature.manager.portal,fieldservice_mobile.model_fsm_mobile_feature_mapping,base.group_portal,1,0,0,0
access_calendar_recurrence_portal,access_calendar_recurrence_portal,calendar.model_calendar_recurrence,base.group_portal,1,0,0,0
3 changes: 3 additions & 0 deletions fieldservice_mobile/views/fsm_order_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
</field>
</group>
</xpath>
<field name="company_id" position="after">
<field name="payment_state" invisible="1"/>
</field>
</field>
</record>

Expand Down
5 changes: 3 additions & 2 deletions fieldservice_mobile/views/mobile_feature_mapping.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@
<notebook>
<page name="mapping_page" string="Group Access Rights">
<field name="feature_line_ids">
<tree editable="bottom">
<field name="name" />
<tree editable="bottom" create="false" delete="false">
<field name="name" readonly="1" force_save="1" />
<field name="code" readonly="1" force_save="1" optional="hide" />
<field name="group_ids" widget="many2many_tags" />
</tree>
</field>
Expand Down
Loading