forked from Yaltik/golem
[REF][FIX][IMP]GOLEM Resource Account : create only one invoice, use actions on main model and add as many lines as needed on invoice
This commit is contained in:
parent
2336614701
commit
f25e69040a
@ -31,43 +31,14 @@ class GolemReservationInvoiceWizard(models.TransientModel):
|
||||
default=lambda self: self._context.get('active_ids', []))
|
||||
|
||||
@api.multi
|
||||
def create_invoices(self):
|
||||
""" Invoice creations """
|
||||
def create_invoice(self):
|
||||
""" Invoice creation """
|
||||
self.ensure_one()
|
||||
|
||||
inv_obj = self.env['account.invoice']
|
||||
partner_id = self.reservation_ids[0].partner_id
|
||||
product = self.reservation_ids[0].resource_id.product_tmpl_id
|
||||
self.reservation_ids.check_before_invoicing()
|
||||
self.reservation_ids[0].create_invoice()
|
||||
if len(self.reservation_ids) > 1:
|
||||
invoice_id = self.reservation_ids[0].invoice_id
|
||||
self.reservation_ids[1:].create_invoice_line(invoice_id)
|
||||
|
||||
if product.id:
|
||||
account_id = product.property_account_income_id.id
|
||||
if not account_id:
|
||||
account_id = product.categ_id.property_account_income_categ_id.id
|
||||
if not account_id:
|
||||
raise UserError(
|
||||
_('There is no income account defined for this product: "%s". \
|
||||
You may have to install a chart of account from Accounting \
|
||||
app, settings menu.') % (product.name,))
|
||||
|
||||
lines = []
|
||||
|
||||
for reservation in self.reservation_ids:
|
||||
product = reservation.resource_id.product_tmpl_id
|
||||
amount = product.standard_price
|
||||
lines.append((0, 0, {
|
||||
'origin': reservation.resource_id.name,
|
||||
'account_id': account_id,
|
||||
'price_unit': amount,
|
||||
'quantity': 1.0,
|
||||
'uom_id': product.uom_id.id,
|
||||
'product_id': product.id,
|
||||
}))
|
||||
invoice = inv_obj.create({
|
||||
'origin': self.reservation_ids[-1].name,
|
||||
'type': 'out_invoice',
|
||||
'reference': False,
|
||||
'account_id': partner_id.property_account_receivable_id.id,
|
||||
'partner_id': partner_id.id,
|
||||
'invoice_line_ids': lines,
|
||||
})
|
||||
self.reservation_ids.write({'invoice_id': invoice.id})
|
||||
# return {}
|
||||
|
@ -25,14 +25,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
<field name="name"> GOLEM Reservation Invoice Wizard Form</field>
|
||||
<field name="model">golem.reservation.invoice.wizard</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Reservation to invoice">
|
||||
<form string="Reservations to invoice">
|
||||
<p>
|
||||
<strong>
|
||||
Invoices will be created in draft so that you can review them before validation
|
||||
Only one invoice will be created in draft with corresponding reservations.
|
||||
Then, you will be redirected to the new invoice and can review it before validation.
|
||||
</strong>
|
||||
</p>
|
||||
<footer>
|
||||
<button name="create_invoices" string="Create Invoices" type="object"
|
||||
<button name="create_invoice" string="Create Invoice" type="object"
|
||||
class="oe_highlight" />
|
||||
<button string="Cancel" class="oe_link" special="cancel" />
|
||||
</footer>
|
||||
|
Loading…
x
Reference in New Issue
Block a user