add button 'create_equipment'
This commit is contained in:
parent
f49769990e
commit
cf34d85596
7
exceptions.py
Normal file
7
exceptions.py
Normal file
@ -0,0 +1,7 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
|
||||
from trytond.exceptions import UserError
|
||||
|
||||
class InvalidNumberPurchases(UserError):
|
||||
pass
|
12
message.xml
Normal file
12
message.xml
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
this repository contains the full copyright notices and license terms. -->
|
||||
|
||||
<tryton>
|
||||
<data grouped="1">
|
||||
<record model="ir.message" id="msg_invalid_number_purchases">
|
||||
<field name="text">Please, select only one purchase.</field>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
@ -57,7 +57,7 @@ class Template(metaclass=PoolMeta):
|
||||
useful_life = fields.Char(
|
||||
"Useful life", size=None)
|
||||
warranty = fields.Char(
|
||||
"Warranty", size=None)
|
||||
"Warranty")
|
||||
serial = fields.Char(
|
||||
"Serial", size=None)
|
||||
health_register = fields.Char(
|
||||
|
57
purchase.py
57
purchase.py
@ -2,11 +2,60 @@
|
||||
#txhis repository contains the full copyright notices and license terms
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
from trytond.model import ModelView, ModelSQL, fields
|
||||
from trytond.pyson import Eval
|
||||
from trytond.exceptions import UserError
|
||||
from trytond.i18n import gettext
|
||||
from .exceptions import (
|
||||
InvalidNumberPurchases)
|
||||
|
||||
class Purchase(metaclass=PoolMeta):
|
||||
__name__ = 'purchase.purchase'
|
||||
|
||||
equipment_available = fields.Boolean("Equipments Availables", readonly=True)
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(Purchase, cls).__setup__()
|
||||
cls._buttons.update({
|
||||
'create_equipments': {
|
||||
'invisible': Eval('equipment_avalaible')},
|
||||
})
|
||||
|
||||
|
||||
@classmethod
|
||||
@ModelView.button
|
||||
def create_equipments(cls, purchases):
|
||||
if len(purchases) > 1:
|
||||
raise InvalidNumberPurchases(
|
||||
gettext('purchase.msg_invalid_number_purchases'))
|
||||
else:
|
||||
pool = Pool()
|
||||
Equipment = pool.get('optical_equipment.equipment')
|
||||
Line = pool.get('purchase.line')
|
||||
lines = []
|
||||
purchase = purchases[0]
|
||||
|
||||
for line in purchase.lines:
|
||||
equipment = Equipment(
|
||||
company=line.company,
|
||||
equipment_type=line.product.equipment_type,
|
||||
party_address=line.address_equipment,
|
||||
product=line.product,
|
||||
risk=line.product.risk,
|
||||
use=line.product.use,
|
||||
biomedical_class=line.product.biomedical_class,
|
||||
calibration=line.product.calibration,
|
||||
refurbish=line.refurbish,
|
||||
serial=line.serial_equipment,
|
||||
software_version=line.product.software_version)
|
||||
|
||||
equipment.save()
|
||||
purchase.equipment_available = True
|
||||
cls.save(purchases)
|
||||
|
||||
|
||||
|
||||
"""
|
||||
@classmethod
|
||||
@ModelView.button
|
||||
def process(cls, purchases):
|
||||
@ -18,7 +67,7 @@ class Purchase(metaclass=PoolMeta):
|
||||
process, done = [], []
|
||||
cls.lock(purchases)
|
||||
for purchase in purchases:
|
||||
"""if purchase.state not in {'confirmed', 'processing', 'done'}:
|
||||
if purchase.state not in {'confirmed', 'processing', 'done'}:
|
||||
continue
|
||||
purchase.create_invoice()
|
||||
purchase.set_invoice_state()
|
||||
@ -27,7 +76,6 @@ class Purchase(metaclass=PoolMeta):
|
||||
if return_moves:
|
||||
purchase.create_return_shipment(return_moves)
|
||||
purchase.set_shipment_state()
|
||||
"""
|
||||
#raise UserError(str(dir(purchase)))
|
||||
#equipment = Equipment()
|
||||
for line in purchase.lines:
|
||||
@ -47,7 +95,7 @@ class Purchase(metaclass=PoolMeta):
|
||||
)
|
||||
equipment.save()
|
||||
#raise UserError(str([equipment.serial, equipment.software_version]))
|
||||
""" line.set_actual_quantity()
|
||||
line.set_actual_quantity()
|
||||
lines.append(line)
|
||||
|
||||
if purchase.is_done():
|
||||
@ -61,7 +109,8 @@ class Purchase(metaclass=PoolMeta):
|
||||
if process:
|
||||
cls.proceed(process)
|
||||
if done:
|
||||
cls.do(done)"""
|
||||
cls.do(done)
|
||||
"""
|
||||
|
||||
class Line(metaclass=PoolMeta):
|
||||
__name__ = 'purchase.line'
|
||||
|
10
purchase.xml
10
purchase.xml
@ -8,5 +8,15 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<field name="inherit" ref="purchase.purchase_line_view_form"/>
|
||||
<field name="name">purchase_line_form</field>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="purchase_view_form">
|
||||
<field name="model">purchase.purchase</field>
|
||||
<field name="inherit" ref="purchase.purchase_view_form"/>
|
||||
<field name="name">purchase_form</field>
|
||||
</record>
|
||||
<record model="ir.model.button" id="purchase_create_equipments">
|
||||
<field name="name">create_equipments</field>
|
||||
<field name="string">Create Equipments</field>
|
||||
<field name="model" search="[('model', '=', 'purchase.purchase')]"/>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
||||
|
10
view/purchase_form.xml
Normal file
10
view/purchase_form.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--This file file is part of Tryton. The COPYRIGHT file at the top level of this repository contains the full copyright notices and license terms. -->
|
||||
<data>
|
||||
<xpath
|
||||
expr="/form/notebook/page[@id='info']/separator[@name='comment']"
|
||||
position="before">
|
||||
<label name="equipment_available"/>
|
||||
<field name="equipment_available"/>
|
||||
</xpath>
|
||||
</data>
|
Loading…
Reference in New Issue
Block a user