Fix: Add buttons with error
This commit is contained in:
		| @@ -1,6 +1,6 @@ | ||||
| # 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.model import ModelView, ModelSQL, fields | ||||
| from trytond.model import ModelView, ModelSQL, fields, Workflow | ||||
| from trytond.pool import Pool | ||||
| from trytond.transaction import Transaction | ||||
| from trytond.modules.currency.fields import Monetary | ||||
| @@ -9,7 +9,7 @@ from decimal import Decimal | ||||
| from datetime import date | ||||
|  | ||||
|  | ||||
| class SaleOrder(ModelView, ModelSQL): | ||||
| class SaleOrder (Workflow, ModelView, ModelSQL): | ||||
|     "Sale Order" | ||||
|     __name__ = 'sale.order' | ||||
|  | ||||
| @@ -23,7 +23,7 @@ class SaleOrder(ModelView, ModelSQL): | ||||
|         [("on_site", "On Site"), | ||||
|          ("at_home", "At Home")], 'Pickup Location' | ||||
|     ) | ||||
|     order_adress = fields.Many2One( | ||||
|     order_address = fields.Many2One( | ||||
|         'party.address', 'Address' | ||||
|     ) | ||||
|     order_mobile = fields.Function( | ||||
| @@ -42,6 +42,51 @@ class SaleOrder(ModelView, ModelSQL): | ||||
|         Monetary("Total", currency='currency', digits='currency'), | ||||
|         'on_change_with_total_order' | ||||
|     ) | ||||
|     number = fields.Char( | ||||
|         "Number", readonly=True | ||||
|     ) | ||||
|     state = fields.Selection([ | ||||
|         ('draft', 'Draft'), | ||||
|         ('confirmed', 'Confirmed')], "State" | ||||
|     ) | ||||
|  | ||||
|     @classmethod | ||||
|     def __setup__(cls): | ||||
|         super(SaleOrder, cls).__setup__() | ||||
|         cls._buttons.update({ | ||||
|             'confirm': {}, | ||||
|         }) | ||||
|         cls._transitions |= set(( | ||||
|             ('draft', 'confirmed'), | ||||
|         )) | ||||
|  | ||||
|     @classmethod | ||||
|     @ModelView.button | ||||
|     @Workflow.transition('confirmed') | ||||
|     def confirm(cls, orders): | ||||
|         for order in orders: | ||||
|             if order.number: | ||||
|                 continue | ||||
|             else: | ||||
|                 cls.set_code([order]) | ||||
|  | ||||
|     @classmethod | ||||
|     def set_code(cls, orders): | ||||
|         for order in orders: | ||||
|             order.number = cls.get_number()[0].get() | ||||
|             order.save() | ||||
|  | ||||
|     @classmethod | ||||
|     def get_number(cls): | ||||
|         pool = Pool() | ||||
|         Sequence = pool.get('ir.sequence') | ||||
|         order_sequence = Sequence.search([( | ||||
|             'sequence_type', '=', "sale.order")]) | ||||
|         return order_sequence | ||||
|  | ||||
|     @staticmethod | ||||
|     def default_state(): | ||||
|         return 'draft' | ||||
|  | ||||
|     @staticmethod | ||||
|     def default_company(): | ||||
|   | ||||
| @@ -39,6 +39,21 @@ this repository contains the full copyright notices and license terms. --> | ||||
|       <field name="view" ref="sale_order_view_form"/> | ||||
|       <field name="act_window" ref="act_sale_order"/> | ||||
|     </record> | ||||
|    | ||||
|     <record model="ir.sequence.type" id="sequence_type_order"> | ||||
|       <field name="name">Order</field> | ||||
|     </record> | ||||
|     <record model="ir.sequence" id="sequence_sale_order"> | ||||
|       <field name="name">Sale Order Number Sequence</field> | ||||
|       <field name="sequence_type" ref="sequence_type_order"/> | ||||
|       <field name="prefix">SO</field> | ||||
|       <field name="padding">5</field> | ||||
|     </record> | ||||
|     <record model="ir.model.button" id="confirm_order_button"> | ||||
| 	    <field name="name">confirm</field> | ||||
| 	    <field name="string">Confirm</field> | ||||
| 	    <field name="model" search="[('model', '=', 'sale_order.order')]"/> | ||||
| 	</record> | ||||
|     <menuitem | ||||
|       name="Order" | ||||
|       action="act_sale_order" | ||||
|   | ||||
| @@ -34,7 +34,6 @@ Create order:: | ||||
|   >>> order = SaleOrder() | ||||
|   >>> order.party = party | ||||
|   >>> order.pickup_location = "on_site" | ||||
|   >>> order.save() | ||||
|   >>> line1 = order.lines.new() | ||||
|   >>> line1.product = product | ||||
|   >>> line1.unit = unit | ||||
| @@ -43,6 +42,10 @@ Create order:: | ||||
|   >>> line1.total_amount = Decimal('33600') | ||||
|   >>> order.total_order = Decimal('33600') | ||||
|   >>> order.save() | ||||
|  | ||||
|  | ||||
|    | ||||
|   >>> order.state | ||||
|   'draft' | ||||
|   >>> order.click('confirm') | ||||
|   >>> order.state | ||||
|   'confirmed' | ||||
|   >>> order.number | ||||
|   'SO00001' | ||||
| @@ -4,10 +4,12 @@ this repository contains the full copyright notices and license terms. --> | ||||
| <form> | ||||
|   <label name="party"/> | ||||
|   <field name="party"/> | ||||
|   <label name="number"/> | ||||
|   <field name="number"/> | ||||
|   <label name="pickup_location"/> | ||||
|   <field name="pickup_location"/> | ||||
|   <label name="order_adress"/> | ||||
|   <field name="order_adress"/> | ||||
|   <label name="order_address"/> | ||||
|   <field name="order_address"/> | ||||
|   <label name="order_mobile"/> | ||||
|   <field name="order_mobile"/> | ||||
|   <label name="date"/> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user