Example #1
0
 def cancel_ticket(self, ticket_number=None):
     """cancels a single ticket"""
     try:
         with Transaction().start(DBNAME, 1) as transaction:
             transaction.context = config.get_config().context
             ticket, = self.Ticket.search([('id', '=', ticket_number)])
             if ticket.invoice:
                 return False, 'Cannot cancel,Ticket is used in Invoice:{0}'.format(
                     ticket.invoice.id)
             for i in ticket.lines:
                 if i.remark == 'excess' or i.remark == 'malicious':
                     to_drop = abs(i.quantity - i.excess_quantity)
                     status = self.dishes.cancel_dish(product=i.product,
                                                      quantity=to_drop)
                     if not status:
                         return False
                 else:
                     status = self.dishes.cancel_dish(product=i.product,
                                                      quantity=i.quantity)
                     i.excess_quantity = i.quantity
                     if not status:
                         return False
                 i.state = 'cancel'
                 i.remark = 'normal'
                 i.quantity = int(0)
                 i.save()
             ticket.state = 'cancel'
             ticket.save()
             transaction.cursor.commit()
             return ticket.state, 'Successfully canceled the Ticket'
     except Exception:
         if settings.level == 10:
             logger.exception('raised exception')
         return False, 'Cannot be canceled. Backend Error.'
Example #2
0
 def discard(self, data):
     """
     adds the dish to the wastes for the present day
     :param data:the dictionary of the dish and other details
     :return: boolean value True if the process was successful
     """
     logger.info('WasteMenu discard initiated')
     try:
         with Transaction().start(DBNAME, 1) as transaction:
             transaction.context = config.get_config().context
             item = data['item']
             product = self.Product.search([('name', '=', item), ('description', '=', 'Dish'),
                                            ('type', '=', 'goods')])[-1]
             quantity = Decimal(data['quantity'])
             reason_for_discard = data['reason_for_discard']
             state = self.move(from_location=self.inventory, to_location=self.throw, item=product,
                               quantity=quantity, reason=reason_for_discard)
             transaction.cursor.commit()
             if state:
                 return True
             else:
                 return False
     except Exception:
         if settings.level == 10:
             logger.exception('raised exception')
         return False
Example #3
0
    def check_fiscal_bug(self):
        """check if the fiscal year entry is present"""
        Fiscal = Model.get('account.fiscalyear')
        today = date.today()
        fiscalyear = Fiscal.find(['name', '=', str(today.year)])
        if not fiscalyear:
            company = self.User(id=1).main_company
            from fiscal_year_bug import create_fiscalyear

            create_fiscalyear(company=company,
                              config=config.get_config(),
                              today=today)
def translate_currencies(currencies):
    Currency = Model.get('currency.currency')

    current_config = config.get_config()
    for code in _get_language_codes():
        try:
            gnutranslation = gettext.translation(
                'iso4217', pycountry.LOCALES_DIR, languages=[code])
        except IOError:
            continue
        print("Update currencies %s" % code, file=sys.stderr)
        with current_config.set_context(language=code):
            records = []
            for currency in _progress(pycountry.currencies):
                record = Currency(currencies[currency.alpha_3].id)
                record.name = gnutranslation.gettext(currency.name)
                records.append(record)
            Currency.save(records)
Example #5
0
def translate_countries(countries):
    Country = Model.get('country.country')

    current_config = config.get_config()
    for code in _get_language_codes():
        try:
            gnutranslation = gettext.translation('iso3166',
                                                 pycountry.LOCALES_DIR,
                                                 languages=[code])
        except IOError:
            continue
        print("Update countries %s" % code, file=sys.stderr)
        with current_config.set_context(language=code):
            records = []
            for country in _progress(pycountry.countries):
                record = Country(countries[country.alpha_2].id)
                record.name = _remove_forbidden_chars(
                    gnutranslation.gettext(country.name))
                records.append(record)
            Country.save(records)
def translate_subdivisions(subdivisions):
    Subdivision = Model.get('country.subdivision')

    current_config = config.get_config()
    for code in _get_language_codes():
        try:
            gnutranslation = gettext.translation('iso3166-2',
                                                 pycountry.LOCALES_DIR,
                                                 languages=[code])
        except IOError:
            continue
        print("Update subdivisions %s" % code, file=sys.stderr)
        with current_config.set_context(language=code):
            records = []
            for subdivision in _progress(pycountry.subdivisions):
                record = Subdivision(subdivisions[(subdivision.country_code,
                                                   subdivision.code)].id)
                record.name = gnutranslation.gettext(subdivision.name)
                records.append(record)
            Subdivision.save(records)
Example #7
0
def create_company(party=None, currency=None, config=None):
    "Create the company using the proteus config"
    Party = Model.get('party.party', config=config)
    User = Model.get('res.user', config=config)

    company_config = Wizard('company.company.config')
    company_config.execute('company')
    company = company_config.form
    if not party:
        party = Party(name='Dunder Mifflin')
        party.save()
    company.party = party
    if not currency:
        currency = get_currency()
    company.currency = currency
    company_config.execute('add')

    if not config:
        config = get_config()
    config._context = User.get_preferences(True, {})
    return company_config
Example #8
0
def set_user(user, config=None):
    if not config:
        config = pconfig.get_config()
    User = Model.get('res.user', config=config)
    config.user = int(user)
    config._context = User.get_preferences(True, {})
Example #9
0
def main(database, config_file=None):
    config.set_trytond(database, config_file=config_file)
    with config.get_config().set_context(active_test=False):
        do_import()
Example #10
0
    def start(self, template):
        """
        starts printing
        :param template:
        :return:
        """
        self.html = self.environment.get_template(template)
        con = config.get_config()
        User = Model.get('res.user')
        party = User(id=con.user).main_company.party
        address = party.addresses[-1]

        if self.printformat == 'bill':
            user = {}
            menu_list = self.dataobj[0]
            user['company'] = os.path.join(os.getcwd(), 'printer', 'company.png')
            user['menu'] = menu_list
            data = self.dataobj[1]
            status = data['status']
            if status == 'Paid':
                user['status'] = 'Bill Paid'
            else:
                user['status'] = 'Bill Due'
            user['total'] = data['total']
            user['bill_number'] = str(data['bill_number'])
            user['servicetax'] = data['tax']
            user['servicetax_amount'] = data['tax_amount']
            user['grandtotal'] = data['grand']
            user['roundoff'] = data['roundoff']
            user['name'] = party.name.title()
            user['address'] = address.full_address
            user['date'] = datetime.now().strftime('[%d-%b-%Y] %I:%M %p')
            return self.print_bill(user=user)
        if self.printformat == 'ticket':
            user = {}
            menu_list = self.dataobj[0]
            user['menu'] = menu_list
            data = self.dataobj[1]
            user['ticket_no'] = str(data['ticket_no'])
            user['table_no'] = str(data['table_no'])
            user['name'] = party.name.title()
            user['address'] = address.full_address
            user['date'] = datetime.now().strftime('[%d-%b-%Y] %I:%M %p')
            return self.print_ticket(user=user)
        if self.printformat == 'bill_report':
            user = {}
            menu_list = self.dataobj[0]
            user['menu'] = menu_list
            data = self.dataobj[1]
            user['total'] = str(data['total'])
            user['from_date'] = str(data['from_date'])
            user['to_date'] = str(data['to_date'])
            user['name'] = party.name.title()
            user['address'] = address.full_address
            user['date'] = datetime.now().strftime('[%d-%b-%Y] %I:%M %p')
            return self.print_bill_report(user=user)
        elif self.printformat == 'purchase':
            user = {}
            purchase_list = self.dataobj[0]
            supplier = purchase_list[0]['supplier']
            user['purchase_list'] = purchase_list
            user['company'] = os.path.join(os.getcwd(), 'printer', 'company.png')
            user['batch'] = self.dataobj[1]
            user['name'] = party.name.title()
            user['address'] = address.full_address
            user['date'] = date.today()
            user['supplier'] = supplier
            return self.print_purchase(user=user)
        elif self.printformat == 'stock':
            user = {}
            stock_list = self.dataobj
            user['stock_list'] = stock_list
            user['company'] = os.path.join(os.getcwd(), 'printer', 'company.png')
            user['name'] = party.name.title()
            user['address'] = address.full_address
            user['date'] = date.today()
            return self.print_stock(user=user)
        elif self.printformat == 'payslip':
            user = {}
            pay_slip = self.dataobj
            user['company'] = os.path.join(os.getcwd(), 'printer', 'company.png')
            user['name'] = party.name.title()
            user['address'] = address.full_address
            user['date'] = date.today()
            user['employee'] = pay_slip['employee']
            user['designation'] = pay_slip['designation']
            user['pan'] = pay_slip['pan']
            user['pay_date'] = pay_slip['date'].strftime('%B %Y')
            user['basic_pay'] = str(pay_slip['basic_pay'])
            user['da'] = str(pay_slip['da'])
            user['gross'] = str(pay_slip['gross'])
            user['hra'] = str(pay_slip['hra'])
            user['pf'] = str(pay_slip['pf'])
            user['esi'] = str(pay_slip['esi'])
            user['professional_tax'] = str(pay_slip['professional_tax'])
            user['other_deductions'] = str(pay_slip['other_deductions'])
            user['total_deduction'] = str(pay_slip['total_deduction'])
            user['net'] = str(pay_slip['net'])
            user['rupees'] = str(pay_slip['rupees'])
            return self.print_payslip(user=user)

        else:
            ############################test object instad of selfdataobj
            user = {}
            menu = []
            menu_item = {'date': '10/15/2015', 'code': '542', 'item': 'rice', 'rate': '100', 'amount': '500',
                         'category': 'grains',
                         'quantity': '5', 'supplier': 'id2015'}
            for i in range(50):
                menu.append(menu_item)

            user['menu'] = menu
            user['total'] = '50000'
            user['servicetax'] = '12.5'
            user['grandtotal'] = '51250'
            ##############################
        try: #waste not used pdf format discarded
            handle, destination_file = tempfile.mkstemp(suffix='.pdf')
            # HTML(string=''.join(self.html.generate(user=user)),
            # base_url=os.path.join(os.getcwd(), 'printer')).write_pdf(
            # destination_file)
            pdfkit.from_string(''.join(self.html.generate(user=user)), destination_file)
            if sys.platform == 'win32':
                os.startfile(destination_file, 'print')
            else:
                command = 'lp -t testfile -d {0} {1}'.format(self.printer, destination_file)
                subprocess.call(command.split(), shell=False)
                # with open('lol.html', 'w') as f:
                # print "created file"
                # f.write(''.join(self.html.generate(user=user)))
        except Exception, e:
            print "In Printing", sys.exc_info()
Example #11
0
 def save_ticket(self, dataobj, table_number=None, ticket_number=None):
     """
     :param dataobj: product to be added into the invoice
     :return:id of the invoice and status
     """
     logger.info('SaveTicket saving ticket initiated')
     try:
         with Transaction().start(DBNAME, 1) as transaction:
             transaction.context = config.get_config().context
             if not ticket_number:
                 ticket = self.Ticket()
                 ticket.table_no = int(table_number)
                 ticket.save()
                 for i in dataobj:
                     line = self.TicketLine()
                     product = self.Product.search([('code', '=', i['id']),
                                                    ('description', '=',
                                                     'Dish'),
                                                    ('type', '=', 'goods')])
                     product = product[-1]
                     quantity = int(i['quantity'])
                     counter = self.dishes.calculate_availability(
                         product=product)
                     if counter:
                         if counter >= quantity:
                             status = self.dishes.use_dish(
                                 product=product, quantity=quantity)
                             if not status:
                                 return False, 'Dish not used'
                             line.remark = 'normal'
                         else:
                             excess = quantity - counter
                             status = self.dishes.use_dish(product=product,
                                                           quantity=counter)
                             if not status:
                                 return False, 'Dish not used'
                             line.remark = 'excess'
                             line.excess_quantity = excess
                     else:
                         line.remark = 'excess'
                         line.excess_quantity = quantity
                     line.product = product
                     line.quantity = quantity
                     line.ticket = ticket
                     line.save()
             else:
                 ticket, = self.Ticket.search([('id', '=', ticket_number)])
                 if ticket.invoice:
                     return False, 'The ticket is already billed and hence cannot be modified.'
                 ticket.table_no = int(table_number)
                 for i in dataobj:
                     product = self.Product.search([('code', '=', i['id']),
                                                    ('description', '=',
                                                     'Dish'),
                                                    ('type', '=', 'goods')])
                     if product:
                         product = product[0]
                         quantity = int(i['quantity'])
                         lines = self.TicketLine.search([
                             ('ticket', '=', ticket.id),
                             ('product', '=', product.id)
                         ])
                         for line in lines:
                             if i['state'] == 'processing' or i[
                                     'state'] == 'rejected':
                                 counter = self.dishes.calculate_availability(
                                     product=product)
                                 if line.remark == 'excess':
                                     if counter:
                                         if counter >= line.excess_quantity:
                                             status = self.dishes.use_dish(
                                                 product=product,
                                                 quantity=line.
                                                 excess_quantity)
                                             if not status:
                                                 return False, 'Dish not used'
                                             line.state = 'processing'
                                             line.remark = 'normal'
                                         else:
                                             excess = line.excess_quantity - counter
                                             status = self.dishes.use_dish(
                                                 product=product,
                                                 quantity=counter)
                                             if not status:
                                                 return False, 'Dish not used'
                                             line.remark = 'excess'
                                             line.excess_quantity = excess
                                             line.state = 'processing'
                                     else:
                                         line.remark = 'excess'
                                         line.excess_quantity = line.excess_quantity
                                     line.product = product
                                     line.quantity = quantity
                                     line.ticket = ticket
                                 if line.remark == 'normal':
                                     if line.quantity < quantity:
                                         excess = quantity - line.quantity
                                         if counter >= excess:
                                             status = self.dishes.use_dish(
                                                 product=product,
                                                 quantity=excess)
                                             if not status:
                                                 return False, 'Dish not used'
                                             line.state = 'processing'
                                             line.remark = 'normal'
                                         else:
                                             excess = excess - counter
                                             status = self.dishes.use_dish(
                                                 product=product,
                                                 quantity=counter)
                                             if not status:
                                                 return False, 'Dish not used'
                                             line.state = 'processing'
                                             line.remark = 'excess'
                                             line.excess_quantity = excess
                                     elif line.quantity > quantity:
                                         difference_quantity = line.quantity - quantity
                                         status = self.dishes.cancel_dish(
                                             product=product,
                                             quantity=difference_quantity)
                                         if not status:
                                             return False, 'Dish not reduced'
                                         line.state = 'processing'
                                         line.remark = 'normal'
                                     line.product = product
                                     line.quantity = quantity
                                     line.ticket = ticket
                             elif i['state'] == 'cancel':
                                 state = self.cancel_ticketline(
                                     ticketline=line)
                                 if not state:
                                     return False, 'Could not cancel the Dish'
                             line.state = i[
                                 'state']  # for state=='rejected'
                             line.save()
             ticket.state = 'draft'
             ticket.save()
             data = []
             data.append(str(ticket.id))
             data.append(str(ticket.state))
             data.append(str(ticket.invoice.id if ticket.invoice else None))
             transaction.cursor.commit()
             return data
     except Exception:
         if settings.level == 10:
             logger.exception('raised exception')
         return False, 'Unknown Error'
Example #12
0
 def __init__(self):
     self.conf = config.get_config()
     self.userid = ''
Example #13
0
__email__ = "*****@*****.**"
__status__ = "Developement"

from proteus import config

from trytond.pool import Pool
from trytond.cache import Cache
from trytond.transaction import Transaction
from decimal import Decimal
import logging
from GUI import settings

logger = logging.getLogger(__name__)
logger.setLevel(settings.level)
DBNAME = 'testdbkitchen'
Context = config.get_config().context


class AccessUser():
    """
    Validate the user
    """
    global logger
    with Transaction().start(DBNAME, 1):
        Pool.start()
        pool = Pool(DBNAME)

        # Clean the global cache for multi-instance
        Cache.clean(DBNAME)
        pool.init()
        Tax = pool.get('account.tax')