Server Framework 101 - Solusi 12

 solusi untuk tutorial https://www.odoo.com/documentation/18.0/developer/tutorials/server_framework_101/13_other_module.html


Buat modul baru dengan nama estate_account (Anda sudah melakukannya pada awal tutoral ini ketika membuat estate modul).

file estate_account/__init__.py

from . import estate_property


file estate_account/__manifest__.py

{
    'name': 'Estate Account',
    'depends':[
        'estate',
        'account',
    ],
    'auto_install': True
}


file estate_account/models/__init__.py

from . import estate_property


file estate_account/models/estate_property.py

# -*- coding: utf-8 -*-

from odoo import models, Command


class EstateProperty(models.Model):

    # ---------------------------------------- Private Attributes ---------------------------------

    _inherit = "estate.property"

    # ---------------------------------------- Action Methods -------------------------------------

    def action_sold(self):
        res = super().action_sold()
        journal = self.env["account.journal"].search([("type", "=", "sale")], limit=1)
        # Another way to get the journal:
        # journal = self.env["account.move"].with_context(default_move_type="out_invoice")._get_default_journal()
        for prop in self:
            self.env["account.move"].create(
                {
                    "partner_id": prop.buyer_id.id,
                    "move_type": "out_invoice",
                    "journal_id": journal.id,
                    "invoice_line_ids": [
                        Command.create({
                            "name": prop.name,
                            "quantity": 1.0,
                            "price_unit": prop.selling_price * 6.0 / 100.0,
                        }),
                        Command.create({
                            "name": "Administrative fees",
                            "quantity": 1.0,
                            "price_unit": 100.0,
                        }),
                    ],
                }
            )
        return res


restart odoo server, lalu update application list. Search module estate_account, lalu Click activate. Modul estate_account dan invoice akan otomatis diinstal.

Silakan coba buat property baru, lalu set status menjadi sold. Invoice akan otomatis dibuat.






Comments

Popular posts from this blog

Solusi Tutorial Owl Components - Counter

Solusi Tutorial Owl Components - Todo List

Tutorial Owl Components