[FIX]GOLEM Resource Account : do not allow invoice re-creation

This commit is contained in:
Fabien BOURGEOIS 2018-03-26 12:36:17 +02:00
parent 5307ae37c0
commit 471e9f35c7
2 changed files with 9 additions and 6 deletions

View File

@ -40,6 +40,9 @@ class GolemResourceReservation(models.Model):
def create_invoice(self):
""" Invoice creation """
for reservation in self:
if reservation.invoice_line_id:
raise ValidationError(_('You can not create an invoice as there '
'is already one.'))
inv_obj = self.env['account.invoice']
partner_id = reservation.partner_id
product = reservation.resource_id.product_tmpl_id
@ -66,11 +69,11 @@ class GolemResourceReservation(models.Model):
'invoice_line_ids': [(0, 0, {
'name': reservation.resource_id.name,
'origin': reservation.name,
'account_id': account_id,
'price_unit': amount,
'quantity': 1.0,
'discount': 0.0,
'uom_id': product.uom_id.id,
'account_id': account_id,
'product_id': product.id,
})]
})
reservation.invoice_line_id = reservation.invoice_id.invoice_line_ids[0]

View File

@ -28,6 +28,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<field name='inherit_id' ref="golem_resource.golem_resource_reservation_view_tree"/>
<field name="arch" type="xml">
<field name="state" position="after">
<field name="invoice_id" />
<field name="invoice_state" string="Invoice status" />
</field>
</field>
@ -42,11 +43,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<field name="arch" type="xml">
<button name="state_rejected" position="after">
<button name="create_invoice" type="object" string="Create Invoice" class="oe_highlight"
attrs="{'invisible': ['|', ('state', '!=', 'validated'), ('resource_product_id', '=', False)]}" />
attrs="{'invisible': ['|', ('state', '!=', 'validated'), '|', ('resource_product_id', '=', False), ('invoice_id', '!=', False)]}" />
</button>
<group name="reservation" position="after">
<group name="invoicing" string="Invoicing"
attrs="{'invisible': ['|', ('state', '!=', 'validated'), ('resource_product_id', '=', False)]}">
attrs="{'invisible': [('invoice_id', '=', False)]}">
<field name="resource_product_id" />
<field name="invoice_id" />