Skip to content

Commit

Permalink
Merge PR #22 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by andhit-r
  • Loading branch information
ssi-bot committed Oct 13, 2024
2 parents 9a1cd2d + 074e48a commit f250ef0
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 185 deletions.
159 changes: 42 additions & 117 deletions ssi_revenue_recognition/models/revenue_recognition.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,23 @@ class RevenueRecognition(models.Model):
comodel_name="account.move",
readonly=True,
)
income_amount_policy = fields.Selection(
string="Income Amount Policy",
selection=[
("amount_accepted", "Amount Accepted"),
],
default="amount_accepted",
required=True,
)
expense_amount_policy = fields.Selection(
string="Expense Amount Policy",
selection=[
("balance", "Balance"),
("theoritical_balance", "Theoritical Balance"),
],
default="balance",
required=True,
)

@api.model
def _get_policy_field(self):
Expand Down Expand Up @@ -485,20 +502,11 @@ def _compute_balance(self):

@ssi_decorator.post_done_action()
def _create_accounting_entry(self):
pob = self.performance_obligation_id
self._create_move()
if pob.revenue_recognition_timing == "point_in_time":
self._create_move_point_in_time()
elif (
pob.revenue_recognition_timing == "over_time"
and pob.progress_completion_method == "input"
):
self._create_move_over_time_input()
elif (
pob.revenue_recognition_timing == "over_time"
and pob.progress_completion_method == "output"
):
self._create_move_over_time_output()
self._create_unearned_income_ml()
self._create_income_ml()
self._create_expense_ml()
self._create_wip_ml()
self.move_id.action_post()

def _create_move(self):
Expand All @@ -513,131 +521,41 @@ def _create_move(self):
}
)

def _create_move_point_in_time(self):
self.ensure_one()
self._create_unearned_income_ml_point_in_time()
self._create_income_ml_point_in_time()
for account in self.account_ids:
account._create_wip_ml_point_in_time()
account._create_expense_ml_point_in_time()

def _create_unearned_income_ml_point_in_time(self):
ML = self.env["account.move.line"]
ML.with_context(check_move_validity=False).create(
self._prepare_unearned_income_ml_point_in_time()
)

def _create_income_ml_point_in_time(self):
ML = self.env["account.move.line"]
ML.with_context(check_move_validity=False).create(
self._prepare_income_ml_point_in_time()
)

def _prepare_unearned_income_ml_point_in_time(self):
self.ensure_one()
pob = self.performance_obligation_id
return self._prepare_ml(
account=self.unearned_income_account_id,
debit=pob.price_subtotal,
credit=0.0,
)

def _prepare_income_ml_point_in_time(self):
self.ensure_one()
pob = self.performance_obligation_id
return self._prepare_ml(
account=self.income_account_id,
debit=0.0,
credit=pob.price_subtotal,
)

def _create_move_over_time_input(self):
self.ensure_one()
self._create_unearned_income_ml_over_time_input()
self._create_income_ml_over_time_input()
for account in self.account_ids:
account._create_wip_ml_over_time_input()
account._create_expense_ml_over_time_input()

def _create_move_over_time_output(self):
self.ensure_one()
self._create_unearned_income_ml_over_time_output()
self._create_income_ml_over_time_output()
for account in self.account_ids:
account._create_wip_ml_over_time_output()
account._create_expense_ml_over_time_output()

def _create_unearned_income_ml_over_time_output(self):
ML = self.env["account.move.line"]
ML.with_context(check_move_validity=False).create(
self._prepare_unearned_income_ml_over_time_output()
)

def _create_income_ml_over_time_output(self):
def _create_income_ml(self):
ML = self.env["account.move.line"]
ML.with_context(check_move_validity=False).create(
self._prepare_income_ml_over_time_output()
)

def _prepare_unearned_income_ml_over_time_output(self):
self.ensure_one()
return self._prepare_ml(
account=self.unearned_income_account_id,
debit=self.amount_accepted,
credit=0.0,
)
ML.with_context(check_move_validity=False).create(self._prepare_income_ml())

def _prepare_income_ml_over_time_output(self):
def _prepare_income_ml(self):
self.ensure_one()
return self._prepare_ml(
account=self.income_account_id,
credit=getattr(self, self.income_amount_policy),
debit=0.0,
credit=self.amount_accepted,
)

def _create_unearned_income_ml_over_time_input(self):
ML = self.env["account.move.line"]
ML.with_context(check_move_validity=False).create(
self._prepare_unearned_income_ml_over_time_input()
)

def _create_income_ml_over_time_input(self):
def _create_unearned_income_ml(self):
ML = self.env["account.move.line"]
ML.with_context(check_move_validity=False).create(
self._prepare_income_ml_over_time_input()
self._prepare_unearned_income_ml()
)

def _prepare_unearned_income_ml_over_time_input(self):
def _prepare_unearned_income_ml(self):
self.ensure_one()
return self._prepare_ml(
account=self.unearned_income_account_id,
debit=self.theoritical_accepted,
debit=getattr(self, self.income_amount_policy),
credit=0.0,
)

def _prepare_income_ml_over_time_input(self):
def _create_expense_ml(self):
self.ensure_one()
return self._prepare_ml(
account=self.income_account_id,
debit=0.0,
credit=self.theoritical_accepted,
)
for expense in self.account_ids:
expense._create_expense_ml()

def _prepare_account_move(self):
return {
"name": self.name,
"date": self.date,
"journal_id": self.journal_id.id,
}

def _create_income_move_lines(self):
def _create_wip_ml(self):
self.ensure_one()
ML = self.env["account.move.line"]

ML.with_context(check_move_validity=False).create(
self._prepare_unearned_income_ml()
)
ML.with_context(check_move_validity=False).create(self._prepare_income_ml())
for expense in self.account_ids:
expense._create_wip_ml()

def _prepare_ml(self, account, debit, credit):
pob = self.performance_obligation_id
Expand All @@ -650,6 +568,13 @@ def _prepare_ml(self, account, debit, credit):
"move_id": self.move_id.id,
}

def _prepare_account_move(self):
return {
"name": self.name,
"date": self.date,
"journal_id": self.journal_id.id,
}

@ssi_decorator.post_cancel_action()
def _20_cancel_move(self):
self.ensure_one()
Expand Down
78 changes: 10 additions & 68 deletions ssi_revenue_recognition/models/revenue_recognition_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,88 +106,30 @@ def _compute_theoritical_balance(self):
record.recognition_id.percentage_accepted / 100.00
) * record.budget

def _create_wip_ml_point_in_time(self):
ML = self.env["account.move.line"]
ML.with_context(check_move_validity=False).create(
self._prepare_wip_ml_point_in_time()
)

def _create_expense_ml_point_in_time(self):
ML = self.env["account.move.line"]
ML.with_context(check_move_validity=False).create(
self._prepare_expense_ml_point_in_time()
)

def _create_wip_ml_over_time_output(self):
ML = self.env["account.move.line"]
ML.with_context(check_move_validity=False).create(
self._prepare_wip_ml_over_time_output()
)

def _create_expense_ml_over_time_output(self):
ML = self.env["account.move.line"]
ML.with_context(check_move_validity=False).create(
self._prepare_expense_ml_over_time_output()
)

def _create_wip_ml_over_time_input(self):
ML = self.env["account.move.line"]
ML.with_context(check_move_validity=False).create(
self._prepare_wip_ml_over_time_input()
)

def _create_expense_ml_over_time_input(self):
ML = self.env["account.move.line"]
ML.with_context(check_move_validity=False).create(
self._prepare_expense_ml_over_time_input()
)

def _prepare_wip_ml_point_in_time(self):
def _create_expense_ml(self):
self.ensure_one()
return self._prepare_ml(
account=self.wip_account_id,
debit=0.0,
credit=self.balance,
)
ML = self.env["account.move.line"]
ML.with_context(check_move_validity=False).create(self._prepare_expense_ml())

def _prepare_expense_ml_point_in_time(self):
def _prepare_expense_ml(self):
self.ensure_one()
return self._prepare_ml(
account=self.expense_account_id,
debit=self.balance,
debit=getattr(self, self.recognition_id.expense_amount_policy),
credit=0.0,
)

def _prepare_wip_ml_over_time_output(self):
self.ensure_one()
return self._prepare_ml(
account=self.wip_account_id,
debit=0.0,
credit=self.theoritical_balance,
)

def _prepare_expense_ml_over_time_output(self):
def _create_wip_ml(self):
self.ensure_one()
return self._prepare_ml(
account=self.expense_account_id,
debit=self.theoritical_balance,
credit=0.0,
)
ML = self.env["account.move.line"]
ML.with_context(check_move_validity=False).create(self._prepare_wip_ml())

def _prepare_wip_ml_over_time_input(self):
def _prepare_wip_ml(self):
self.ensure_one()
return self._prepare_ml(
account=self.wip_account_id,
credit=getattr(self, self.recognition_id.expense_amount_policy),
debit=0.0,
credit=self.balance,
)

def _prepare_expense_ml_over_time_input(self):
self.ensure_one()
return self._prepare_ml(
account=self.expense_account_id,
debit=self.balance,
credit=0.0,
)

def _prepare_ml(self, account, debit, credit):
Expand Down
2 changes: 2 additions & 0 deletions ssi_revenue_recognition/views/revenue_recognition_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@
<page name="accounting" string="Accounting">
<group name="accounting" colspan="4" col="2">
<group name="accounting_1" colspan="1" col="2">
<field name="income_amount_policy" />
<field name="expense_amount_policy" />
<field name="journal_id" />
<field name="unearned_income_account_id" />
<field name="income_account_id" />
Expand Down

0 comments on commit f250ef0

Please sign in to comment.