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

[REF] hr_expense: Create Vendor Bills in both type of expenses #16

Open
wants to merge 1 commit into
base: 16.0-Expense-Sheet-Post-Journals-Draft-CarmenMiranda
Choose a base branch
from
Open
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
7 changes: 0 additions & 7 deletions addons/hr_expense/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@ def _creation_message(self):
return _("Expense entry Created")
return super()._creation_message()

@api.depends('expense_sheet_id.payment_mode')
def _compute_payment_state(self):
company_paid = self.filtered(lambda m: m.expense_sheet_id.payment_mode == 'company_account')
for move in company_paid:
move.payment_state = 'paid'
super(AccountMove, self - company_paid)._compute_payment_state()

@api.depends('expense_sheet_id')
def _compute_needed_terms(self):
# EXTENDS account
Expand Down
26 changes: 5 additions & 21 deletions addons/hr_expense/models/hr_expense.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,7 @@ def _prepare_move_line_vals(self):
'product_uom_id': self.product_uom_id.id,
'analytic_distribution': self.analytic_distribution,
'expense_id': self.id,
# TODO: Check if this needs to be the same with commercial...
'partner_id': False if self.payment_mode == 'company_account' else self.employee_id.sudo().address_home_id.commercial_partner_id.id,
'tax_ids': [Command.set(self.tax_ids.ids)],
}
Expand Down Expand Up @@ -1204,32 +1205,15 @@ def action_sheet_move_create(self):
expense_line_ids = self.mapped('expense_line_ids')\
.filtered(lambda r: not float_is_zero(r.total_amount, precision_rounding=(r.currency_id or self.env.company.currency_id).rounding))
res = expense_line_ids.with_context(clean_context(self.env.context)).action_move_create()

paid_expenses_company = self.filtered(lambda m: m.payment_mode == 'company_account')
paid_expenses_company.write({'state': 'done', 'amount_residual': 0.0, 'payment_state': 'paid'})

paid_expenses_employee = self - paid_expenses_company
paid_expenses_employee.write({'state': 'post'})
self.write({"state": "post"})

self.activity_update()
return res

def _do_create_moves(self):
self = self.with_context(clean_context(self.env.context)) # remove default_*
skip_context = {
'skip_invoice_sync':True,
'skip_invoice_line_sync':True,
'skip_account_move_synchronization':True,
'check_move_validity':False,
}
own_account_sheets = self.filtered(lambda sheet: sheet.payment_mode == 'own_account')
company_account_sheets = self - own_account_sheets

moves = self.env['account.move'].create([sheet._prepare_bill_vals() for sheet in own_account_sheets])
payments = self.env['account.payment'].with_context(**skip_context).create([sheet._prepare_payment_vals() for sheet in company_account_sheets])
moves |= payments.move_id
# NOTE: Only the Vendor Bills (Own account sheets) need to be left as draft, company can be posted.
payments.move_id.action_post()
moves = self.env["account.move"].create([sheet._prepare_bill_vals() for sheet in self])

self.activity_update()

Expand Down Expand Up @@ -1375,8 +1359,8 @@ def action_open_account_move(self):
'type': 'ir.actions.act_window',
'view_mode': 'form',
'views': [[False, "form"]],
'res_model': 'account.move' if self.payment_mode == 'own_account' else 'account.payment',
'res_id': self.account_move_id.id if self.payment_mode == 'own_account' else self.account_move_id.payment_id.id,
"res_id": self.account_move_id.id,
"res_model": "account.move",
}

# --------------------------------------------
Expand Down