コード例 #1
0
    def setup_defaults(self):
        """
        Setup the defaults
        """
        with Transaction().set_context(company=None):
            self.usd, = self.Currency.create([{
                'name': 'US Dollar',
                'code': 'USD',
                'symbol': '$',
            }])
            self.party, = self.Party.create([{
                'name': 'Openlabs',
            }])
            self.company, = self.Company.create([{
                'party': self.party.id,
                'currency': self.usd
            }])
        self.User.write(
            [self.User(USER)], {
                'main_company': self.company.id,
                'company': self.company.id,
            }
        )

        CONTEXT.update(self.User.get_preferences(context_only=True))
コード例 #2
0
    def setup_defaults(self):
        """Creates default data for testing
        """
        self.currency, = self.Currency.create([{
            'name': 'US Dollar',
            'code': 'USD',
            'symbol': '$',
        }])

        with Transaction().set_context(company=None):
            company_party, = self.Party.create([{
                'name': 'openlabs'
            }])
            employee_party, = self.Party.create([{
                'name': 'Jim'
            }])

        self.company, = self.Company.create([{
            'party': company_party,
            'currency': self.currency,
        }])

        self.employee, = self.Employee.create([{
            'party': employee_party.id,
            'company': self.company.id,
        }])

        self.User.write([self.User(USER)], {
            'company': self.company,
            'main_company': self.company,
            'employees': [('add', [self.employee.id])],
        })
        # Write employee separately as employees needs to be saved first
        self.User.write([self.User(USER)], {
            'employee': self.employee.id,
        })

        CONTEXT.update(self.User.get_preferences(context_only=True))

        # Create Fiscal Year
        self._create_fiscal_year(company=self.company.id)
        # Create Chart of Accounts
        self._create_coa_minimal(company=self.company.id)
        # Create a payment term
        self.payment_term, = self._create_payment_term()
        self.cash_journal, = self.Journal.search(
            [('type', '=', 'cash')], limit=1
        )

        self.country, = self.Country.create([{
            'name': 'United States of America',
            'code': 'US',
        }])

        self.subdivision, = self.Subdivision.create([{
            'country': self.country.id,
            'name': 'California',
            'code': 'CA',
            'type': 'state',
        }])
コード例 #3
0
    def setup_defaults(self):
        """Creates default data for testing
        """
        self.currency, = self.Currency.create([{
            'name': 'US Dollar',
            'code': 'USD',
            'symbol': '$',
        }])

        with Transaction().set_context(company=None):
            company_party, = self.Party.create([{
                'name': 'openlabs'
            }])
            employee_party, = self.Party.create([{
                'name': 'Jim'
            }])

        self.company, = self.Company.create([{
            'party': company_party,
            'currency': self.currency,
        }])

        self.employee, = self.Employee.create([{
            'party': employee_party.id,
            'company': self.company.id,
        }])

        self.User.write([self.User(USER)], {
            'company': self.company,
            'main_company': self.company,
            'employees': [('add', [self.employee.id])],
        })
        # Write employee separately as employees needs to be saved first
        self.User.write([self.User(USER)], {
            'employee': self.employee.id,
        })

        CONTEXT.update(self.User.get_preferences(context_only=True))

        # Create Fiscal Year
        self._create_fiscal_year(company=self.company.id)
        # Create Chart of Accounts
        self._create_coa_minimal(company=self.company.id)
        # Create a payment term
        self.payment_term, = self._create_payment_term()
        self.cash_journal, = self.Journal.search(
            [('type', '=', 'cash')], limit=1
        )

        self.country, = self.Country.create([{
            'name': 'United States of America',
            'code': 'US',
        }])

        self.subdivision, = self.Subdivision.create([{
            'country': self.country.id,
            'name': 'California',
            'code': 'CA',
            'type': 'state',
        }])
コード例 #4
0
 def test0010_create_shop(self):
     with Transaction().start(DB_NAME, USER,
             context=CONTEXT) as transaction:
         #This is needed in order to get default values for other test
         #executing in the same database
         company, = self.company.search([
                 ('rec_name', '=', 'Dunder Mifflin'),
                 ])
         self.user.write([self.user(USER)], {
                 'main_company': company.id,
                 'company': company.id,
                 })
         CONTEXT.update(self.user.get_preferences(context_only=True))
         with transaction.set_context(company=company.id):
             sequence, = self.sequence.search([
                     ('code', '=', 'sale.sale'),
                     ], limit=1)
             warehouse, = self.location.search([
                     ('code', '=', 'WH'),
                     ])
             price_list, = self.price_list.create([{
                         'name': 'Test',
                         }])
             term, = self.payment_term.create([{
                         'name': 'Payment term',
                         'lines': [
                             ('create', [{
                                         'sequence': 0,
                                         'type': 'remainder',
                                         'days': 0,
                                         'months': 0,
                                         'weeks': 0,
                                         }])]
                         }])
             shop, = self.shop.create([{
                         'name': 'Shop',
                         'warehouse': warehouse.id,
                         'price_list': price_list.id,
                         'payment_term': term.id,
                         'sale_sequence': sequence.id,
                         'sale_invoice_method': 'order',
                         'sale_invoice_method': 'order',
                         }])
             user = self.user(USER)
             self.user.write([user], {
                     'shops': [('add', [shop])],
                     'shop': shop.id,
                      })
         # Clear user values before commiting
         self.user.write([self.user(USER)], {
                 'main_company': None,
                 'company': None,
                 })
         transaction.cursor.commit()
コード例 #5
0
    def setup_defaults(self):
        """
        Creates default data for testing
        """
        currency, = self.Currency.create([{
            'name': 'US Dollar',
            'code': 'USD',
            'symbol': '$',
        }])

        with Transaction().set_context(company=None):
            company_party, = self.Party.create([{
                'name': 'Openlabs'
            }])

        self.company, = self.Company.create([{
            'party': company_party,
            'currency': currency,
        }])

        self.User.write([self.User(USER)], {
            'company': self.company,
            'main_company': self.company,
        })

        CONTEXT.update(self.User.get_preferences(context_only=True))

        # Create Fiscal Year
        self._create_fiscal_year(company=self.company.id)
        # Create Chart of Accounts
        self._create_coa_minimal(company=self.company.id)
        # Create Cash journal
        self.cash_journal, = self.Journal.search(
            [('type', '=', 'cash')], limit=1
        )
        self.Journal.write([self.cash_journal], {
            'debit_account': self._get_account_by_kind('expense').id
        })

        # Create a party
        self.party, = self.Party.create([{
            'name': 'Test party',
            'addresses': [('create', [{
                'name': 'Test Party',
                'street': 'Test Street',
                'city': 'Test City',
            }])],
            'account_receivable': self._get_account_by_kind(
                'receivable').id,
        }])
コード例 #6
0
    def setup_defaults(self):
        """
        Setting up default values.
        """

        usd, = self.Currency.create([{
            'name': 'US Dollar',
            'code': 'USD',
            'symbol': '$',
        }])

        # Create parties
        with Transaction().set_context(company=None):
            self.party, = self.Party.create([{
                'name': 'openlabs',
            }])

        self.company, = self.Company.create([{
            'party': self.party,
            'currency': usd,
        }])

        self.User.write([self.User(USER)], {
            'main_company': self.company.id,
            'company': self.company.id,
        })
        CONTEXT.update(self.User.get_preferences(context_only=True))

        # Create Fiscal Year
        self._create_fiscal_year(company=self.company.id)
        # Create Chart of Accounts
        self._create_coa_minimal(company=self.company.id)

        guest_party, = self.Party.create([{
            'name': 'Guest User',
        }])

        self.party2, = self.Party.create([{
            'name': 'Registered User',
        }])

        self.party3, = self.Party.create([{
            'name': 'Registered User 2',
        }])

        self.party4, = self.Party.create([{
            'name': 'Registered User 3',
        }])

        self.guest_user, = self.NereidUser.create([{
            'party': guest_party.id,
            'name': 'Guest User',
            'email': '*****@*****.**',
            'password': '******',
            'company': self.company.id,
        }])

        # Create test users
        self.registered_user, = self.NereidUser.create([{
            'party':
            self.party2.id,
            'name':
            'Registered User',
            'email':
            '*****@*****.**',
            'password':
            '******',
            'company':
            self.company.id,
        }])
        self.registered_user2, = self.NereidUser.create([{
            'party':
            self.party3.id,
            'name':
            'Registered User 2',
            'email':
            '*****@*****.**',
            'password':
            '******',
            'company':
            self.company.id,
        }])
        self.registered_user3, = self.NereidUser.create([{
            'party':
            self.party4.id,
            'name':
            'Registered User 3',
            'email':
            '*****@*****.**',
            'password':
            '******',
            'company':
            self.company.id,
        }])

        # create countries
        self._create_countries()
        self.available_countries = self.Country.search([], limit=5)

        en_us, = self.Language.search([('code', '=', 'en_US')])

        self.locale_en_us, = self.Locale.create([{
            'code': 'en_US',
            'language': en_us.id,
            'currency': usd.id,
        }])
        warehouse, = self.Location.search([('type', '=', 'warehouse')],
                                          limit=1)
        location, = self.Location.search([('type', '=', 'storage')], limit=1)

        payment_term, = self._create_payment_term()

        shop_price_list = self._create_pricelists()

        with Transaction().set_context(company=self.company.id):
            self.channel, = self.Channel.create([{
                'name':
                'Default channel',
                'price_list':
                shop_price_list,
                'warehouse':
                warehouse,
                'source':
                'webshop',
                'invoice_method':
                'order',
                'shipment_method':
                'order',
                'payment_term':
                payment_term,
                'company':
                self.company.id,
                'create_users': [('add', [USER])]
            }])

        self.User.set_preferences({'current_channel': self.channel})

        self.User.write(
            [self.User(USER)], {
                'main_company': self.company.id,
                'company': self.company.id,
                'current_channel': self.channel,
            })

        self.NereidWebsite.create([{
            'name':
            'localhost',
            'company':
            self.company.id,
            'application_user':
            USER,
            'channel':
            self.channel,
            'default_locale':
            self.locale_en_us.id,
            'warehouse':
            warehouse,
            'stock_location':
            location,
            'countries': [('add', self.available_countries)],
            'guest_user':
            self.guest_user,
        }])
コード例 #7
0
    def setup_defaults(self):
        """Creates default data for testing
        """
        currency, = self.Currency.create([{"name": "US Dollar", "code": "USD", "symbol": "$"}])

        with Transaction().set_context(company=None):
            company_party, = self.Party.create([{"name": "Openlabs"}])

        self.company, = self.Company.create([{"party": company_party, "currency": currency}])

        self.User.write([self.User(USER)], {"company": self.company, "main_company": self.company})

        CONTEXT.update(self.User.get_preferences(context_only=True))

        # Create Fiscal Year
        self._create_fiscal_year(company=self.company.id)
        # Create Chart of Accounts
        self._create_coa_minimal(company=self.company.id)
        # Create a payment term
        self.payment_term, = self._create_payment_term()

        self.cash_journal, = self.Journal.search([("type", "=", "cash")], limit=1)

        # This is required to successfully pay the invoices
        main_cash_account = self._get_account_by_kind("other")

        self.Journal.write([self.cash_journal], {"debit_account": main_cash_account.id})

        self.uom, = self.Uom.search([("symbol", "=", "d")])

        self.country, = self.Country.create([{"name": "United States of America", "code": "US"}])

        self.subdivision, = self.Subdivision.create(
            [{"country": self.country.id, "name": "California", "code": "CA", "type": "state"}]
        )

        # Add address to company's party record
        self.Party.write(
            [self.company.party],
            {
                "addresses": [
                    (
                        "create",
                        [
                            {
                                "name": "Openlabs",
                                "party": Eval("id"),
                                "city": "Los Angeles",
                                "invoice": True,
                                "country": self.country.id,
                                "subdivision": self.subdivision.id,
                            }
                        ],
                    )
                ]
            },
        )

        # Create party
        self.party, = self.Party.create(
            [
                {
                    "name": "Bruce Wayne",
                    "addresses": [
                        (
                            "create",
                            [
                                {
                                    "name": "Bruce Wayne",
                                    "party": Eval("id"),
                                    "city": "Gotham",
                                    "invoice": True,
                                    "country": self.country.id,
                                    "subdivision": self.subdivision.id,
                                }
                            ],
                        )
                    ],
                    "customer_payment_term": self.payment_term.id,
                    "account_receivable": self._get_account_by_kind("receivable").id,
                    "contact_mechanisms": [("create", [{"type": "mobile", "value": "8888888888"}])],
                }
            ]
        )

        self.journal, = self.Journal.search([("type", "=", "revenue")], limit=1)

        self.product_category, = self.ProductCategory.create(
            [
                {
                    "name": "Test Category",
                    "account_revenue": self._get_account_by_kind("revenue", company=self.company.id).id,
                    "account_expense": self._get_account_by_kind("expense", company=self.company.id).id,
                }
            ]
        )

        self.product_template, = self.ProductTemplate.create(
            [
                {
                    "name": "Toy",
                    "type": "goods",
                    "list_price": Decimal("10"),
                    "cost_price": Decimal("5"),
                    "categories": [("add", [self.product_category.id])],
                    "default_uom": self.uom,
                    "account_revenue": self._get_account_by_kind("revenue", company=self.company.id).id,
                    "account_expense": self._get_account_by_kind("expense", company=self.company.id).id,
                }
            ]
        )

        self.product1, = self.Product.create([{"template": self.product_template.id, "code": "toy-1"}])
        self.product2, = self.Product.create([{"template": self.product_template.id, "code": "toy-2"}])

        with Transaction().set_context(use_dummy=True):
            self.dummy_gateway, = self.PaymentGateway.create(
                [
                    {
                        "name": "Dummy Gateway",
                        "journal": self.cash_journal.id,
                        "provider": "dummy",
                        "method": "credit_card",
                    }
                ]
            )
        self.dummy_cc_payment_profile = self.create_payment_profile(self.party, self.dummy_gateway)

        self.cash_gateway, = self.PaymentGateway.create(
            [{"name": "Cash Gateway", "journal": self.cash_journal.id, "provider": "self", "method": "manual"}]
        )
コード例 #8
0
def dataset(request):
    """Create minimal data needed for testing
    """
    from trytond.transaction import Transaction
    from trytond.tests.test_tryton import USER, CONTEXT, DB_NAME, POOL

    Party = POOL.get('party.party')
    Company = POOL.get('company.company')
    Country = POOL.get('country.country')
    Subdivision = POOL.get('country.subdivision')
    Employee = POOL.get('company.employee')
    Currency = POOL.get('currency.currency')
    User = POOL.get('res.user')
    FiscalYear = POOL.get('account.fiscalyear')
    Sequence = POOL.get('ir.sequence')
    AccountTemplate = POOL.get('account.account.template')
    Account = POOL.get('account.account')
    Journal = POOL.get('account.journal')
    PaymentGateway = POOL.get('payment_gateway.gateway')
    AccountCreateChart = POOL.get('account.create_chart', type="wizard")

    with Transaction().start(DB_NAME, USER, context=CONTEXT) as transaction:
        # Create company, employee and set it user's current company
        usd, = Currency.create([{
            'name': 'US Dollar',
            'code': 'USD',
            'symbol': '$',
        }])

        country_us, = Country.create([{
            'name': 'United States',
            'code': 'US',
        }])
        subdivision_florida, = Subdivision.create([{
            'name': 'Florida',
            'code': 'US-FL',
            'country': country_us.id,
            'type': 'state'
        }])
        subdivision_california, = Subdivision.create([{
            'name': 'California',
            'code': 'US-CA',
            'country': country_us.id,
            'type': 'state'
        }])

        company_party, = Party.create([{
            'name': 'ABC Corp.',
            'addresses': [('create', [{
                'name': 'ABC Corp.',
                'street': '247 High Street',
                'zip': '94301-1041',
                'city': 'Palo Alto',
                'country': country_us.id,
                'subdivision': subdivision_california.id,
            }])],
            'contact_mechanisms': [('create', [{
                'type': 'phone',
                'value': '123456789'
            }])]
        }])

        employee_party, = Party.create([{
            'name': 'Prakash Pandey',
        }])
        company, = Company.create([{
            'party': company_party.id,
            'currency': usd.id,
        }])
        employee, = Employee.create([{
            'party': employee_party.id,
            'company': company.id,
        }])
        User.write(
            [User(USER)], {
                'main_company': company.id,
                'company': company.id,
            }
        )
        CONTEXT.update(User.get_preferences(context_only=True))

        # Create fiscal year
        date = datetime.date.today()

        post_move_sequence, = Sequence.create([{
            'name': '%s' % date.year,
            'code': 'account.move',
            'company': company.id,
        }])

        fiscal_year, = FiscalYear.create([{
            'name': '%s' % date.year,
            'start_date': date + relativedelta(month=1, day=1),
            'end_date': date + relativedelta(month=12, day=31),
            'company': company.id,
            'post_move_sequence': post_move_sequence.id,
        }])
        FiscalYear.create_period([fiscal_year])

        # Create minimal chart of account
        account_template, = AccountTemplate.search(
            [('parent', '=', None)]
        )

        session_id, _, _ = AccountCreateChart.create()
        create_chart = AccountCreateChart(session_id)
        create_chart.account.account_template = account_template
        create_chart.account.company = company
        create_chart.transition_create_account()

        receivable, = Account.search([
            ('kind', '=', 'receivable'),
            ('company', '=', company.id),
        ])
        payable, = Account.search([
            ('kind', '=', 'payable'),
            ('company', '=', company.id),
        ])
        create_chart.properties.company = company
        create_chart.properties.account_receivable = receivable
        create_chart.properties.account_payable = payable
        create_chart.transition_create_properties()

        account_revenue, = Account.search([
            ('kind', '=', 'revenue')
        ])
        account_expense, = Account.search([
            ('kind', '=', 'expense')
        ])

        # Create customer
        customer, = Party.create([{
            'name': 'John Doe',
            'addresses': [('create', [{
                'name': 'John Doe',
                'street': '250 NE 25th St',
                'zip': '33137',
                'city': 'Miami, Miami-Dade',
                'country': country_us.id,
                'subdivision': subdivision_florida.id,
            }])],
            'contact_mechanisms': [('create', [{
                'type': 'phone',
                'value': '123456789'
            }])]
        }])

        cash_journal, = Journal.search(
            [('type', '=', 'cash')], limit=1
        )
        Journal.write([cash_journal], {
            'debit_account': account_expense.id
        })

        stripe_gateway = PaymentGateway(
            name='Credit Card - Stripe',
            journal=cash_journal,
            provider='stripe',
            method='credit_card',
            stripe_api_key="sk_test_Xw6QdFU31e8mcmcdeMt7DoiE",
            test=True
        )
        stripe_gateway.save()

        result = {
            'customer': customer,
            'company': company,
            'stripe_gateway': stripe_gateway,
        }

        transaction.cursor.commit()

    def get():
        from trytond.model import Model

        for key, value in result.iteritems():
            if isinstance(value, Model):
                result[key] = value.__class__(value.id)
        return namedtuple('Dataset', result.keys())(**result)

    return get
コード例 #9
0
def dataset(request):
    """Create minimal data needed for testing
    """
    from trytond.transaction import Transaction
    from trytond.tests.test_tryton import USER, CONTEXT, DB_NAME, POOL

    Party = POOL.get('party.party')
    Company = POOL.get('company.company')
    Country = POOL.get('country.country')
    Subdivision = POOL.get('country.subdivision')
    Employee = POOL.get('company.employee')
    Currency = POOL.get('currency.currency')
    SequenceStrict = POOL.get('ir.sequence.strict')
    User = POOL.get('res.user')
    FiscalYear = POOL.get('account.fiscalyear')
    Sequence = POOL.get('ir.sequence')
    AccountTemplate = POOL.get('account.account.template')
    Account = POOL.get('account.account')
    ProductTemplate = POOL.get('product.template')
    Product = POOL.get('product.product')
    Uom = POOL.get('product.uom')
    Carrier = POOL.get('carrier')
    PaymentTerm = POOL.get('account.invoice.payment_term')
    FedExShipmentMethod = POOL.get('fedex.shipment.method')
    StockLocation = POOL.get('stock.location')
    SaleConfiguration = POOL.get('sale.configuration')
    AccountCreateChart = POOL.get('account.create_chart', type="wizard")

    with Transaction().start(DB_NAME, USER, context=CONTEXT) as transaction:
        # Create company, employee and set it user's current company
        usd, = Currency.create([{
            'name': 'US Dollar',
            'code': 'USD',
            'symbol': '$',
        }])

        country_us, = Country.create([{
            'name': 'United States',
            'code': 'US',
        }])
        subdivision_florida, = Subdivision.create([{
            'name': 'Florida',
            'code': 'US-FL',
            'country': country_us.id,
            'type': 'state'
        }])
        subdivision_california, = Subdivision.create([{
            'name': 'California',
            'code': 'US-CA',
            'country': country_us.id,
            'type': 'state'
        }])

        company_party, = Party.create([{
            'name': 'ABC Corp.',
            'addresses': [('create', [{
                'name': 'ABC Corp.',
                'street': '247 High Street',
                'zip': '94301-1041',
                'city': 'Palo Alto',
                'country': country_us.id,
                'subdivision': subdivision_california.id,
            }])],
            'contact_mechanisms': [('create', [{
                'type': 'phone',
                'value': '123456789'
            }])]
        }])

        employee_party, = Party.create([{
            'name': 'Prakash Pandey',
        }])
        company, = Company.create([{
            'party': company_party.id,
            'currency': usd.id,
        }])
        employee, = Employee.create([{
            'party': employee_party.id,
            'company': company.id,
        }])
        User.write(
            [User(USER)], {
                'main_company': company.id,
                'company': company.id,
            }
        )
        CONTEXT.update(User.get_preferences(context_only=True))

        # Set warehouse address as company address
        StockLocation.write(
            StockLocation.search([('type', '=', 'warehouse')]), {
                'address': company_party.addresses[0].id,
            }
        )

        # Create fiscal year
        date = datetime.date.today()

        post_move_sequence, = Sequence.create([{
            'name': '%s' % date.year,
            'code': 'account.move',
            'company': company.id,
        }])
        invoice_sequence, = SequenceStrict.create([{
            'name': '%s' % date.year,
            'code': 'account.invoice',
            'company': company.id,
        }])

        fiscal_year, = FiscalYear.create([{
            'name': '%s' % date.year,
            'start_date': date + relativedelta(month=1, day=1),
            'end_date': date + relativedelta(month=12, day=31),
            'company': company.id,
            'post_move_sequence': post_move_sequence.id,
            'out_invoice_sequence': invoice_sequence.id,
            'in_invoice_sequence': invoice_sequence.id,
            'out_credit_note_sequence': invoice_sequence.id,
            'in_credit_note_sequence': invoice_sequence.id,
        }])
        FiscalYear.create_period([fiscal_year])

        # Create minimal chart of account
        account_template, = AccountTemplate.search(
            [('parent', '=', None)]
        )

        session_id, _, _ = AccountCreateChart.create()
        create_chart = AccountCreateChart(session_id)
        create_chart.account.account_template = account_template
        create_chart.account.company = company
        create_chart.transition_create_account()

        receivable, = Account.search([
            ('kind', '=', 'receivable'),
            ('company', '=', company.id),
        ])
        payable, = Account.search([
            ('kind', '=', 'payable'),
            ('company', '=', company.id),
        ])
        create_chart.properties.company = company
        create_chart.properties.account_receivable = receivable
        create_chart.properties.account_payable = payable
        create_chart.transition_create_properties()

        account_revenue, = Account.search([
            ('kind', '=', 'revenue')
        ])

        # Create payment term
        payment_term, = PaymentTerm.create([{
            'name': 'Direct',
            'lines': [
                ('create', [{
                    'type': 'remainder'
                }])
            ]
        }])

        # Create Products
        uom_pound, = Uom.search([('symbol', '=', 'lb')])
        uom_unit, = Uom.search([('symbol', '=', 'u')])
        uom_day, = Uom.search([('symbol', '=', 'd')])

        product_template, = ProductTemplate.create([{
            'name': 'KindleFire',
            'type': 'goods',
            'salable': True,
            'sale_uom': uom_unit.id,
            'list_price': Decimal('119'),
            'cost_price': Decimal('100'),
            'default_uom': uom_unit.id,
            'account_revenue': account_revenue.id,
            'weight': .7,
            'weight_uom': uom_pound.id,
            'products': [],
        }])

        product1, product2 = Product.create([{
            'code': 'ABC',
            'template': product_template.id,
        }, {
            'code': 'MAD',
            'template': product_template.id,
        }])

        # Create carrier
        carrier_party, = Party.create([{
            'name': 'FedEx',
        }])
        fedex_carrier_product_template, = ProductTemplate.create([{
            'name': 'FedEx Carrier Product',
            'type': 'service',
            'salable': True,
            'sale_uom': uom_day,
            'list_price': Decimal('0'),
            'cost_price': Decimal('0'),
            'default_uom': uom_day,
            'cost_price_method': 'fixed',
            'account_revenue': account_revenue.id,
            'products': [('create', [{
                'code': '001',
            }])]
        }])
        fedex_carrier_product, = fedex_carrier_product_template.products

        fedex_carrier, = Carrier.create([{
            'party': carrier_party.id,
            'carrier_product': fedex_carrier_product.id,
            'currency': usd.id,
            'carrier_cost_method': 'fedex',
            'fedex_key': 'w8B7YBVgtfnDgn0k',
            'fedex_account_number': '510088000',
            'fedex_password': '******',
            'fedex_meter_number': '118518591',
            'fedex_integrator_id': '123',
            'fedex_product_id': 'TEST',
            'fedex_product_version': '9999',
        }])

        # Create customer
        customer, = Party.create([{
            'name': 'John Doe',
            'addresses': [('create', [{
                'name': 'John Doe',
                'street': '250 NE 25th St',
                'zip': '33137',
                'city': 'Miami, Miami-Dade',
                'country': country_us.id,
                'subdivision': subdivision_florida.id,
            }])],
            'contact_mechanisms': [('create', [{
                'type': 'phone',
                'value': '123456789'
            }])]
        }])

        def get_fedex_drop_off_type(value):
            res, = FedExShipmentMethod.search([
                ('method_type', '=', 'dropoff'),
                ('value', '=', value),
            ])
            return res.id

        def get_fedex_packaging_type(value):
            res, = FedExShipmentMethod.search([
                ('method_type', '=', 'packaging'),
                ('value', '=', value),
            ])
            return res.id

        def get_fedex_service_type(value):
            res, = FedExShipmentMethod.search([
                ('method_type', '=', 'service'),
                ('value', '=', value),
            ])
            return res.id

        sale_config = SaleConfiguration(1)
        sale_config.fedex_drop_off_type = \
            get_fedex_drop_off_type('REGULAR_PICKUP')
        sale_config.fedex_packaging_type = \
            get_fedex_packaging_type('FEDEX_BOX')
        sale_config.fedex_service_type = get_fedex_service_type('FEDEX_2_DAY')
        sale_config.save()

        result = {
            'customer': customer,
            'company': company,
            'product1': product1,
            'product2': product2,
            'fedex_carrier': fedex_carrier,
            'currency_usd': usd,
            'payment_term': payment_term,
            'uom_unit': uom_unit,
            'get_fedex_drop_off_type': get_fedex_drop_off_type,
            'get_fedex_packaging_type': get_fedex_packaging_type,
            'get_fedex_service_type': get_fedex_service_type,
        }

        transaction.cursor.commit()

    def get():
        from trytond.model import Model

        for key, value in result.iteritems():
            if isinstance(value, Model):
                result[key] = value.__class__(value.id)
        return namedtuple('Dataset', result.keys())(**result)

    return get
コード例 #10
0
    def setup_defaults(self):
        """Creates default data for testing
        """
        self.country, = self.Country.create([{
            'name': 'United States of America',
            'code': 'US',
        }])
        self.subdivision, = self.Subdivision.create([{
            'country': self.country.id,
            'name': 'California',
            'code': 'CA',
            'type': 'state',
        }])

        self.currency, = self.Currency.create([{
            'name': 'US Dollar',
            'code': 'USD',
            'symbol': '$',
        }])

        with Transaction().set_context(company=None):
            company_party, = self.Party.create([{
                'name': 'openlabs'
            }])

        self.company, = self.Company.create([{
            'party': company_party,
            'currency': self.currency,
        }])

        self.User.write([self.User(USER)], {
            'company': self.company,
            'main_company': self.company,
        })
        CONTEXT.update(self.User.get_preferences(context_only=True))

        # Create Fiscal Year
        self._create_fiscal_year(company=self.company.id)
        # Create Chart of Accounts
        self._create_coa_minimal(company=self.company.id)
        # Create a payment term
        self.payment_term, = self._create_payment_term()

        self.cash_journal, = self.Journal.search(
            [('type', '=', 'cash')], limit=1
        )
        self.Journal.write([self.cash_journal], {
            'debit_account': self._get_account_by_kind('other').id
        })

        # Create party
        self.party, = self.Party.create([{
            'name': 'Bruce Wayne',
            'addresses': [('create', [{
                'name': 'Bruce Wayne',
                'party': Eval('id'),
                'city': 'Gotham',
                'invoice': True,
                'country': self.country.id,
                'subdivision': self.subdivision.id,
            }])],
            'customer_payment_term': self.payment_term.id,
            'account_receivable': self._get_account_by_kind(
                'receivable').id,
            'contact_mechanisms': [('create', [
                {'type': 'email', 'value': '*****@*****.**'},
            ])],
        }])

        self.uom, = self.Uom.search([('name', '=', 'Unit')])
        self.product_category, = self.ProductCategory.create([{
            'name': 'Automobile',
            'account_revenue': self._get_account_by_kind(
                'revenue', company=self.company.id).id,
            'account_expense': self._get_account_by_kind(
                'expense', company=self.company.id).id,
        }])

        self.product_template, = self.ProductTemplate.create([{
            'name': 'Bat Mobile',
            'type': 'goods',
            'salable': True,
            'category': self.product_category.id,
            'default_uom': self.uom.id,
            'sale_uom': self.uom.id,
            'list_price': Decimal('20000'),
            'cost_price': Decimal('15000'),
            'account_category': True,
        }])

        self.product, = self.Product.create([{
            'template': self.product_template.id,
            'code': '123',
        }])
コード例 #11
0
    def setup_defaults(self):
        """Creates default data for testing
        """
        currency, = self.Currency.create([{
            'name': 'US Dollar',
            'code': 'USD',
            'symbol': '$',
        }])

        with Transaction().set_context(company=None):
            company_party, = self.Party.create([{'name': 'Openlabs'}])

        self.company, = self.Company.create([{
            'party': company_party,
            'currency': currency,
        }])

        self.User.write([self.User(USER)], {
            'company': self.company,
            'main_company': self.company,
        })

        CONTEXT.update(self.User.get_preferences(context_only=True))

        self.uom, = self.Uom.search([('symbol', '=', 'u')])

        self.country, = self.Country.create([{
            'name': 'United States of America',
            'code': 'US',
        }])

        self.subdivision, = self.Subdivision.create([{
            'country': self.country.id,
            'name': 'California',
            'code': 'CA',
            'type': 'state',
        }])

        # Add address to company's party record
        self.Party.write(
            [self.company.party], {
                'addresses': [('create', [{
                    'name': 'Openlabs',
                    'party': Eval('id'),
                    'city': 'Los Angeles',
                    'country': self.country.id,
                    'subdivision': self.subdivision.id,
                }])],
            })

        self.product_category, = self.ProductCategory.create([{
            'name':
            'Automobile',
        }])

        self.product_template, = self.ProductTemplate.create([{
            'name':
            'Bat Mobile',
            'type':
            'goods',
            'list_price':
            Decimal('2000'),
            'cost_price':
            Decimal('1500'),
            'category':
            self.product_category.id,
            'default_uom':
            self.uom,
        }])

        self.product, = self.Product.create([{
            'template':
            self.product_template.id,
            'code':
            '123',
        }])

        self.warehouse, = self.Location.search([('code', '=', 'WH')])
コード例 #12
0
    def setup_defaults(self):
        """Method to setup defaults
        """
        # Create currency
        self.currency, = self.Currency.create([{
            'name': 'Euro',
            'code': 'EUR',
            'symbol': 'EUR',
        }])

        country_de, country_tw = self.Country.create([{
            'name': 'Germany',
            'code': 'DE',
        }, {
            'name': 'Taiwan',
            'code': 'TW',
        }])

        subdivision_bw, = self.Subdivision.create([{
            'name': 'Baden-Württemberg',
            'code': 'DE-BW',
            'type': 'state',
            'country': country_de.id,
        }])

        with Transaction().set_context(company=None):
            company_party, = self.Party.create([{
                'name':
                'Orkos',
                'vat_number':
                '123456',
                'addresses': [('create', [{
                    'name': 'Fruchtzentrale Orkos',
                    'street': 'Luetzowstr. 28a',
                    'streetbis': '',
                    'zip': '45141',
                    'city': 'Dortmund',
                    'country': country_de.id,
                }])],
                'contact_mechanisms': [('create', [{
                    'type': 'phone',
                    'value': '030244547777778',
                }, {
                    'type': 'email',
                    'value': '*****@*****.**',
                }, {
                    'type': 'fax',
                    'value': '030244547777778',
                }, {
                    'type': 'mobile',
                    'value': '9876543212',
                }, {
                    'type': 'website',
                    'value': 'example.com',
                }])],
            }])

        self.company, = self.Company.create([{
            'party': company_party.id,
            'currency': self.currency.id,
        }])

        self.User.write([self.User(USER)], {
            'main_company': self.company.id,
            'company': self.company.id,
        })

        CONTEXT.update(self.User.get_preferences(context_only=True))

        self._create_fiscal_year(company=self.company)
        self._create_coa_minimal(company=self.company)
        self.payment_term, = self._create_payment_term()

        account_revenue, = self.Account.search([('kind', '=', 'revenue')])

        # Create product category
        category, = self.Category.create([{
            'name': 'Test Category',
        }])

        uom_kg, = self.Uom.search([('symbol', '=', 'kg')])
        uom_cm, = self.Uom.search([('symbol', '=', 'cm')])
        uom_pound, = self.Uom.search([('symbol', '=', 'lb')])

        # Carrier Carrier Product
        carrier_product_template, = self.Template.create([{
            'name':
            'Test Carrier Product',
            'category':
            category.id,
            'type':
            'service',
            'salable':
            True,
            'sale_uom':
            uom_kg,
            'list_price':
            Decimal('10'),
            'cost_price':
            Decimal('5'),
            'default_uom':
            uom_kg,
            'cost_price_method':
            'fixed',
            'account_revenue':
            account_revenue.id,
            'products': [('create', self.Template.default_products())]
        }])

        carrier_product = carrier_product_template.products[0]

        # Create product
        template, = self.Template.create([{
            'name':
            'Test Product',
            'category':
            category.id,
            'type':
            'goods',
            'salable':
            True,
            'sale_uom':
            uom_kg,
            'list_price':
            Decimal('10'),
            'cost_price':
            Decimal('5'),
            'default_uom':
            uom_kg,
            'account_revenue':
            account_revenue.id,
            'weight':
            .5,
            'weight_uom':
            uom_pound.id,
            'products': [('create', self.Template.default_products())]
        }])

        self.product = template.products[0]

        # Create party
        carrier_party, = self.Party.create([{
            'name': 'Test Party',
        }])

        # Create party
        carrier_party, = self.Party.create([{
            'name': 'Test Party',
        }])

        values = {
            'party': carrier_party.id,
            'currency': self.company.currency.id,
            'carrier_product': carrier_product.id,
            'carrier_cost_method': 'gls',
            'gls_server': self.gls_server,
            'gls_port': self.gls_port,
            'gls_contract': self.gls_contract,
            'gls_customer_id': '2760179437',
            'gls_location': 'DE 460',
            'gls_shipping_depot_number': '46',
            'gls_is_test': True,
            'gls_customer_number': '15082',
            'gls_consignor_label': 'Empfanger',
            'gls_customer_id_label': 'ID-Nr',
            'gls_customer_label': 'Kd-Nr',
        }

        self.carrier, = self.Carrier.create([values])

        self.sale_party, self.sale_party2 = self.Party.create([{
            'name':
            'GLS Germany',
            'vat_number':
            '123456',
            'addresses': [('create', [{
                'name': 'GLS Germany',
                'street': 'Huckarder Str. 91',
                'streetbis': '',
                'zip': '44147',
                'city': 'Dortmund',
                'country': country_de.id,
                'subdivision': subdivision_bw.id,
            }])],
            'contact_mechanisms': [('create', [{
                'type': 'phone',
                'value': '+886 2 27781-8',
            }, {
                'type': 'email',
                'value': '*****@*****.**',
            }])],
        }, {
            'name':
            'Klammer Company',
            'vat_number':
            '123456',
            'addresses': [('create', [{
                'name': 'John Wick',
                'street': 'Chung Hsiao East Road.',
                'streetbis': '55',
                'zip': '100',
                'city': 'Taipeh',
                'country': country_tw.id,
            }])],
            'contact_mechanisms': [('create', [{
                'type': 'phone',
                'value': '+886 2 27781-8',
            }, {
                'type': 'email',
                'value': '*****@*****.**',
            }])],
        }])
        sale_config = self.SaleConfig()
        sale_config.save()
コード例 #13
0
    def setup_defaults(self):
        """Creates default data for testing
        """

        self.currency, = self.Currency.create([{
            'name': 'US Dollar',
            'code': 'USD',
            'symbol': '$',
        }])

        with Transaction().set_context(company=None):
            self.company_party, = self.Party.create([{
                'name': 'openlabs',
            }])

        self.company, = self.Company.create([{
            'party': self.company_party,
            'currency': self.currency,
        }])
        self.User.write([self.User(USER)], {
            'company': self.company,
            'main_company': self.company,
        })

        CONTEXT.update(self.User.get_preferences(context_only=True))

        self.country, = self.Country.create([{
            'name': 'United States of America',
            'code': 'US',
        }])
        self.subdivision, = self.Subdivision.create([{
            'country': self.country.id,
            'name': 'California',
            'code': 'CA',
            'type': 'state',
        }])

        self.party, = self.Party.create([{
            'name':
            'Bruce Wayne',
            'addresses': [('create', [{
                'name': 'Bruce Wayne',
                'party': Eval('id'),
                'city': 'Gotham',
                'country': self.country.id,
                'subdivision': self.subdivision.id,
            }])],
            'contact_mechanisms': [('create', [
                {
                    'type': 'mobile',
                    'value': '8888888888'
                },
            ])],
        }])
        self.Party.write(
            [self.company.party], {
                'addresses': [('create', [{
                    'name': 'Lie Nielsen',
                    'city': 'Los Angeles',
                    'country': self.country.id,
                    'subdivision': self.subdivision.id,
                }])],
            })
        self.product_category, = self.ProductCategory.create([{
            'name':
            'Automobile',
        }])
        self.uom, = self.Uom.search([('name', '=', 'Unit')])

        self.product_template, = self.ProductTemplate.create([{
            'name':
            'Bat Mobile',
            'type':
            'goods',
            'category':
            self.product_category.id,
            'list_price':
            Decimal('20000'),
            'cost_price':
            Decimal('15000'),
            'default_uom':
            self.uom.id,
        }])
        self.product, = self.Product.create([{
            'template':
            self.product_template.id,
            'code':
            '123',
        }])
コード例 #14
0
    def setup_defaults(self):
        """Method to setup defaults
        """
        # Create currency
        self.currency, = self.Currency.create([{"name": "Euro", "code": "EUR", "symbol": "EUR"}])

        country_de, country_tw = self.Country.create(
            [{"name": "Germany", "code": "DE"}, {"name": "Taiwan", "code": "TW"}]
        )

        subdivision_bw, = self.Subdivision.create(
            [{"name": "Baden-Württemberg", "code": "DE-BW", "type": "state", "country": country_de.id}]
        )

        with Transaction().set_context(company=None):
            company_party, = self.Party.create(
                [
                    {
                        "name": "Deutsche Post IT Brief GmbH",
                        "vat_number": "123456",
                        "addresses": [
                            (
                                "create",
                                [
                                    {
                                        "name": "Max Muster",
                                        "street": "Heinrich-Bruening-Str.",
                                        "streetbis": "7",
                                        "zip": "53113",
                                        "city": "Bonn",
                                        "country": country_de.id,
                                    }
                                ],
                            )
                        ],
                        "contact_mechanisms": [
                            (
                                "create",
                                [
                                    {"type": "phone", "value": "030244547777778"},
                                    {"type": "email", "value": "*****@*****.**"},
                                    {"type": "fax", "value": "030244547777778"},
                                    {"type": "mobile", "value": "9876543212"},
                                    {"type": "website", "value": "example.com"},
                                ],
                            )
                        ],
                    }
                ]
            )

        self.company, = self.Company.create([{"party": company_party.id, "currency": self.currency.id}])

        self.User.write([self.User(USER)], {"main_company": self.company.id, "company": self.company.id})

        CONTEXT.update(self.User.get_preferences(context_only=True))

        self._create_fiscal_year(company=self.company)
        self._create_coa_minimal(company=self.company)
        self.payment_term, = self._create_payment_term()

        account_revenue, = self.Account.search([("kind", "=", "revenue")])

        # Create product category
        category, = self.Category.create([{"name": "Test Category"}])

        uom_kg, = self.Uom.search([("symbol", "=", "kg")])
        uom_cm, = self.Uom.search([("symbol", "=", "cm")])
        uom_pound, = self.Uom.search([("symbol", "=", "lb")])

        # Carrier Carrier Product
        carrier_product_template, = self.Template.create(
            [
                {
                    "name": "Test Carrier Product",
                    "category": category.id,
                    "type": "service",
                    "salable": True,
                    "sale_uom": uom_kg,
                    "list_price": Decimal("10"),
                    "cost_price": Decimal("5"),
                    "default_uom": uom_kg,
                    "cost_price_method": "fixed",
                    "account_revenue": account_revenue.id,
                    "products": [("create", self.Template.default_products())],
                }
            ]
        )

        carrier_product = carrier_product_template.products[0]

        # Create product
        template, = self.Template.create(
            [
                {
                    "name": "Test Product",
                    "category": category.id,
                    "type": "goods",
                    "salable": True,
                    "sale_uom": uom_kg,
                    "list_price": Decimal("10"),
                    "cost_price": Decimal("5"),
                    "default_uom": uom_kg,
                    "account_revenue": account_revenue.id,
                    "weight": 0.5,
                    "weight_uom": uom_pound.id,
                    "products": [("create", self.Template.default_products())],
                }
            ]
        )

        self.product = template.products[0]

        # Create party
        carrier_party, = self.Party.create([{"name": "Test Party"}])

        # Create party
        carrier_party, = self.Party.create([{"name": "Test Party"}])

        values = {
            "party": carrier_party.id,
            "currency": self.currency.id,
            "carrier_product": carrier_product.id,
            "carrier_cost_method": "dhl_de",
            "dhl_de_username": self.username,
            "dhl_de_password": self.password,
            "dhl_de_api_user": "******",
            "dhl_de_api_signature": "Dhl_ep_test1",
            "dhl_de_account_no": "5000000008 72 01",
        }

        self.carrier, = self.Carrier.create([values])

        self.sale_party, self.sale_party2 = self.Party.create(
            [
                {
                    "name": "Klammer Company",
                    "vat_number": "123456",
                    "addresses": [
                        (
                            "create",
                            [
                                {
                                    "name": "Kai Wahn",
                                    "street": "Marktplatz",
                                    "streetbis": "1",
                                    "zip": "70173",
                                    "city": "Stuttgart",
                                    "country": country_de.id,
                                    "subdivision": subdivision_bw.id,
                                }
                            ],
                        )
                    ],
                    "contact_mechanisms": [
                        (
                            "create",
                            [{"type": "phone", "value": "+886 2 27781-8"}, {"type": "email", "value": "*****@*****.**"}],
                        )
                    ],
                },
                {
                    "name": "Klammer Company",
                    "vat_number": "123456",
                    "addresses": [
                        (
                            "create",
                            [
                                {
                                    "name": "John Wick",
                                    "street": "Chung Hsiao East Road.",
                                    "streetbis": "55",
                                    "zip": "100",
                                    "city": "Taipeh",
                                    "country": country_tw.id,
                                }
                            ],
                        )
                    ],
                    "contact_mechanisms": [
                        (
                            "create",
                            [{"type": "phone", "value": "+886 2 27781-8"}, {"type": "email", "value": "*****@*****.**"}],
                        )
                    ],
                },
            ]
        )
        sale_config = self.SaleConfig()
        sale_config.save()
コード例 #15
0
    def setup_defaults(self):
        """
        Setup the defaults
        """
        with Transaction().set_context(company=None):
            self.usd, = self.Currency.create([{
                'name': 'US Dollar',
                'code': 'USD',
                'symbol': '$',
            }])
            self.party, = self.Party.create([{
                'name': 'Openlabs',
            }])
            self.company, = self.Company.create([{
                'party': self.party.id,
                'currency': self.usd
            }])
        self.User.write([self.User(USER)], {
            'main_company': self.company.id,
            'company': self.company.id,
        })

        CONTEXT.update(self.User.get_preferences(context_only=True))

        # Create Fiscal Year
        self._create_fiscal_year(company=self.company.id)
        # Create Chart of Accounts
        self._create_coa_minimal(company=self.company.id)
        # Create a payment term
        payment_term, = self._create_payment_term()

        channel_price_list, user_price_list = self._create_pricelists()

        party1, = self.Party.create([{
            'name': 'Guest User',
        }])

        party2, = self.Party.create([{
            'name': 'Registered User',
            'sale_price_list': user_price_list,
        }])

        party3, = self.Party.create([{
            'name': 'Registered User 2',
        }])

        # Create users and assign the pricelists to them
        self.guest_user, = self.NereidUser.create([{
            'party': party1.id,
            'display_name': 'Guest User',
            'email': '*****@*****.**',
            'password': '******',
            'company': self.company.id,
        }])
        self.registered_user, = self.NereidUser.create([{
            'party':
            party2.id,
            'display_name':
            'Registered User',
            'email':
            '*****@*****.**',
            'password':
            '******',
            'company':
            self.company.id,
        }])
        self.registered_user2, = self.NereidUser.create([{
            'party':
            party3.id,
            'display_name':
            'Registered User 2',
            'email':
            '*****@*****.**',
            'password':
            '******',
            'company':
            self.company.id,
        }])

        self._create_countries()
        self.available_countries = self.Country.search([], limit=5)

        warehouse, = self.Location.search([('type', '=', 'warehouse')],
                                          limit=1)
        location, = self.Location.search([('type', '=', 'storage')], limit=1)
        en_us, = self.Language.search([('code', '=', 'en_US')])

        self.locale_en_us, = self.Locale.create([{
            'code': 'en_US',
            'language': en_us.id,
            'currency': self.usd.id,
        }])

        self.sale_tax, = self.Tax.create([{
            'name':
            'Sales Tax',
            'description':
            'Sales Tax',
            'type':
            'percentage',
            'rate':
            Decimal('0.05'),  # Rate 5%
            'company':
            self.company.id,
            'invoice_account':
            self._get_account_by_kind('other').id,
            'credit_note_account':
            self._get_account_by_kind('other').id,
        }])

        with Transaction().set_context(company=self.company.id):
            self.channel, = self.SaleChannel.create([{
                'name':
                'Default Channel',
                'price_list':
                channel_price_list,
                'invoice_method':
                'order',
                'shipment_method':
                'order',
                'source':
                'manual',
                'create_users': [('add', [USER])],
                'warehouse':
                warehouse,
                'payment_term':
                payment_term,
                'company':
                self.company.id,
            }])

        self.User.set_preferences({'current_channel': self.channel})

        self.User.write(
            [self.User(USER)], {
                'main_company': self.company.id,
                'company': self.company.id,
                'current_channel': self.channel,
            })

        self.create_website()

        # Create product templates with products
        self.template1, = self._create_product_template(
            'product-1',
            [{
                'type': 'goods',
                'salable': True,
                'list_price': Decimal('10'),
                'cost_price': Decimal('5'),
                'account_expense': self._get_account_by_kind('expense').id,
                'account_revenue': self._get_account_by_kind('revenue').id,
            }],
            uri='product-1',
        )
        self.template2, = self._create_product_template(
            'product-2',
            [{
                'type': 'goods',
                'salable': True,
                'list_price': Decimal('15'),
                'cost_price': Decimal('5'),
                'account_expense': self._get_account_by_kind('expense').id,
                'account_revenue': self._get_account_by_kind('revenue').id,
            }],
            uri='product-2',
        )
        self.product1 = self.template1.products[0]
        self.product2 = self.template2.products[0]
コード例 #16
0
    def setup_defaults(self):
        '''
        Setup defaults for test
        '''
        usd, = self.Currency.create([{
            'name': 'US Dollar',
            'code': 'USD',
            'symbol': '$',
        }])
        self.Country.create([{
            'name': 'India',
            'code': 'IN',
        }])
        self.country, = self.Country.search([])

        with Transaction().set_context(company=None):
            company_party, = self.Party.create([{
                'name': 'Openlabs',
            }])
            self.company, = self.Company.create([{
                'party': company_party,
                'currency': usd,
            }])

        self.User.write([self.User(USER)], {
            'company': self.company,
            'main_company': self.company,
        })
        CONTEXT.update(self.User.get_preferences(context_only=True))

        self._create_fiscal_year(company=self.company.id)
        self._create_coa_minimal(company=self.company.id)

        guest_party, = self.Party.create([{
            'name': 'Guest User',
        }])

        self.guest_user, = self.NereidUser.create([{
            'party': guest_party,
            'display_name': 'Guest User',
            'email': '*****@*****.**',
            'password': '******',
            'company': self.company.id,
        }])

        admin_party1, = self.Party.create([{
            'name': 'Crm Admin',
        }])
        self.crm_admin, = self.NereidUser.create([{
            'party': admin_party1,
            'display_name': 'Crm Admin',
            'email': '*****@*****.**',
            'password': '******',
            'company': self.company.id,
        }])
        employee, = self.Employee.create([{
            'company': self.company.id,
            'party': self.crm_admin.party.id,
        }])

        self.Config.write([self.Config(1)], {'website_employee': employee.id})

        self.NereidUser.write([self.crm_admin], {
            'employee': employee.id,
        })

        admin_party2, = self.Party.create([{
            'name': 'Crm Admin2',
        }])

        self.crm_admin2, = self.NereidUser.create([{
            'party': admin_party2,
            'display_name': 'Crm Admin2',
            'email': '*****@*****.**',
            'password': '******',
            'company': self.company.id,
        }])
        employee, = self.Employee.create([{
            'company': self.company.id,
            'party': self.crm_admin2.party.id,
        }])
        self.NereidUser.write([self.crm_admin2], {
            'employee': employee.id,
        })

        url_map, = self.UrlMap.search([], limit=1)
        en_us, = self.Language.search([('code', '=', 'en_US')])
        locale_en, = self.Locale.create([{
            'code': 'en_US',
            'language': en_us.id,
            'currency': usd.id,
        }])
        self.NereidWebsite.create([{
            'name': 'localhost',
            'url_map': url_map,
            'company': self.company,
            'application_user': USER,
            'default_locale': locale_en.id,
            'guest_user': self.guest_user,
        }])

        perm_admin, = self.NereidPermission.search([
            ('value', '=', 'sales.admin'),
        ])
        self.NereidUser.write([self.crm_admin],
                              {'permissions': [('set', [perm_admin])]})
        self.Company.write([self.company],
                           {'sales_team': [('add', [self.crm_admin])]})
コード例 #17
0
    def setup_defaults(self):
        """
        Setup defaults
        """
        usd, = self.Currency.create([{
            'name': 'US Dollar',
            'code': 'USD',
            'symbol': '$',
        }])

        with Transaction().set_context(company=None):
            company_party, = self.Party.create([{
                'name':
                'Openlabs',
                'addresses': [('create', [{
                    'name': 'Openlabs',
                }])],
            }])

        self.company, = self.Company.create([{
            'party': company_party.id,
            'currency': usd,
        }])

        self.User.write([self.User(USER)], {
            'company': self.company,
            'main_company': self.company,
        })

        CONTEXT.update(self.User.get_preferences(context_only=True))

        # Create Fiscal Year
        self._create_fiscal_year(company=self.company.id)
        # Create Chart of Accounts
        self._create_coa_minimal(company=self.company.id)
        # Create a payment term
        payment_term, = self._create_payment_term()

        channel_price_list, user_price_list = self._create_pricelists()
        party1, = self.Party.create([{
            'name': 'Guest User',
        }])

        party2, = self.Party.create([{
            'name': 'Registered User',
            'sale_price_list': user_price_list,
        }])

        self.party2 = party2

        party3, = self.Party.create([{
            'name': 'Registered User 2',
        }])

        # Create users and assign the pricelists to them
        self.guest_user, = self.NereidUser.create([{
            'party': party1.id,
            'display_name': 'Guest User',
            'email': '*****@*****.**',
            'password': '******',
            'company': self.company.id,
        }])
        self.registered_user, = self.NereidUser.create([{
            'party':
            party2.id,
            'display_name':
            'Registered User',
            'email':
            '*****@*****.**',
            'password':
            '******',
            'company':
            self.company.id,
        }])
        self.registered_user2, = self.NereidUser.create([{
            'party':
            party3.id,
            'display_name':
            'Registered User 2',
            'email':
            '*****@*****.**',
            'password':
            '******',
            'company':
            self.company.id,
        }])

        warehouse, = self.Location.search([('type', '=', 'warehouse')],
                                          limit=1)
        location, = self.Location.search([('type', '=', 'storage')], limit=1)
        en_us, = self.Language.search([('code', '=', 'en_US')])

        self.locale_en_us, = self.Locale.create([{
            'code': 'en_US',
            'language': en_us.id,
            'currency': usd.id,
        }])

        self.channel, = self.SaleChannel.create([{
            'name':
            'Default Channel',
            'price_list':
            channel_price_list,
            'warehouse':
            warehouse,
            'payment_term':
            payment_term,
            'company':
            self.company.id,
            'create_users': [('add', [USER])],
            'invoice_method':
            'order',
            'shipment_method':
            'order',
            'source':
            'manual'
        }])
        self.User.set_preferences({'current_channel': self.channel})

        self.User.write(
            [self.User(USER)], {
                'main_company': self.company.id,
                'company': self.company.id,
                'current_channel': self.channel,
            })
        self.default_node, = self.Node.create([{
            'name': 'root',
            'slug': 'root',
        }])
        self.country, = self.Country.create([{
            'name': 'United States',
            'code': 'US',
        }])
        self.subdivision1, = self.Subdivision.create([{
            'country': self.country.id,
            'name': 'California',
            'code': 'US-CA',
            'type': 'state',
        }])
        self.NereidWebsite.create([{
            'name': 'localhost',
            'channel': self.channel,
            'company': self.company.id,
            'application_user': USER,
            'default_locale': self.locale_en_us.id,
            'guest_user': self.guest_user,
            'countries': [('add', [self.country.id])],
            'currencies': [('add', [usd.id])],
        }])
    def setup_defaults(self):
        """
        Creates default data for testing
        """
        currency, = self.Currency.create([{
            'name': 'US Dollar',
            'code': 'USD',
            'symbol': '$',
        }])

        with Transaction().set_context(company=None):
            company_party, = self.Party.create([{
                'name': 'Openlabs'
            }])

        self.company, = self.Company.create([{
            'party': company_party,
            'currency': currency,
        }])

        self.User.write([self.User(USER)], {
            'company': self.company,
            'main_company': self.company,
        })

        CONTEXT.update(self.User.get_preferences(context_only=True))

        # Create Fiscal Year
        self._create_fiscal_year(company=self.company.id)
        # Create Chart of Accounts
        self._create_coa_minimal(company=self.company.id)
        # Create Cash journal
        self.cash_journal, = self.Journal.search(
            [('type', '=', 'cash')], limit=1
        )
        self.Journal.write([self.cash_journal], {
            'debit_account': self._get_account_by_kind('expense').id
        })

        self.auth_net_gateway = self.PaymentGateway(
            name='Authorize.net',
            journal=self.cash_journal,
            provider='authorize_net',
            method='credit_card',
            authorize_net_login='******',
            authorize_net_transaction_key='32jF65cTxja88ZA2',
            test=True
        )
        self.auth_net_gateway.save()

        # Create parties
        self.party1, = self.Party.create([{
            'name': 'Test party - 1',
            'addresses': [('create', [{
                'name': 'Test Party %s' % random.randint(1, 999),
                'street': 'Test Street %s' % random.randint(1, 999),
                'city': 'Test City %s' % random.randint(1, 999),
            }])],
            'account_receivable': self._get_account_by_kind(
                'receivable').id,
        }])
        self.party2, = self.Party.create([{
            'name': 'Test party - 2',
            'addresses': [('create', [{
                'name': 'Test Party',
                'street': 'Test Street',
                'city': 'Test City',
            }])],
            'account_receivable': self._get_account_by_kind(
                'receivable').id,
        }])
        self.party3, = self.Party.create([{
            'name': 'Test party - 3',
            'addresses': [('create', [{
                'name': 'Test Party',
                'street': 'Test Street',
                'city': 'Test City',
            }])],
            'account_receivable': self._get_account_by_kind(
                'receivable').id,
        }])

        self.card_data1 = self.UseCardView(
            number='4111111111111111',
            expiry_month='04',
            expiry_year=str(random.randint(2016, 2020)),
            csc=str(random.randint(100, 555)),
            owner='Test User -1',
        )
        self.card_data2 = self.UseCardView(
            number='4111111111111111',
            expiry_month='08',
            expiry_year=str(random.randint(2016, 2020)),
            csc=str(random.randint(556, 999)),
            owner='Test User -2',
        )
        self.invalid_card_data = self.UseCardView(
            number='4111111111111111',
            expiry_month='08',
            expiry_year='2022',
            csc=str(911),
            owner='Test User -2',
        )

        self.payment_profile = self.PaymentProfile(
            party=self.party1,
            address=self.party1.addresses[0].id,
            gateway=self.auth_net_gateway.id,
            last_4_digits='1111',
            expiry_month='01',
            expiry_year='2018',
            provider_reference='27527167',
            authorize_profile_id='28545177',
        )
        self.payment_profile.save()
コード例 #19
0
    def setup_defaults(self):
        """Method to setup defaults
        """
        # Create currency
        self.currency, = self.Currency.create([{
            'name': 'Euro',
            'code': 'EUR',
            'symbol': 'EUR',
        }])

        country_de, country_tw = self.Country.create([{
            'name': 'Germany',
            'code': 'DE',
        }, {
            'name': 'Taiwan',
            'code': 'TW',
        }])

        subdivision_bw, = self.Subdivision.create([{
            'name': 'Baden-Württemberg',
            'code': 'DE-BW',
            'type': 'state',
            'country': country_de.id,
        }])

        with Transaction().set_context(company=None):
            company_party, = self.Party.create([{
                'name': 'Deutsche Post IT Brief GmbH',
                'vat_number': '123456',
                'addresses': [('create', [{
                    'name': 'Max Muster',
                    'street': 'Heinrich-Bruening-Str.',
                    'streetbis': '7',
                    'zip': '53113',
                    'city': 'Bonn',
                    'country': country_de.id,
                }])],
                'contact_mechanisms': [('create', [{
                    'type': 'phone',
                    'value': '030244547777778',
                }, {
                    'type': 'email',
                    'value': '*****@*****.**',
                }, {
                    'type': 'fax',
                    'value': '030244547777778',
                }, {
                    'type': 'mobile',
                    'value': '9876543212',
                }, {
                    'type': 'website',
                    'value': 'example.com',
                }])],
            }])

        self.company, = self.Company.create([{
            'party': company_party.id,
            'currency': self.currency.id,
        }])

        self.User.write(
            [self.User(USER)], {
                'main_company': self.company.id,
                'company': self.company.id,
            }
        )

        CONTEXT.update(self.User.get_preferences(context_only=True))

        self._create_fiscal_year(company=self.company)
        self._create_coa_minimal(company=self.company)
        self.payment_term, = self._create_payment_term()

        account_revenue, = self.Account.search([
            ('kind', '=', 'revenue')
        ])

        # Create product category
        category, = self.Category.create([{
            'name': 'Test Category',
        }])

        uom_kg, = self.Uom.search([('symbol', '=', 'kg')])
        uom_cm, = self.Uom.search([('symbol', '=', 'cm')])
        uom_pound, = self.Uom.search([('symbol', '=', 'lb')])

        # Carrier Carrier Product
        carrier_product_template, = self.Template.create([{
            'name': 'Test Carrier Product',
            'category': category.id,
            'type': 'service',
            'salable': True,
            'sale_uom': uom_kg,
            'list_price': Decimal('10'),
            'cost_price': Decimal('5'),
            'default_uom': uom_kg,
            'cost_price_method': 'fixed',
            'account_revenue': account_revenue.id,
            'products': [('create', self.Template.default_products())]
        }])

        carrier_product = carrier_product_template.products[0]

        # Create product
        template, = self.Template.create([{
            'name': 'Test Product',
            'category': category.id,
            'type': 'goods',
            'salable': True,
            'sale_uom': uom_kg,
            'list_price': Decimal('10'),
            'cost_price': Decimal('5'),
            'default_uom': uom_kg,
            'account_revenue': account_revenue.id,
            'weight': .5,
            'weight_uom': uom_pound.id,
            'products': [('create', self.Template.default_products())]
        }])

        self.product = template.products[0]

        # Create party
        carrier_party, = self.Party.create([{
            'name': 'Test Party',
        }])

        # Create party
        carrier_party, = self.Party.create([{
            'name': 'Test Party',
        }])

        values = {
            'party': carrier_party.id,
            'currency': self.currency.id,
            'carrier_product': carrier_product.id,
            'carrier_cost_method': 'dhl_de',
            'dhl_de_username': self.username,
            'dhl_de_password': self.password,
            'dhl_de_api_user': '******',
            'dhl_de_api_signature': 'Dhl_ep_test1',
            'dhl_de_account_no': '5000000008 72 01',
        }

        self.carrier, = self.Carrier.create([values])

        self.sale_party, self.sale_party2 = self.Party.create([{
            'name': 'Klammer Company',
            'vat_number': '123456',
            'addresses': [('create', [{
                'name': 'Kai Wahn',
                'street': 'Marktplatz',
                'streetbis': '1',
                'zip': '70173',
                'city': 'Stuttgart',
                'country': country_de.id,
                'subdivision': subdivision_bw.id,
            }])],
            'contact_mechanisms': [('create', [{
                'type': 'phone',
                'value': '+886 2 27781-8',
            }, {
                'type': 'email',
                'value': '*****@*****.**',
            }])],
        }, {
            'name': 'Klammer Company',
            'vat_number': '123456',
            'addresses': [('create', [{
                'name': 'John Wick',
                'street': 'Chung Hsiao East Road.',
                'streetbis': '55',
                'zip': '100',
                'city': 'Taipeh',
                'country': country_tw.id,
            }])],
            'contact_mechanisms': [('create', [{
                'type': 'phone',
                'value': '+886 2 27781-8',
            }, {
                'type': 'email',
                'value': '*****@*****.**',
            }])],
        }])
        sale_config = self.SaleConfig()
        sale_config.save()
コード例 #20
0
    def setup_defaults(self):
        """
        Setup the defaults
        """
        with Transaction().set_context(company=None):
            self.usd, = self.Currency.create([{
                'name': 'US Dollar',
                'code': 'USD',
                'symbol': '$',
            }])
            self.party, = self.Party.create([{
                'name': 'Openlabs',
            }])
            self.company, = self.Company.create([{
                'party': self.party.id,
                'currency': self.usd
            }])

        self.User.write(
            [self.User(USER)], {
                'main_company': self.company.id,
                'company': self.company.id,
            }
        )
        CONTEXT.update(self.User.get_preferences(context_only=True))

        # Create Fiscal Year
        self._create_fiscal_year(company=self.company.id)
        # Create Chart of Accounts
        self._create_coa_minimal(company=self.company.id)
        # Create a payment term
        payment_term, = self._create_payment_term()

        channel_price_list, user_price_list = self._create_pricelists()
        party1, = self.Party.create([{
            'name': 'Guest User',
        }])

        party2, = self.Party.create([{
            'name': 'Registered User',
            'sale_price_list': user_price_list,
        }])

        self.party2 = party2

        party3, = self.Party.create([{
            'name': 'Registered User 2',
        }])

        sale_config = self.SaleConfig(1)
        sale_config.payment_authorize_on = 'manual'
        sale_config.payment_capture_on = 'sale_process'
        sale_config.gift_card_method = 'order'
        sale_config.save()

        # Create users and assign the pricelists to them
        self.guest_user, = self.NereidUser.create([{
            'party': party1.id,
            'display_name': 'Guest User',
            'email': '*****@*****.**',
            'password': '******',
            'company': self.company.id,
        }])
        self.registered_user, = self.NereidUser.create([{
            'party': party2.id,
            'display_name': 'Registered User',
            'email': '*****@*****.**',
            'password': '******',
            'company': self.company.id,
        }])
        self.registered_user2, = self.NereidUser.create([{
            'party': party3.id,
            'display_name': 'Registered User 2',
            'email': '*****@*****.**',
            'password': '******',
            'company': self.company.id,
        }])

        self._create_countries()
        self.available_countries = self.Country.search([], limit=5)

        warehouse, = self.Location.search([
            ('type', '=', 'warehouse')
        ], limit=1)
        location, = self.Location.search([
            ('type', '=', 'storage')
        ], limit=1)
        en_us, = self.Language.search([('code', '=', 'en_US')])

        self.locale_en_us, = self.Locale.create([{
            'code': 'en_US',
            'language': en_us.id,
            'currency': self.usd.id,
        }])

        self.sale_tax, = self.Tax.create([{
            'name': 'Sales Tax',
            'description': 'Sales Tax',
            'type': 'percentage',
            'rate': Decimal('0.05'),  # Rate 5%
            'company': self.company.id,
            'invoice_account': self._get_account_by_kind('other').id,
            'credit_note_account': self._get_account_by_kind('other').id,
        }])

        self.channel, = self.SaleChannel.create([{
            'name': 'Default Channel',
            'price_list': channel_price_list,
            'warehouse': warehouse,
            'payment_term': payment_term,
            'company': self.company.id,
            'currency': self.company.currency.id,
            'invoice_method': 'order',
            'shipment_method': 'order',
            'source': 'webshop',
            'create_users': [('add', [USER])],
        }])

        self.User.set_preferences({'current_channel': self.channel})

        self.User.write(
            [self.User(USER)], {
                'main_company': self.company.id,
                'company': self.company.id,
                'current_channel': self.channel,
            }
        )

        self.default_node, = self.Node.create([{
            'name': 'root',
            'slug': 'root',
        }])
        self.default_menuitem, = self.MenuItem.create([{
            'type_': 'view',
            'title': 'Test Title'
        }])
        self.NereidWebsite.create([{
            'name': 'localhost',
            'channel': self.channel,
            'company': self.company.id,
            'application_user': USER,
            'default_locale': self.locale_en_us.id,
            'guest_user': self.guest_user,
            'countries': [('add', self.available_countries)],
            'currencies': [('add', [self.usd.id])],
            'homepage_menu': self.default_menuitem.id,
        }])

        # Create an article category
        article_categ, = self.ArticleCategory.create([{
            'title': 'Test Categ',
            'unique_name': 'test-categ',
        }])

        self.Article.create([{
            'title': 'Test Article',
            'uri': 'test-article',
            'content': 'Test Content',
            'sequence': 10,
            'categories': [('add', [article_categ.id])],
        }])

        # Product categories
        self.category, = self._create_product_category('categ1', [{}])
        self.category2, = self._create_product_category('categ2', [{}])
        self.category3, = self._create_product_category('categ3', [{}])

        self.Account.write(
            self.Account.search([]), {'party_required': True}
        )
コード例 #21
0
    def setup_defaults(self):
        """Creates default data for testing
        """
        currency, = self.Currency.create([{
            'name': 'US Dollar',
            'code': 'USD',
            'symbol': '$',
        }])

        with Transaction().set_context(company=None):
            company_party, = self.Party.create([{
                'name': 'Openlabs'
            }])

        self.company, = self.Company.create([{
            'party': company_party,
            'currency': currency,
        }])

        self.User.write([self.User(USER)], {
            'company': self.company,
            'main_company': self.company,
        })

        CONTEXT.update(self.User.get_preferences(context_only=True))

        # Create Fiscal Year
        self._create_fiscal_year(company=self.company.id)
        # Create Chart of Accounts
        self._create_coa_minimal(company=self.company.id)
        # Create a payment term
        self.payment_term, = self._create_payment_term()

        self.cash_journal, = self.Journal.search(
            [('type', '=', 'cash')], limit=1
        )

        # This is required to successfully pay the invoices
        main_cash_account = self._get_account_by_kind('other')

        self.Journal.write([self.cash_journal], {
            'debit_account': main_cash_account.id
        })

        self.uom, = self.Uom.search([('symbol', '=', 'd')])

        self.country, = self.Country.create([{
            'name': 'United States of America',
            'code': 'US',
        }])

        self.subdivision, = self.Subdivision.create([{
            'country': self.country.id,
            'name': 'California',
            'code': 'CA',
            'type': 'state',
        }])

        # Add address to company's party record
        self.Party.write([self.company.party], {
            'addresses': [('create', [{
                'name': 'Openlabs',
                'party': Eval('id'),
                'city': 'Los Angeles',
                'invoice': True,
                'country': self.country.id,
                'subdivision': self.subdivision.id,
            }])],
        })

        # Create party
        self.party, = self.Party.create([{
            'name': 'Bruce Wayne',
            'addresses': [('create', [{
                'name': 'Bruce Wayne',
                'party': Eval('id'),
                'city': 'Gotham',
                'invoice': True,
                'country': self.country.id,
                'subdivision': self.subdivision.id,
            }])],
            'customer_payment_term': self.payment_term.id,
            'account_receivable': self._get_account_by_kind(
                'receivable').id,
            'contact_mechanisms': [('create', [
                {'type': 'mobile', 'value': '8888888888'},
            ])],
        }])

        self.journal, = self.Journal.search([('type', '=', 'revenue')], limit=1)

        self.product_category, = self.ProductCategory.create([{
            'name': 'Test Category',
            'account_revenue': self._get_account_by_kind(
                'revenue', company=self.company.id).id,
            'account_expense': self._get_account_by_kind(
                'expense', company=self.company.id).id,
        }])

        self.product_template, = self.ProductTemplate.create([{
            'name': 'Toy',
            'type': 'goods',
            'list_price': Decimal('10'),
            'cost_price': Decimal('5'),
            'category': self.product_category.id,
            'default_uom': self.uom,
            'account_revenue': self._get_account_by_kind(
                'revenue', company=self.company.id).id,
            'account_expense': self._get_account_by_kind(
                'expense', company=self.company.id).id,
        }])

        self.product1, = self.Product.create([{
            'template': self.product_template.id,
            'code': 'toy-1',
        }])
        self.product2, = self.Product.create([{
            'template': self.product_template.id,
            'code': 'toy-2',
        }])

        with Transaction().set_context(use_dummy=True):
            self.dummy_gateway, = self.PaymentGateway.create([{
                'name': 'Dummy Gateway',
                'journal': self.cash_journal.id,
                'provider': 'dummy',
                'method': 'credit_card',
            }])
        self.dummy_cc_payment_profile = self.create_payment_profile(
            self.party, self.dummy_gateway
        )

        self.cash_gateway, = self.PaymentGateway.create([{
            'name': 'Cash Gateway',
            'journal': self.cash_journal.id,
            'provider': 'self',
            'method': 'manual',
        }])
コード例 #22
0
    def setup_defaults(self):
        """Creates default data for testing
        """
        self.currency, = self.Currency.create([{
            'name': 'US Dollar',
            'code': 'USD',
            'symbol': '$',
        }])

        with Transaction().set_context(company=None):
            company_party, = self.Party.create([{
                'name': 'openlabs'
            }])
            employee_party, = self.Party.create([{
                'name': 'Jim'
            }])

        self.company, = self.Company.create([{
            'party': company_party,
            'currency': self.currency,
        }])

        self.employee, = self.Employee.create([{
            'party': employee_party.id,
            'company': self.company.id,
        }])

        self.User.write([self.User(USER)], {
            'company': self.company,
            'main_company': self.company,
            'employees': [('add', [self.employee.id])],
        })
        # Write employee separately as employees needs to be saved first
        self.User.write([self.User(USER)], {
            'employee': self.employee.id,
        })

        CONTEXT.update(self.User.get_preferences(context_only=True))

        # Create Fiscal Year
        self._create_fiscal_year(company=self.company.id)
        # Create Chart of Accounts
        self._create_coa_minimal(company=self.company.id)
        # Create a payment term
        self.payment_term, = self._create_payment_term()

        # Create carrier
        carrier_price_list, = self.PriceList.create([{
            'name': 'PL 1',
            'company': self.company.id,
            'lines': [
                ('create', [{
                    'formula': '(unit_price * 0.0) + 5',
                }])
            ],
        }])
        carrier_party, = self.Party.create([{
            'name': 'Pricelist Carrier',
        }])

        day, = self.Uom.search([('name', '=', 'Day')])
        carrier_product_template, = self.ProductTemplate.create([{
            'name': 'Carrier Pricelist',
            'type': 'service',
            'salable': True,
            'default_uom': day.id,
            'sale_uom': day.id,
            'account_revenue': self._get_account_by_kind('revenue').id,
            'list_price': Decimal('50'),
            'cost_price': Decimal('40'),
        }])
        carrier_product, = self.Product.create([{
            'template': carrier_product_template.id,
        }])
        self.carrier, = self.Carrier.create([{
            'party': carrier_party.id,
            'carrier_cost_method': 'pricelist',
            'carrier_product': carrier_product.id,
            'price_list': carrier_price_list.id,
        }])

        unit, = self.Uom.search([('name', '=', 'Unit')])

        self.template1, = self.ProductTemplate.create([{
            'name': 'Product 1',
            'type': 'goods',
            'salable': True,
            'default_uom': unit.id,
            'sale_uom': unit.id,
            'list_price': Decimal('100'),
            'cost_price': Decimal('90'),
            'account_revenue': self._get_account_by_kind('revenue').id,
            'products': [('create', [{
                'code': 'product-1'
            }])]
        }])

        self.template2, = self.ProductTemplate.create([{
            'name': 'Product 2',
            'type': 'goods',
            'salable': True,
            'default_uom': unit.id,
            'sale_uom': unit.id,
            'list_price': Decimal('50'),
            'cost_price': Decimal('40'),
            'account_revenue': self._get_account_by_kind('revenue').id,
            'products': [('create', [{
                'code': 'product-1'
            }])]
        }])

        self.product1 = self.template1.products[0]
        self.product2 = self.template2.products[0]

        # Create sale party
        self.sale_party, = self.Party.create([{
            'name': 'Test Sale Party',
            'addresses': [('create', [{
                'name': 'John Doe',
                'street': '123 Main Street',
                'zip': '83702',
                'city': 'Boise',
            }])]
        }])
コード例 #23
0
    def setup_defaults(self):
        """
        Setup the defaults
        """

        self.User.write(
            [self.User(USER)], {
                'main_company': self.company.id,
                'company': self.company.id,
            }
        )
        CONTEXT.update(self.User.get_preferences(context_only=True))

        # Create Fiscal Year
        self._create_fiscal_year(company=self.company.id)
        # Create Chart of Accounts
        self._create_coa_minimal(company=self.company.id)
        # Create a payment term
        self._create_payment_term()

        guest_price_list, user_price_list = self._create_pricelists()

        party1, = self.Party.create([{
            'name': 'Guest User',
            'sale_price_list': guest_price_list
        }])

        party2, = self.Party.create([{
            'name': 'Registered User',
            'sale_price_list': user_price_list,
        }])

        party3, = self.Party.create([{
            'name': 'Registered User 2',
        }])

        # Create users and assign the pricelists to them
        guest_user, = self.NereidUser.create([{
            'party': party1.id,
            'display_name': 'Guest User',
            'email': '*****@*****.**',
            'password': '******',
            'company': self.company.id,
        }])
        self.registered_user, = self.NereidUser.create([{
            'party': party2.id,
            'display_name': 'Registered User',
            'email': '*****@*****.**',
            'password': '******',
            'company': self.company.id,
        }])
        self.registered_user2, = self.NereidUser.create([{
            'party': party3.id,
            'display_name': 'Registered User 2',
            'email': '*****@*****.**',
            'password': '******',
            'company': self.company.id,
        }])

        self._create_countries()
        self.available_countries = self.Country.search([], limit=5)

        self.category, = self._create_product_category(
            'Category', [{'uri': 'category'}]
        )

        warehouse, = self.Location.search([
            ('type', '=', 'warehouse')
        ], limit=1)
        location, = self.Location.search([
            ('type', '=', 'storage')
        ], limit=1)
        url_map, = self.UrlMap.search([], limit=1)
        en_us, = self.Language.search([('code', '=', 'en_US')])

        self.locale_en_us, = self.Locale.create([{
            'code': 'en_US',
            'language': en_us.id,
            'currency': self.usd.id,
        }])
        self.NereidWebsite.create([{
            'name': 'localhost',
            'url_map': url_map,
            'company': self.company.id,
            'application_user': USER,
            'default_locale': self.locale_en_us.id,
            'guest_user': guest_user,
            'countries': [('set', self.available_countries)],
            'warehouse': warehouse,
            'stock_location': location,
            'categories': [('set', [self.category.id])],
            'currencies': [('set', [self.usd.id])],
        }])

         # Create product templates with products
        self.template1, = self._create_product_template(
            'product-1',
            [{
                'category': self.category.id,
                'type': 'goods',
                'salable': True,
                'list_price': Decimal('10'),
                'cost_price': Decimal('5'),
                'account_expense': self._get_account_by_kind('expense').id,
                'account_revenue': self._get_account_by_kind('revenue').id,
            }],
            uri='product-1',
        )
        self.template2, = self._create_product_template(
            'product-2',
            [{
                'category': self.category.id,
                'type': 'goods',
                'salable': True,
                'list_price': Decimal('15'),
                'cost_price': Decimal('5'),
                'account_expense': self._get_account_by_kind('expense').id,
                'account_revenue': self._get_account_by_kind('revenue').id,
            }],
            uri='product-2',
        )
        self.product1 = self.template1.products[0]
        self.product2 = self.template2.products[0]
コード例 #24
0
    def setup_defaults(self):
        """Method to setup defaults
        """
        # Create currency
        currency, = self.currency.create([{
            'name': 'United Stated Dollar',
            'code': 'USD',
            'symbol': 'USD',
        }])
        self.currency.create([{
            'name': 'Indian Rupee',
            'code': 'INR',
            'symbol': 'INR',
        }])

        company_party, = self.party.create([{'name': 'Test Party'}])

        # Endicia Configuration
        self.company, = self.company.create([{
            'party': company_party.id,
            'currency': currency.id,
            'endicia_account_id': '123456',
            'endicia_requester_id': '123456',
            'endicia_passphrase': 'PassPhrase',
            'endicia_test': True,
        }])
        self.party_contact.create([{
            'type': 'phone',
            'value': '8005551212',
            'party': self.company.party.id
        }])

        # Sale configuration
        endicia_mailclass, = self.endicia_mailclass.search([('value', '=',
                                                             'First')])

        self.sale_config.write(
            self.sale_config(1), {
                'endicia_label_subtype': 'Integrated',
                'endicia_integrated_form_type': 'Form2976',
                'endicia_mailclass': endicia_mailclass.id,
                'endicia_include_postage': True,
            })

        self.User.write([self.User(USER)], {
            'main_company': self.company.id,
            'company': self.company.id,
        })

        CONTEXT.update(self.User.get_preferences(context_only=True))

        self._create_fiscal_year(company=self.company)
        self._create_coa_minimal(company=self.company)
        self.payment_term, = self._create_payment_term()

        account_revenue, = self.account.search([('kind', '=', 'revenue')])

        # Create product category
        category, = self.category.create([{
            'name': 'Test Category',
        }])

        uom_kg, = self.uom.search([('symbol', '=', 'kg')])
        uom_pound, = self.uom.search([('symbol', '=', 'lbs')])

        # Carrier Carrier Product
        carrier_product_template, = self.template.create([{
            'name':
            'Test Carrier Product',
            'category':
            category.id,
            'type':
            'service',
            'salable':
            True,
            'sale_uom':
            uom_kg,
            'list_price':
            Decimal('10'),
            'cost_price':
            Decimal('5'),
            'default_uom':
            uom_kg,
            'cost_price_method':
            'fixed',
            'account_revenue':
            account_revenue.id,
        }])

        carrier_product = carrier_product_template.products[0]

        # Create product
        template, = self.template.create([{
            'name': 'Test Product',
            'category': category.id,
            'type': 'goods',
            'salable': True,
            'sale_uom': uom_kg,
            'list_price': Decimal('10'),
            'cost_price': Decimal('5'),
            'default_uom': uom_kg,
            'account_revenue': account_revenue.id,
            'weight': .5,
            'weight_uom': uom_pound.id,
        }])

        product = template.products[0]

        # Create party
        carrier_party, = self.party.create([{
            'name': 'Test Party',
        }])

        # Create party
        carrier_party, = self.party.create([{
            'name': 'Test Party',
        }])

        carrier, = self.carrier.create([{
            'party': carrier_party.id,
            'carrier_product': carrier_product.id,
            'carrier_cost_method': 'endicia',
        }])

        country_us, = self.country.create([{
            'name': 'United States',
            'code': 'US',
        }])

        subdivision_idaho, = self.country_subdivision.create([{
            'name':
            'Idaho',
            'code':
            'US-ID',
            'country':
            country_us.id,
            'type':
            'state'
        }])

        subdivision_california, = self.country_subdivision.create([{
            'name':
            'California',
            'code':
            'US-CA',
            'country':
            country_us.id,
            'type':
            'state'
        }])
        company_address, = self.party_address.create([{
            'name':
            'Amine Khechfe',
            'street':
            '247 High Street',
            'zip':
            '84301',
            'city':
            'Palo Alto',
            'country':
            country_us.id,
            'subdivision':
            subdivision_california.id,
            'party':
            self.company.party.id,
        }])

        sale_party, = self.party.create([{
            'name': 'Test Sale Party',
        }])
        self.party_contact.create([{
            'type': 'phone',
            'value': '8005763279',
            'party': sale_party.id
        }])

        sale_address, = self.party_address.create([{
            'name':
            'John Doe',
            'street':
            '123 Main Street',
            'zip':
            '83702',
            'city':
            'Boise',
            'country':
            country_us.id,
            'subdivision':
            subdivision_idaho.id,
            'party':
            sale_party,
        }])

        with Transaction().set_context(company=self.company.id):

            # Create sale order
            sale, = self.sale.create([{
                'reference':
                'S-1001',
                'payment_term':
                self.payment_term,
                'party':
                sale_party.id,
                'invoice_address':
                sale_address.id,
                'shipment_address':
                sale_address.id,
                'carrier':
                carrier.id,
                'lines': [
                    ('create', [{
                        'type': 'line',
                        'quantity': 1,
                        'product': product,
                        'unit_price': Decimal('10.00'),
                        'description': 'Test Description1',
                        'unit': uom_kg,
                    }]),
                ]
            }])

            self.stock_location.write([sale.warehouse], {
                'address': company_address.id,
            })

            # Confirm and process sale order
            self.assertEqual(len(sale.lines), 1)
            self.sale.quote([sale])
            self.assertEqual(len(sale.lines), 2)
            self.sale.confirm([sale])
            self.sale.process([sale])
コード例 #25
0
ファイル: test_account.py プロジェクト: kret0s/gnuhealth-live
    def test0010account_chart(self):
        'Test creation of minimal chart of accounts'
        with Transaction().start(DB_NAME, USER,
                                 context=CONTEXT) as transaction:
            account_template = self.account_template(
                self.model_data.get_id('account', 'account_template_root_en'))
            tax_account = self.account_template(
                self.model_data.get_id('account', 'account_template_tax_en'))
            with Transaction().set_user(0):
                tax_code = self.tax_code_template()
                tax_code.name = 'Tax Code'
                tax_code.account = account_template
                tax_code.save()
                base_code = self.tax_code_template()
                base_code.name = 'Base Code'
                base_code.account = account_template
                base_code.save()
                tax = self.tax_template()
                tax.name = tax.description = '20% VAT'
                tax.type = 'percentage'
                tax.rate = Decimal('0.2')
                tax.account = account_template
                tax.invoice_account = tax_account
                tax.credit_note_account = tax_account
                tax.invoice_base_code = base_code
                tax.invoice_base_sign = Decimal(1)
                tax.invoice_tax_code = tax_code
                tax.invoice_tax_sign = Decimal(1)
                tax.credit_note_base_code = base_code
                tax.credit_note_base_sign = Decimal(-1)
                tax.credit_note_tax_code = tax_code
                tax.credit_note_tax_sign = Decimal(-1)
                tax.save()

            company, = self.company.search([
                ('rec_name', '=', 'Dunder Mifflin'),
            ])
            self.user.write([self.user(USER)], {
                'main_company': company.id,
                'company': company.id,
            })
            CONTEXT.update(self.user.get_preferences(context_only=True))

            session_id, _, _ = self.account_create_chart.create()
            create_chart = self.account_create_chart(session_id)
            create_chart.account.account_template = account_template
            create_chart.account.company = company
            create_chart.transition_create_account()
            receivable, = self.account.search([
                ('kind', '=', 'receivable'),
                ('company', '=', company.id),
            ])
            payable, = self.account.search([
                ('kind', '=', 'payable'),
                ('company', '=', company.id),
            ])
            create_chart.properties.company = company
            create_chart.properties.account_receivable = receivable
            create_chart.properties.account_payable = payable
            create_chart.transition_create_properties()
            transaction.cursor.commit()
コード例 #26
0
    def setup_defaults(self):
        """Creates default data for testing
        """
        currency, = self.Currency.create([{
            'name': 'US Dollar',
            'code': 'USD',
            'symbol': '$',
        }])

        with Transaction().set_context(company=None):
            company_party, = self.Party.create([{
                'name': 'Openlabs'
            }])

        self.company, = self.Company.create([{
            'party': company_party,
            'currency': currency,
        }])

        self.User.write([self.User(USER)], {
            'company': self.company,
            'main_company': self.company,
        })

        CONTEXT.update(self.User.get_preferences(context_only=True))

        self.uom, = self.Uom.search([('symbol', '=', 'u')])

        self.country, = self.Country.create([{
            'name': 'United States of America',
            'code': 'US',
        }])

        self.subdivision, = self.Subdivision.create([{
            'country': self.country.id,
            'name': 'California',
            'code': 'CA',
            'type': 'state',
        }])

        # Add address to company's party record
        self.Party.write([self.company.party], {
            'addresses': [('create', [{
                'name': 'Openlabs',
                'party': Eval('id'),
                'city': 'Los Angeles',
                'country': self.country.id,
                'subdivision': self.subdivision.id,
            }])],
        })

        self.product_category, = self.ProductCategory.create([{
            'name': 'Automobile',
        }])

        self.product_template, = self.ProductTemplate.create([{
            'name': 'Bat Mobile',
            'type': 'goods',
            'list_price': Decimal('2000'),
            'cost_price': Decimal('1500'),
            'category': self.product_category.id,
            'default_uom': self.uom,
        }])

        self.product, = self.Product.create([{
            'template': self.product_template.id,
            'code': '123',
        }])

        self.warehouse, = self.Location.search([
            ('code', '=', 'WH')
        ])
コード例 #27
0
    def setup_defaults(self):
        """Creates default data for testing
        """

        self.currency, = self.Currency.create([{
            'name': 'US Dollar',
            'code': 'USD',
            'symbol': '$',
        }])

        with Transaction().set_context(company=None):
            self.company_party, = self.Party.create([{
                'name': 'openlabs',
            }])

        self.company, = self.Company.create([{
            'party': self.company_party,
            'currency': self.currency,
        }])
        self.User.write([self.User(USER)], {
            'company': self.company,
            'main_company': self.company,
        })

        CONTEXT.update(self.User.get_preferences(context_only=True))

        self.country, = self.Country.create([{
            'name': 'United States of America',
            'code': 'US',
        }])
        self.subdivision, = self.Subdivision.create([{
            'country': self.country.id,
            'name': 'California',
            'code': 'CA',
            'type': 'state',
        }])

        self._create_coa_minimal(self.company)
        self._create_payment_term()

        self.party, = self.Party.create([{
            'name': 'Bruce Wayne',
            'addresses': [('create', [{
                'name': 'Bruce Wayne',
                'party': Eval('id'),
                'city': 'Gotham',
                'country': self.country.id,
                'subdivision': self.subdivision.id,
            }])],
            'contact_mechanisms': [('create', [
                {'type': 'mobile', 'value': '8888888888'},
            ])],
        }])
        self.Party.write([self.company.party], {
            'addresses': [('create', [{
                'name': 'Lie Nielsen',
                'city': 'Los Angeles',
                'country': self.country.id,
                'subdivision': self.subdivision.id,
            }])],
        })
        self.product_category, = self.ProductCategory.create([{
            'name': 'Automobile',
        }])
        self.uom, = self.Uom.search([('name', '=', 'Unit')])

        self.product_template, = self.ProductTemplate.create([{
            'name': 'Bat Mobile',
            'type': 'goods',
            'category': self.product_category.id,
            'list_price': Decimal('20000'),
            'cost_price': Decimal('15000'),
            'default_uom': self.uom.id,
        }])
        self.product, = self.Product.create([{
            'template': self.product_template.id,
            'code': '123',
        }])
コード例 #28
0
    def setup_defaults(self):
        """
        Setting up default values.
        """

        usd, = self.Currency.create([{
            'name': 'US Dollar',
            'code': 'USD',
            'symbol': '$',
        }])

        # Create parties
        with Transaction().set_context(company=None):
            self.party, = self.Party.create([{
                'name': 'openlabs',
            }])

        self.company, = self.Company.create([{
            'party': self.party,
            'currency': usd,
        }])

        self.User.write(
            [self.User(USER)], {
                'main_company': self.company.id,
                'company': self.company.id,
            }
        )
        CONTEXT.update(self.User.get_preferences(context_only=True))

        # Create Fiscal Year
        self._create_fiscal_year(company=self.company.id)
        # Create Chart of Accounts
        self._create_coa_minimal(company=self.company.id)

        guest_party, = self.Party.create([{
            'name': 'Guest User',
        }])

        self.party2, = self.Party.create([{
            'name': 'Registered User',
        }])

        self.party3, = self.Party.create([{
            'name': 'Registered User 2',
        }])

        self.guest_user, = self.NereidUser.create([{
            'party': guest_party.id,
            'display_name': 'Guest User',
            'email': '*****@*****.**',
            'password': '******',
            'company': self.company.id,
        }])

        # Create test users
        self.registered_user, = self.NereidUser.create([{
            'party': self.party2.id,
            'display_name': 'Registered User',
            'email': '*****@*****.**',
            'password': '******',
            'company': self.company.id,
        }])
        self.registered_user2, = self.NereidUser.create([{
            'party': self.party3.id,
            'display_name': 'Registered User 2',
            'email': '*****@*****.**',
            'password': '******',
            'company': self.company.id,
        }])

        # create countries
        self._create_countries()
        self.available_countries = self.Country.search([], limit=5)

        en_us, = self.Language.search([('code', '=', 'en_US')])

        self.locale_en_us, = self.Locale.create([{
            'code': 'en_US',
            'language': en_us.id,
            'currency': usd.id,
        }])
        warehouse, = self.Location.search([
            ('type', '=', 'warehouse')
        ], limit=1)
        location, = self.Location.search([
            ('type', '=', 'storage')
        ], limit=1)

        payment_term, = self._create_payment_term()

        shop_price_list = self._create_pricelists()

        with Transaction().set_context(company=self.company.id):
            self.shop, = self.SaleShop.create([{
                'name': 'Default Shop',
                'price_list': shop_price_list,
                'warehouse': warehouse,
                'payment_term': payment_term,
                'company': self.company.id,
                'users': [('add', [USER])]
            }])

        self.User.set_preferences({'shop': self.shop})
        self.NereidWebsite.create([{
            'name': 'localhost',
            'company': self.company.id,
            'application_user': USER,
            'shop': self.shop,
            'default_locale': self.locale_en_us.id,
            'warehouse': warehouse,
            'stock_location': location,
            'countries': [('add', self.available_countries)],
            'guest_user': self.guest_user,
        }])
コード例 #29
0
    def setup_defaults(self):
        """Creates default data for testing
        """
        currency, = self.Currency.create([{
            'name': 'US Dollar',
            'code': 'USD',
            'symbol': '$',
        }])

        with Transaction().set_context(company=None):
            company_party, = self.Party.create([{
                'name': 'Openlabs'
            }])

        self.company, = self.Company.create([{
            'party': company_party,
            'currency': currency,
        }])

        self.User.write([self.User(USER)], {
            'company': self.company,
            'main_company': self.company,
        })

        CONTEXT.update(self.User.get_preferences(context_only=True))

        # Create Fiscal Year
        self._create_fiscal_year(company=self.company.id)
        # Create Chart of Accounts
        self._create_coa_minimal(company=self.company.id)
        # Create a payment term
        self.payment_term, = self._create_payment_term()

        self.cash_journal, = self.Journal.search(
            [('type', '=', 'cash')], limit=1
        )

        # This is required to successfully pay the invoices
        main_cash_account = self._get_account_by_kind('other')

        self.Journal.write([self.cash_journal], {
            'debit_account': main_cash_account.id
        })

        self.uom, = self.Uom.search([('symbol', '=', 'd')])

        self.country, = self.Country.create([{
            'name': 'United States of America',
            'code': 'US',
        }])

        self.subdivision, = self.Subdivision.create([{
            'country': self.country.id,
            'name': 'California',
            'code': 'CA',
            'type': 'state',
        }])

        # Add address to company's party record
        self.Party.write([self.company.party], {
            'addresses': [('create', [{
                'name': 'Openlabs',
                'party': Eval('id'),
                'city': 'Los Angeles',
                'invoice': True,
                'country': self.country.id,
                'subdivision': self.subdivision.id,
            }])],
        })

        # Create party
        self.party, = self.Party.create([{
            'name': 'Bruce Wayne',
            'addresses': [('create', [{
                'name': 'Bruce Wayne',
                'party': Eval('id'),
                'city': 'Gotham',
                'invoice': True,
                'country': self.country.id,
                'subdivision': self.subdivision.id,
            }])],
            'customer_payment_term': self.payment_term.id,
            'account_receivable': self._get_account_by_kind(
                'receivable').id,
            'contact_mechanisms': [('create', [
                {'type': 'mobile', 'value': '8888888888'},
            ])],
        }])

        self.journal, = self.Journal.search([('type', '=', 'revenue')], limit=1)

        self.product_category, = self.ProductCategory.create([{
            'name': 'Test Category',
            'account_revenue': self._get_account_by_kind(
                'revenue', company=self.company.id).id,
            'account_expense': self._get_account_by_kind(
                'expense', company=self.company.id).id,
        }])

        self.product_template, = self.ProductTemplate.create([{
            'name': 'Toy',
            'type': 'goods',
            'list_price': Decimal('10'),
            'cost_price': Decimal('5'),
            'categories': [('add', [self.product_category.id])],
            'default_uom': self.uom,
            'account_revenue': self._get_account_by_kind(
                'revenue', company=self.company.id).id,
            'account_expense': self._get_account_by_kind(
                'expense', company=self.company.id).id,
        }])

        self.product1, = self.Product.create([{
            'template': self.product_template.id,
            'code': 'toy-1',
        }])
        self.product2, = self.Product.create([{
            'template': self.product_template.id,
            'code': 'toy-2',
        }])

        with Transaction().set_context(use_dummy=True):
            self.dummy_gateway, = self.PaymentGateway.create([{
                'name': 'Dummy Gateway',
                'journal': self.cash_journal.id,
                'provider': 'dummy',
                'method': 'credit_card',
            }])
        self.dummy_cc_payment_profile = self.create_payment_profile(
            self.party, self.dummy_gateway
        )

        self.cash_gateway, = self.PaymentGateway.create([{
            'name': 'Cash Gateway',
            'journal': self.cash_journal.id,
            'provider': 'self',
            'method': 'manual',
        }])
コード例 #30
0
    def setup_defaults(self):
        '''
        Setup defaults for test
        '''
        usd, = self.Currency.create([{
            'name': 'US Dollar',
            'code': 'USD',
            'symbol': '$',
        }])
        self.Country.create([{
            'name': 'India',
            'code': 'IN',
        }])
        self.country, = self.Country.search([])

        with Transaction().set_context(company=None):
            company_party, = self.Party.create([{
                'name': 'Openlabs',
            }])
            self.company, = self.Company.create([{
                'party': company_party,
                'currency': usd,
            }])

        self.User.write([self.User(USER)], {
            'company': self.company,
            'main_company': self.company,
        })
        CONTEXT.update(self.User.get_preferences(context_only=True))

        self._create_fiscal_year(company=self.company.id)
        self._create_coa_minimal(company=self.company.id)

        admin_party1, = self.Party.create([{
            'name': 'Crm Admin',
        }])
        self.crm_admin, = self.NereidUser.create([{
            'party': admin_party1,
            'display_name': 'Crm Admin',
            'email': '*****@*****.**',
            'password': '******',
            'company': self.company.id,
        }])
        employee, = self.Employee.create([{
            'company': self.company.id,
            'party': self.crm_admin.party.id,
        }])

        self.Config.write([self.Config(1)], {'website_employee': employee.id})

        self.NereidUser.write([self.crm_admin], {
            'employee': employee.id,
        })

        admin_party2, = self.Party.create([{
            'name': 'Crm Admin2',
        }])

        self.crm_admin2, = self.NereidUser.create([{
            'party': admin_party2,
            'display_name': 'Crm Admin2',
            'email': '*****@*****.**',
            'password': '******',
            'company': self.company.id,
        }])
        employee, = self.Employee.create([{
            'company': self.company.id,
            'party': self.crm_admin2.party.id,
        }])
        self.NereidUser.write([self.crm_admin2], {
            'employee': employee.id,
        })

        en_us, = self.Language.search([('code', '=', 'en_US')])
        locale_en, = self.Locale.create([{
            'code': 'en_US',
            'language': en_us.id,
            'currency': usd.id,
        }])
        self.NereidWebsite.create([{
            'name': 'localhost',
            'company': self.company,
            'application_user': USER,
            'default_locale': locale_en.id,
        }])

        perm_admin, = self.NereidPermission.search([
            ('value', '=', 'sales.admin'),
        ])
        self.NereidUser.write(
            [self.crm_admin], {'permissions': [('add', [perm_admin])]}
        )
        self.Company.write(
            [self.company], {'sales_team': [('add', [self.crm_admin])]}
        )
コード例 #31
0
    def setup_defaults(self):
        """Method to setup defaults
        """
        # Create currency
        self.currency, = self.Currency.create([{
            'name': 'United Stated Dollar',
            'code': 'USD',
            'symbol': 'USD',
        }])
        self.Currency.create([{
            'name': 'Indian Rupee',
            'code': 'INR',
            'symbol': 'INR',
        }])

        country_us, country_at = self.Country.create([{
            'name': 'United States',
            'code': 'US',
        }, {
            'name': 'Austria',
            'code': 'AT',
        }])

        subdivision_idaho, = self.Country_Subdivision.create([{
            'name':
            'Idaho',
            'code':
            'US-ID',
            'country':
            country_us.id,
            'type':
            'state'
        }])

        subdivision_california, = self.Country_Subdivision.create([{
            'name':
            'California',
            'code':
            'US-CA',
            'country':
            country_us.id,
            'type':
            'state'
        }])

        subdivision_steiermark, = self.Country_Subdivision.create([{
            'name':
            'Steiermark',
            'code':
            'AT-6',
            'country':
            country_at.id,
            'type':
            'state'
        }])

        with Transaction().set_context(company=None):
            company_party, = self.Party.create([{
                'name':
                'Test Party',
                'addresses': [('create', [{
                    'name':
                    'Amine Khechfe',
                    'street':
                    '247 High Street',
                    'zip':
                    '84301',
                    'city':
                    'Palo Alto',
                    'country':
                    country_us.id,
                    'subdivision':
                    subdivision_california.id,
                }])]
            }])

        # Endicia Configuration
        self.EndiciaConfiguration.create([{
            'account_id': '123456',
            'requester_id': '123456',
            'passphrase': 'PassPhrase',
            'is_test': True,
        }])
        self.company, = self.Company.create([{
            'party': company_party.id,
            'currency': self.currency.id,
        }])
        self.PartyContact.create([{
            'type': 'phone',
            'value': '8005551212',
            'party': self.company.party.id
        }])

        # Sale configuration
        endicia_mailclass, = self.EndiciaMailclass.search([('value', '=',
                                                            'First')])

        self.SaleConfig.write(
            self.SaleConfig(1), {
                'endicia_label_subtype': 'Integrated',
                'endicia_integrated_form_type': 'Form2976',
                'endicia_mailclass': endicia_mailclass.id,
                'endicia_include_postage': True,
            })

        self.User.write([self.User(USER)], {
            'main_company': self.company.id,
            'company': self.company.id,
        })

        CONTEXT.update(self.User.get_preferences(context_only=True))

        self._create_fiscal_year(company=self.company)
        self._create_coa_minimal(company=self.company)
        self.payment_term, = self._create_payment_term()

        account_revenue, = self.Account.search([('kind', '=', 'revenue')])

        # Create product category
        category, = self.Category.create([{
            'name': 'Test Category',
        }])

        uom_kg, = self.Uom.search([('symbol', '=', 'kg')])
        uom_oz, = self.Uom.search([('symbol', '=', 'oz')])

        # Carrier Carrier Product
        carrier_product_template, = self.Template.create([{
            'name':
            'Test Carrier Product',
            'category':
            category.id,
            'type':
            'service',
            'salable':
            True,
            'sale_uom':
            uom_kg,
            'list_price':
            Decimal('10'),
            'cost_price':
            Decimal('5'),
            'default_uom':
            uom_kg,
            'cost_price_method':
            'fixed',
            'account_revenue':
            account_revenue.id,
            'products': [('create', self.Template.default_products())]
        }])

        self.carrier_product = carrier_product_template.products[0]

        # Create product
        template, = self.Template.create([{
            'name':
            'Test Product',
            'category':
            category.id,
            'type':
            'goods',
            'salable':
            True,
            'sale_uom':
            uom_kg,
            'list_price':
            Decimal('10.896'),
            'cost_price':
            Decimal('5.896'),
            'default_uom':
            uom_kg,
            'account_revenue':
            account_revenue.id,
            'weight':
            .1,
            'weight_uom':
            uom_oz.id,
            'products': [('create', self.Template.default_products())]
        }])

        self.product = template.products[0]

        # Create party
        carrier_party, = self.Party.create([{
            'name': 'Test Party',
        }])

        # Create party
        carrier_party, = self.Party.create([{
            'name': 'Test Party',
        }])

        self.carrier, = self.Carrier.create([{
            'party':
            carrier_party.id,
            'carrier_product':
            self.carrier_product.id,
            'carrier_cost_method':
            'endicia',
            'currency':
            self.currency,
        }])

        self.sale_party, = self.Party.create([{
            'name':
            'Test Sale Party',
            'addresses': [('create', [{
                'name': 'John Doe',
                'street': '123 Main Street',
                'zip': '83702',
                'city': 'Boise',
                'country': country_us.id,
                'subdivision': subdivision_idaho.id,
            }, {
                'name': 'John Doe',
                'street': 'Johann Fuxgasse 36',
                'zip': '8010',
                'city': 'Graz',
                'country': country_at.id,
                'subdivision': subdivision_steiermark.id,
            }, {
                'name': 'John Doe',
                'street': '1735 Carleton St.',
                'streetbis': 'Apt A',
                'zip': '94703',
                'city': 'Berkeley',
                'country': country_us.id,
                'subdivision': subdivision_california.id,
            }])]
        }])
        self.PartyContact.create([{
            'type': 'phone',
            'value': '8005763279',
            'party': self.sale_party.id
        }])

        self.sale = self.create_sale(self.sale_party)
コード例 #32
0
    def setup_defaults(self):
        """
        Creates default data for testing
        """
        self.country, = self.Country.create([{
            'name': 'United States',
            'code': 'US',
        }])

        self.subdivision, = self.CountrySubdivision.create([{
            'name':
            'Florida',
            'code':
            'US-FL',
            'country':
            self.country.id,
            'type':
            'state'
        }])
        currency, = self.Currency.create([{
            'name': 'Unites Stated',
            'code': 'USD',
            'symbol': '$',
        }])

        with Transaction().set_context(company=None):
            company_party, = self.Party.create([{'name': 'Openlabs'}])

        self.company, = self.Company.create([{
            'party': company_party,
            'currency': currency,
        }])

        self.User.write([self.User(USER)], {
            'company': self.company,
            'main_company': self.company,
        })

        CONTEXT.update(self.User.get_preferences(context_only=True))

        # Create Fiscal Year
        self._create_fiscal_year(company=self.company.id)
        # Create Chart of Accounts
        self._create_coa_minimal(company=self.company.id)
        # Create Cash journal
        self.cash_journal, = self.Journal.search([('type', '=', 'cash')],
                                                 limit=1)
        self.Journal.write(
            [self.cash_journal], {
                'debit_account': self._get_account_by_kind('expense').id,
                'credit_account': self._get_account_by_kind('expense').id,
            })

        self.beanstream_passcode_gateway = self.PaymentGateway(
            name='beanstream',
            journal=self.cash_journal,
            provider='beanstream',
            method='credit_card',
            beanstream_auth_mechanism='passcode',
            beanstream_merchant_id='300200425',
            beanstream_pass_code='B042485853bb4ee9b8269ADEAF6A60dd',
            beanstream_currency=currency,
            test=True)
        self.beanstream_passcode_gateway.save()

        self.beanstream_hash_gateway = self.PaymentGateway(
            name='beanstream',
            journal=self.cash_journal,
            provider='beanstream',
            method='credit_card',
            beanstream_auth_mechanism='hash',
            beanstream_merchant_id='300200425',
            beanstream_hash_key='de59b16d310ace6983af0b0a791c1d318f79ec9d',
            beanstream_currency=currency,
            test=True,
        )
        self.beanstream_hash_gateway.save()

        # Create parties
        self.party1, = self.Party.create([{
            'name':
            'Test party - 1',
            'addresses': [('create', [{
                'name': 'Amine Khechfe',
                'street': '247 High Street',
                'zip': '94301-1041',
                'city': 'Palo Alto',
                'country': self.country.id,
                'subdivision': self.subdivision.id,
            }])],
            'account_receivable':
            self._get_account_by_kind('receivable').id,
        }])
        self.party2, = self.Party.create([{
            'name':
            'Test party - 2',
            'addresses': [('create', [{
                'name': 'Amine Khechfe',
                'street': '247 High Street',
                'zip': '94301-1041',
                'city': 'Palo Alto',
                'country': self.country.id,
                'subdivision': self.subdivision.id,
            }])],
            'account_receivable':
            self._get_account_by_kind('receivable').id,
        }])
        self.party3, = self.Party.create([{
            'name':
            'Test party - 3',
            'addresses': [('create', [{
                'name': 'Amine Khechfe',
                'street': '247 High Street',
                'zip': '94301-1041',
                'city': 'Palo Alto',
                'country': self.country.id,
                'subdivision': self.subdivision.id,
            }])],
            'account_receivable':
            self._get_account_by_kind('receivable').id,
        }])

        self.card_data1 = self.UseCardView(
            number='4030000010001234',
            expiry_month='04',
            expiry_year=str(random.randint(2016, 2020)),
            csc='123',
            owner='Test User -1',
        )
        self.card_data2 = self.UseCardView(
            number='4111111111111111',
            expiry_month='08',
            expiry_year=str(random.randint(2016, 2020)),
            csc=str(random.randint(556, 999)),
            owner='Test User -2',
        )
        self.invalid_card_data = self.UseCardView(
            number='4111111111111111',
            expiry_month='08',
            expiry_year='2022',
            csc=str(911),
            owner='Test User -2',
        )

        self.payment_profile = self.PaymentProfile(
            party=self.party1,
            address=self.party1.addresses[0].id,
            gateway=self.beanstream_passcode_gateway.id,
            last_4_digits='1111',
            expiry_month='01',
            expiry_year='2018',
            provider_reference='26037832',
        )
        self.payment_profile.save()
コード例 #33
0
    def setup_defaults(self):
        """Method to setup defaults
        """
        # Create currency
        self.currency, = self.Currency.create([{
            'name': 'United Stated Dollar',
            'code': 'USD',
            'symbol': 'USD',
        }])
        self.Currency.create([{
            'name': 'Indian Rupee',
            'code': 'INR',
            'symbol': 'INR',
        }])

        country_us, = self.Country.create([{
            'name': 'United States',
            'code': 'US',
        }])

        country_in, = self.Country.create([{
            'name': 'India',
            'code': 'IN',
        }])

        subdivision_delhi, = self.CountrySubdivision.create([{
            'name': 'Delhi',
            'code': 'IN-DL',
            'country': country_in.id,
            'type': 'state'
        }])

        subdivision_florida, = self.CountrySubdivision.create([{
            'name': 'Florida',
            'code': 'US-FL',
            'country': country_us.id,
            'type': 'state'
        }])

        subdivision_california, = self.CountrySubdivision.create([{
            'name': 'California',
            'code': 'US-CA',
            'country': country_us.id,
            'type': 'state'
        }])

        with Transaction().set_context(company=None):
            company_party, = self.Party.create([{
                'name': 'Test Party',
                'vat_number': '123456',
                'addresses': [('create', [{
                    'name': 'Amine Khechfe',
                    'street': '247 High Street',
                    'zip': '94301',
                    'city': 'Palo Alto',
                    'country': country_us.id,
                    'subdivision': subdivision_california.id,
                }])]
            }])

        self.company, = self.Company.create([{
            'party': company_party.id,
            'currency': self.currency.id,
        }])
        self.PartyContact.create([{
            'type': 'phone',
            'value': '8005551212',
            'party': self.company.party.id
        }])

        self.User.write(
            [self.User(USER)], {
                'main_company': self.company.id,
                'company': self.company.id,
            }
        )

        CONTEXT.update(self.User.get_preferences(context_only=True))

        self._create_fiscal_year(company=self.company)
        self._create_coa_minimal(company=self.company)
        self.payment_term, = self._create_payment_term()

        account_revenue, = self.Account.search([
            ('kind', '=', 'revenue')
        ])

        # Create product category
        category, = self.Category.create([{
            'name': 'Test Category',
        }])

        uom_kg, = self.Uom.search([('symbol', '=', 'kg')])
        uom_cm, = self.Uom.search([('symbol', '=', 'cm')])
        uom_pound, = self.Uom.search([('symbol', '=', 'lb')])

        # Carrier Carrier Product
        carrier_product_template, = self.Template.create([{
            'name': 'Test Carrier Product',
            'category': category.id,
            'type': 'service',
            'salable': True,
            'sale_uom': uom_kg,
            'list_price': Decimal('10'),
            'cost_price': Decimal('5'),
            'default_uom': uom_kg,
            'cost_price_method': 'fixed',
            'account_revenue': account_revenue.id,
            'products': [('create', self.Template.default_products())]
        }])

        carrier_product = carrier_product_template.products[0]

        # Create product
        template, = self.Template.create([{
            'name': 'Test Product',
            'category': category.id,
            'type': 'goods',
            'salable': True,
            'sale_uom': uom_kg,
            'list_price': Decimal('10'),
            'cost_price': Decimal('5'),
            'default_uom': uom_kg,
            'account_revenue': account_revenue.id,
            'weight': .5,
            'weight_uom': uom_pound.id,
            'products': [('create', self.Template.default_products())]
        }])

        self.product = template.products[0]

        # Create party
        carrier_party, = self.Party.create([{
            'name': 'Test Party',
        }])

        # Create party
        carrier_party, = self.Party.create([{
            'name': 'Test Party',
        }])

        values = {
            'party': carrier_party.id,
            'currency': self.company.currency.id,
            'carrier_product': carrier_product.id,
            'carrier_cost_method': 'dpd',
            'dpd_url': self.dpd_server,
            'dpd_username': self.dpd_username,
            'dpd_password': self.dpd_password,
            'dpd_depot': '0163',
        }
        values.update(self.Carrier(**values).on_change_dpd_url())

        self.carrier, = self.Carrier.create([values])

        self.sale_party, self.sale_party2 = self.Party.create([{
            'name': 'Test Sale Party',
            'vat_number': '123456',
            'addresses': [('create', [{
                'name': 'John Doe',
                'street': '250 NE 25th St',
                'zip': '33137',
                'city': 'Miami, Miami-Dade',
                'country': country_us.id,
                'subdivision': subdivision_florida.id,
            }])]
        }, {
            'name': 'Test Sale Party2',
            'vat_number': '123456',
            'addresses': [('create', [{
                'name': 'John Wick',
                'street': '24, Kasturba Gandhi Marg',
                'zip': '110001',
                'city': 'New Delhi',
                'country': country_in.id,
                'subdivision': subdivision_delhi.id,
            }])]
        }])
        self.PartyContact.create([{
            'type': 'phone',
            'value': '8005763279',
            'party': self.sale_party.id
        }, {
            'type': 'phone',
            'value': '8005763279',
            'party': self.sale_party2.id
        }])
コード例 #34
0
    def test0010account_chart(self):
        'Test creation of minimal chart of accounts'
        with Transaction().start(DB_NAME, USER,
                context=CONTEXT) as transaction:
            account_template, = self.account_template.search([
                    ('parent', '=', None),
                    ])
            tax_account, = self.account_template.search([
                    ('name', '=', 'Main Tax'),
                    ])
            with Transaction().set_user(0):
                tax_code = self.tax_code_template()
                tax_code.name = 'Tax Code'
                tax_code.account = account_template
                tax_code.save()
                base_code = self.tax_code_template()
                base_code.name = 'Base Code'
                base_code.account = account_template
                base_code.save()
                tax = self.tax_template()
                tax.name = tax.description = '20% VAT'
                tax.type = 'percentage'
                tax.rate = Decimal('0.2')
                tax.account = account_template
                tax.invoice_account = tax_account
                tax.credit_note_account = tax_account
                tax.invoice_base_code = base_code
                tax.invoice_base_sign = Decimal(1)
                tax.invoice_tax_code = tax_code
                tax.invoice_tax_sign = Decimal(1)
                tax.credit_note_base_code = base_code
                tax.credit_note_base_sign = Decimal(-1)
                tax.credit_note_tax_code = tax_code
                tax.credit_note_tax_sign = Decimal(-1)
                tax.save()

            company, = self.company.search([
                    ('rec_name', '=', 'Dunder Mifflin'),
                    ])
            self.user.write([self.user(USER)], {
                    'main_company': company.id,
                    'company': company.id,
                    })
            CONTEXT.update(self.user.get_preferences(context_only=True))

            session_id, _, _ = self.account_create_chart.create()
            create_chart = self.account_create_chart(session_id)
            create_chart.account.account_template = account_template
            create_chart.account.company = company
            create_chart.transition_create_account()
            receivable, = self.account.search([
                    ('kind', '=', 'receivable'),
                    ('company', '=', company.id),
                    ])
            payable, = self.account.search([
                    ('kind', '=', 'payable'),
                    ('company', '=', company.id),
                    ])
            create_chart.properties.company = company
            create_chart.properties.account_receivable = receivable
            create_chart.properties.account_payable = payable
            create_chart.transition_create_properties()
            transaction.cursor.commit()
コード例 #35
0
    def setup_defaults(self):
        """
        Setup defaults
        """
        usd, = self.Currency.create([{
            'name': 'US Dollar',
            'code': 'USD',
            'symbol': '$',
        }])

        with Transaction().set_context(company=None):
            company_party, = self.Party.create([{
                'name': 'Openlabs',
                'addresses': [('create', [{
                    'name': 'Openlabs',
                }])],
            }])

        self.company, = self.Company.create([{
            'party': company_party.id,
            'currency': usd,
        }])

        self.User.write([self.User(USER)], {
            'company': self.company,
            'main_company': self.company,
        })

        CONTEXT.update(self.User.get_preferences(context_only=True))

        # Create Fiscal Year
        self._create_fiscal_year(company=self.company.id)
        # Create Chart of Accounts
        self._create_coa_minimal(company=self.company.id)
        # Create a payment term
        payment_term, = self._create_payment_term()

        channel_price_list, user_price_list = self._create_pricelists()
        party1, = self.Party.create([{
            'name': 'Guest User',
        }])

        party2, = self.Party.create([{
            'name': 'Registered User',
            'sale_price_list': user_price_list,
        }])

        self.party2 = party2

        party3, = self.Party.create([{
            'name': 'Registered User 2',
        }])

        # Create users and assign the pricelists to them
        self.guest_user, = self.NereidUser.create([{
            'party': party1.id,
            'display_name': 'Guest User',
            'email': '*****@*****.**',
            'password': '******',
            'company': self.company.id,
        }])
        self.registered_user, = self.NereidUser.create([{
            'party': party2.id,
            'display_name': 'Registered User',
            'email': '*****@*****.**',
            'password': '******',
            'company': self.company.id,
        }])
        self.registered_user2, = self.NereidUser.create([{
            'party': party3.id,
            'display_name': 'Registered User 2',
            'email': '*****@*****.**',
            'password': '******',
            'company': self.company.id,
        }])

        warehouse, = self.Location.search([
            ('type', '=', 'warehouse')
        ], limit=1)
        location, = self.Location.search([
            ('type', '=', 'storage')
        ], limit=1)
        en_us, = self.Language.search([('code', '=', 'en_US')])

        self.locale_en_us, = self.Locale.create([{
            'code': 'en_US',
            'language': en_us.id,
            'currency': usd.id,
        }])

        self.channel, = self.SaleChannel.create([{
            'name': 'Default Channel',
            'price_list': channel_price_list,
            'warehouse': warehouse,
            'payment_term': payment_term,
            'company': self.company.id,
            'create_users': [('add', [USER])],
            'invoice_method': 'order',
            'shipment_method': 'order',
            'source': 'manual'
        }])
        self.User.set_preferences({'current_channel': self.channel})

        self.User.write(
            [self.User(USER)], {
                'main_company': self.company.id,
                'company': self.company.id,
                'current_channel': self.channel,
            }
        )
        self.default_node, = self.Node.create([{
            'name': 'root',
            'slug': 'root',
        }])
        self.country, = self.Country.create([{
            'name': 'United States',
            'code': 'US',
        }])
        self.subdivision1, = self.Subdivision.create([{
            'country': self.country.id,
            'name': 'California',
            'code': 'US-CA',
            'type': 'state',
        }])
        self.NereidWebsite.create([{
            'name': 'localhost',
            'channel': self.channel,
            'company': self.company.id,
            'application_user': USER,
            'default_locale': self.locale_en_us.id,
            'guest_user': self.guest_user,
            'countries': [('add', [self.country.id])],
            'currencies': [('add', [usd.id])],
        }])
コード例 #36
0
    def setup_defaults(self):
        """Method to setup defaults
        """
        # Create currency
        self.currency, = self.Currency.create([{
            'name': 'United Stated Dollar',
            'code': 'USD',
            'symbol': 'USD',
        }])
        self.Currency.create([{
            'name': 'Indian Rupee',
            'code': 'INR',
            'symbol': 'INR',
        }])

        country_us, country_at = self.Country.create([{
            'name': 'United States',
            'code': 'US',
        }, {
            'name': 'Austria',
            'code': 'AT',
        }])

        subdivision_idaho, = self.Country_Subdivision.create([{
            'name': 'Idaho',
            'code': 'US-ID',
            'country': country_us.id,
            'type': 'state'
        }])

        subdivision_california, = self.Country_Subdivision.create([{
            'name': 'California',
            'code': 'US-CA',
            'country': country_us.id,
            'type': 'state'
        }])

        subdivision_steiermark, = self.Country_Subdivision.create([{
            'name': 'Steiermark',
            'code': 'AT-6',
            'country': country_at.id,
            'type': 'state'
        }])

        with Transaction().set_context(company=None):
            company_party, = self.Party.create([{
                'name': 'Test Party',
                'addresses': [('create', [{
                    'name': 'Amine Khechfe',
                    'street': '247 High Street',
                    'zip': '84301',
                    'city': 'Palo Alto',
                    'country': country_us.id,
                    'subdivision': subdivision_california.id,
                }])]
            }])

        # Endicia Configuration
        self.EndiciaConfiguration.create([{
            'account_id': '123456',
            'requester_id': '123456',
            'passphrase': 'PassPhrase',
            'is_test': True,
        }])
        self.company, = self.Company.create([{
            'party': company_party.id,
            'currency': self.currency.id,
        }])
        self.PartyContact.create([{
            'type': 'phone',
            'value': '8005551212',
            'party': self.company.party.id
        }])

        # Sale configuration
        endicia_mailclass, = self.EndiciaMailclass.search([
            ('value', '=', 'First')
        ])

        self.SaleConfig.write(self.SaleConfig(1), {
            'endicia_label_subtype': 'Integrated',
            'endicia_integrated_form_type': 'Form2976',
            'endicia_mailclass': endicia_mailclass.id,
            'endicia_include_postage': True,
        })

        self.User.write(
            [self.User(USER)], {
                'main_company': self.company.id,
                'company': self.company.id,
            }
        )

        CONTEXT.update(self.User.get_preferences(context_only=True))

        self._create_fiscal_year(company=self.company)
        self._create_coa_minimal(company=self.company)
        self.payment_term, = self._create_payment_term()

        account_revenue, = self.Account.search([
            ('kind', '=', 'revenue')
        ])

        # Create product category
        category, = self.Category.create([{
            'name': 'Test Category',
        }])

        uom_kg, = self.Uom.search([('symbol', '=', 'kg')])
        uom_oz, = self.Uom.search([('symbol', '=', 'oz')])

        # Carrier Carrier Product
        carrier_product_template, = self.Template.create([{
            'name': 'Test Carrier Product',
            'category': category.id,
            'type': 'service',
            'salable': True,
            'sale_uom': uom_kg,
            'list_price': Decimal('10'),
            'cost_price': Decimal('5'),
            'default_uom': uom_kg,
            'cost_price_method': 'fixed',
            'account_revenue': account_revenue.id,
            'products': [('create', self.Template.default_products())]
        }])

        self.carrier_product = carrier_product_template.products[0]

        # Create product
        template, = self.Template.create([{
            'name': 'Test Product',
            'category': category.id,
            'type': 'goods',
            'salable': True,
            'sale_uom': uom_kg,
            'list_price': Decimal('10.896'),
            'cost_price': Decimal('5.896'),
            'default_uom': uom_kg,
            'account_revenue': account_revenue.id,
            'weight': .1,
            'weight_uom': uom_oz.id,
            'products': [('create', self.Template.default_products())]
        }])

        self.product = template.products[0]

        # Create party
        carrier_party, = self.Party.create([{
            'name': 'Test Party',
        }])

        # Create party
        carrier_party, = self.Party.create([{
            'name': 'Test Party',
        }])

        self.carrier, = self.Carrier.create([{
            'party': carrier_party.id,
            'carrier_product': self.carrier_product.id,
            'carrier_cost_method': 'endicia',
        }])

        self.sale_party, = self.Party.create([{
            'name': 'Test Sale Party',
            'addresses': [('create', [{
                'name': 'John Doe',
                'street': '123 Main Street',
                'zip': '83702',
                'city': 'Boise',
                'country': country_us.id,
                'subdivision': subdivision_idaho.id,
            }, {
                'name': 'John Doe',
                'street': 'Johann Fuxgasse 36',
                'zip': '8010',
                'city': 'Graz',
                'country': country_at.id,
                'subdivision': subdivision_steiermark.id,
            }, {
                'name': 'John Doe',
                'street': '1735 Carleton St.',
                'streetbis': 'Apt A',
                'zip': '94703',
                'city': 'Berkeley',
                'country': country_us.id,
                'subdivision': subdivision_california.id,
            }])]
        }])
        self.PartyContact.create([{
            'type': 'phone',
            'value': '8005763279',
            'party': self.sale_party.id
        }])

        self.sale = self.create_sale(self.sale_party)
コード例 #37
0
def test_dataset(request):
    """Create minimal data needed for testing
    """
    from trytond.transaction import Transaction
    from trytond.tests.test_tryton import USER, CONTEXT, DB_NAME, POOL

    Party = POOL.get('party.party')
    Company = POOL.get('company.company')
    Employee = POOL.get('company.employee')
    Currency = POOL.get('currency.currency')
    User = POOL.get('res.user')
    FiscalYear = POOL.get('account.fiscalyear')
    Sequence = POOL.get('ir.sequence')
    AccountTemplate = POOL.get('account.account.template')
    Account = POOL.get('account.account')
    account_create_chart = POOL.get('account.create_chart', type="wizard")

    with Transaction().start(DB_NAME, USER, context=CONTEXT) as transaction:
        # Create company, employee and set it user's current company
        usd, = Currency.create([{
            'name': 'US Dollar',
            'code': 'USD',
            'symbol': '$',
        }])
        company_party, = Party.create([{
            'name':
            'Openlabs Technologies and Consulting (P) LTD.',
        }])
        employee_party, = Party.create([{
            'name': 'Prakash Pandey',
        }])
        company, = Company.create([{
            'party': company_party.id,
            'currency': usd.id,
        }])
        employee, = Employee.create([{
            'party': employee_party.id,
            'company': company.id,
        }])
        User.write([User(USER)], {
            'main_company': company.id,
            'company': company.id,
        })
        CONTEXT.update(User.get_preferences(context_only=True))

        # Create fiscal year
        date = datetime.date.today()

        fiscal_year, = FiscalYear.create([{
            'name':
            '%s' % date.year,
            'start_date':
            date + relativedelta(month=1, day=1),
            'end_date':
            date + relativedelta(month=12, day=31),
            'company':
            company.id,
            'post_move_sequence':
            Sequence.create([{
                'name': '%s' % date.year,
                'code': 'account.move',
                'company': company.id,
            }])[0],
        }])
        FiscalYear.create_period([fiscal_year])

        # Create minimal chart of account
        account_template, = AccountTemplate.search([('parent', '=', None)])

        session_id, _, _ = account_create_chart.create()
        create_chart = account_create_chart(session_id)
        create_chart.account.account_template = account_template
        create_chart.account.company = company
        create_chart.transition_create_account()

        receivable, = Account.search([
            ('kind', '=', 'receivable'),
            ('company', '=', company.id),
        ])
        payable, = Account.search([
            ('kind', '=', 'payable'),
            ('company', '=', company.id),
        ])
        create_chart.properties.company = company
        create_chart.properties.account_receivable = receivable
        create_chart.properties.account_payable = payable
        create_chart.transition_create_properties()

        transaction.cursor.commit()
コード例 #38
0
    def setup_defaults(self):
        """Creates default data for testing
        """
        self.currency, = self.Currency.create([{
            'name': 'US Dollar',
            'code': 'USD',
            'symbol': '$',
        }])

        with Transaction().set_context(company=None):
            company_party, = self.Party.create([{'name': 'openlabs'}])
            employee_party, = self.Party.create([{'name': 'Jim'}])

        self.company, = self.Company.create([{
            'party': company_party,
            'currency': self.currency,
        }])

        self.employee, = self.Employee.create([{
            'party': employee_party.id,
            'company': self.company.id,
        }])

        self.User.write(
            [self.User(USER)], {
                'company': self.company,
                'main_company': self.company,
                'employees': [('add', [self.employee.id])],
            })
        # Write employee separately as employees needs to be saved first
        self.User.write([self.User(USER)], {
            'employee': self.employee.id,
        })

        CONTEXT.update(self.User.get_preferences(context_only=True))

        # Create Fiscal Year
        self._create_fiscal_year(company=self.company.id)
        # Create Chart of Accounts
        self._create_coa_minimal(company=self.company.id)
        # Create a payment term
        self.payment_term, = self._create_payment_term()

        # Create carrier
        carrier_price_list, = self.PriceList.create([{
            'name':
            'PL 1',
            'company':
            self.company.id,
            'lines': [('create', [{
                'formula': '(unit_price * 0.0) + 5',
            }])],
        }])
        carrier_party, = self.Party.create([{
            'name': 'Pricelist Carrier',
        }])

        day, = self.Uom.search([('name', '=', 'Day')])
        carrier_product_template, = self.ProductTemplate.create([{
            'name':
            'Carrier Pricelist',
            'type':
            'service',
            'salable':
            True,
            'default_uom':
            day.id,
            'sale_uom':
            day.id,
            'account_revenue':
            self._get_account_by_kind('revenue').id,
            'list_price':
            Decimal('50'),
            'cost_price':
            Decimal('40'),
        }])
        carrier_product, = self.Product.create([{
            'template':
            carrier_product_template.id,
        }])
        self.carrier, = self.Carrier.create([{
            'party':
            carrier_party.id,
            'carrier_cost_method':
            'pricelist',
            'carrier_product':
            carrier_product.id,
            'price_list':
            carrier_price_list.id,
        }])

        unit, = self.Uom.search([('name', '=', 'Unit')])

        self.template1, = self.ProductTemplate.create([{
            'name':
            'Product 1',
            'type':
            'goods',
            'salable':
            True,
            'default_uom':
            unit.id,
            'sale_uom':
            unit.id,
            'list_price':
            Decimal('100'),
            'cost_price':
            Decimal('90'),
            'account_revenue':
            self._get_account_by_kind('revenue').id,
            'products': [('create', [{
                'code': 'product-1'
            }])]
        }])

        self.template2, = self.ProductTemplate.create([{
            'name':
            'Product 2',
            'type':
            'goods',
            'salable':
            True,
            'default_uom':
            unit.id,
            'sale_uom':
            unit.id,
            'list_price':
            Decimal('50'),
            'cost_price':
            Decimal('40'),
            'account_revenue':
            self._get_account_by_kind('revenue').id,
            'products': [('create', [{
                'code': 'product-1'
            }])]
        }])

        self.product1 = self.template1.products[0]
        self.product2 = self.template2.products[0]

        # Create sale party
        self.sale_party, = self.Party.create([{
            'name':
            'Test Sale Party',
            'addresses': [('create', [{
                'name': 'John Doe',
                'street': '123 Main Street',
                'zip': '83702',
                'city': 'Boise',
            }])]
        }])
コード例 #39
0
    def setup_defaults(self):
        """Method to setup defaults
        """
        # Create currency
        self.currency, = self.Currency.create([{
            'name': 'Euro',
            'code': 'EUR',
            'symbol': 'EUR',
        }])

        country_de, country_tw = self.Country.create([{
            'name': 'Germany',
            'code': 'DE',
        }, {
            'name': 'Taiwan',
            'code': 'TW',
        }])

        subdivision_bw, = self.Subdivision.create([{
            'name': 'Baden-Württemberg',
            'code': 'DE-BW',
            'type': 'state',
            'country': country_de.id,
        }])

        with Transaction().set_context(company=None):
            company_party, = self.Party.create([{
                'name': 'Orkos',
                'vat_number': '123456',
                'addresses': [('create', [{
                    'name': 'Fruchtzentrale Orkos',
                    'street': 'Luetzowstr. 28a',
                    'streetbis': '',
                    'zip': '45141',
                    'city': 'Dortmund',
                    'country': country_de.id,
                }])],
                'contact_mechanisms': [('create', [{
                    'type': 'phone',
                    'value': '030244547777778',
                }, {
                    'type': 'email',
                    'value': '*****@*****.**',
                }, {
                    'type': 'fax',
                    'value': '030244547777778',
                }, {
                    'type': 'mobile',
                    'value': '9876543212',
                }, {
                    'type': 'website',
                    'value': 'example.com',
                }])],
            }])

        self.company, = self.Company.create([{
            'party': company_party.id,
            'currency': self.currency.id,
        }])

        self.User.write(
            [self.User(USER)], {
                'main_company': self.company.id,
                'company': self.company.id,
            }
        )

        CONTEXT.update(self.User.get_preferences(context_only=True))

        self._create_fiscal_year(company=self.company)
        self._create_coa_minimal(company=self.company)
        self.payment_term, = self._create_payment_term()

        account_revenue, = self.Account.search([
            ('kind', '=', 'revenue')
        ])

        # Create product category
        category, = self.Category.create([{
            'name': 'Test Category',
        }])

        uom_kg, = self.Uom.search([('symbol', '=', 'kg')])
        uom_cm, = self.Uom.search([('symbol', '=', 'cm')])
        uom_pound, = self.Uom.search([('symbol', '=', 'lb')])

        # Carrier Carrier Product
        carrier_product_template, = self.Template.create([{
            'name': 'Test Carrier Product',
            'category': category.id,
            'type': 'service',
            'salable': True,
            'sale_uom': uom_kg,
            'list_price': Decimal('10'),
            'cost_price': Decimal('5'),
            'default_uom': uom_kg,
            'cost_price_method': 'fixed',
            'account_revenue': account_revenue.id,
            'products': [('create', self.Template.default_products())]
        }])

        carrier_product = carrier_product_template.products[0]

        # Create product
        template, = self.Template.create([{
            'name': 'Test Product',
            'category': category.id,
            'type': 'goods',
            'salable': True,
            'sale_uom': uom_kg,
            'list_price': Decimal('10'),
            'cost_price': Decimal('5'),
            'default_uom': uom_kg,
            'account_revenue': account_revenue.id,
            'weight': .5,
            'weight_uom': uom_pound.id,
            'products': [('create', self.Template.default_products())]
        }])

        self.product = template.products[0]

        # Create party
        carrier_party, = self.Party.create([{
            'name': 'Test Party',
        }])

        # Create party
        carrier_party, = self.Party.create([{
            'name': 'Test Party',
        }])

        values = {
            'party': carrier_party.id,
            'currency': self.company.currency.id,
            'carrier_product': carrier_product.id,
            'carrier_cost_method': 'gls',
            'gls_server': self.gls_server,
            'gls_port': self.gls_port,
            'gls_contract': self.gls_contract,
            'gls_customer_id': '2760179437',
            'gls_location': 'DE 460',
            'gls_shipping_depot_number': '46',
            'gls_is_test': True,
            'gls_customer_number': '15082',
            'gls_consignor_label': 'Empfanger',
            'gls_customer_id_label': 'ID-Nr',
            'gls_customer_label': 'Kd-Nr',
        }

        self.carrier, = self.Carrier.create([values])

        self.sale_party, self.sale_party2 = self.Party.create([{
            'name': 'GLS Germany',
            'vat_number': '123456',
            'addresses': [('create', [{
                'name': 'GLS Germany',
                'street': 'Huckarder Str. 91',
                'streetbis': '',
                'zip': '44147',
                'city': 'Dortmund',
                'country': country_de.id,
                'subdivision': subdivision_bw.id,
            }])],
            'contact_mechanisms': [('create', [{
                'type': 'phone',
                'value': '+886 2 27781-8',
            }, {
                'type': 'email',
                'value': '*****@*****.**',
            }])],
        }, {
            'name': 'Klammer Company',
            'vat_number': '123456',
            'addresses': [('create', [{
                'name': 'John Wick',
                'street': 'Chung Hsiao East Road.',
                'streetbis': '55',
                'zip': '100',
                'city': 'Taipeh',
                'country': country_tw.id,
            }])],
            'contact_mechanisms': [('create', [{
                'type': 'phone',
                'value': '+886 2 27781-8',
            }, {
                'type': 'email',
                'value': '*****@*****.**',
            }])],
        }])
        sale_config = self.SaleConfig()
        sale_config.save()
コード例 #40
0
    def setup_defaults(self):
        """
        Setup the defaults
        """

        self.User.write([self.User(USER)], {
            'main_company': self.company.id,
            'company': self.company.id,
        })
        CONTEXT.update(self.User.get_preferences(context_only=True))

        # Create Fiscal Year
        self._create_fiscal_year(company=self.company.id)
        # Create Chart of Accounts
        self._create_coa_minimal(company=self.company.id)
        # Create a payment term
        self._create_payment_term()

        guest_price_list, user_price_list = self._create_pricelists()

        party1, = self.Party.create([{
            'name': 'Guest User',
            'sale_price_list': guest_price_list
        }])

        party2, = self.Party.create([{
            'name': 'Registered User',
            'sale_price_list': user_price_list,
        }])

        party3, = self.Party.create([{
            'name': 'Registered User 2',
        }])

        # Create users and assign the pricelists to them
        guest_user, = self.NereidUser.create([{
            'party': party1.id,
            'display_name': 'Guest User',
            'email': '*****@*****.**',
            'password': '******',
            'company': self.company.id,
        }])
        self.registered_user, = self.NereidUser.create([{
            'party':
            party2.id,
            'display_name':
            'Registered User',
            'email':
            '*****@*****.**',
            'password':
            '******',
            'company':
            self.company.id,
        }])
        self.registered_user2, = self.NereidUser.create([{
            'party':
            party3.id,
            'display_name':
            'Registered User 2',
            'email':
            '*****@*****.**',
            'password':
            '******',
            'company':
            self.company.id,
        }])

        self._create_countries()
        self.available_countries = self.Country.search([], limit=5)

        self.category, = self._create_product_category('Category',
                                                       [{
                                                           'uri': 'category'
                                                       }])

        warehouse, = self.Location.search([('type', '=', 'warehouse')],
                                          limit=1)
        location, = self.Location.search([('type', '=', 'storage')], limit=1)
        url_map, = self.UrlMap.search([], limit=1)
        en_us, = self.Language.search([('code', '=', 'en_US')])

        self.locale_en_us, = self.Locale.create([{
            'code': 'en_US',
            'language': en_us.id,
            'currency': self.usd.id,
        }])
        self.NereidWebsite.create([{
            'name':
            'localhost',
            'url_map':
            url_map,
            'company':
            self.company.id,
            'application_user':
            USER,
            'default_locale':
            self.locale_en_us.id,
            'guest_user':
            guest_user,
            'countries': [('set', self.available_countries)],
            'warehouse':
            warehouse,
            'stock_location':
            location,
            'categories': [('set', [self.category.id])],
            'currencies': [('set', [self.usd.id])],
        }])

        # Create product templates with products
        self.template1, = self._create_product_template(
            'product-1',
            [{
                'category': self.category.id,
                'type': 'goods',
                'salable': True,
                'list_price': Decimal('10'),
                'cost_price': Decimal('5'),
                'account_expense': self._get_account_by_kind('expense').id,
                'account_revenue': self._get_account_by_kind('revenue').id,
            }],
            uri='product-1',
        )
        self.template2, = self._create_product_template(
            'product-2',
            [{
                'category': self.category.id,
                'type': 'goods',
                'salable': True,
                'list_price': Decimal('15'),
                'cost_price': Decimal('5'),
                'account_expense': self._get_account_by_kind('expense').id,
                'account_revenue': self._get_account_by_kind('revenue').id,
            }],
            uri='product-2',
        )
        self.product1 = self.template1.products[0]
        self.product2 = self.template2.products[0]
コード例 #41
0
def dataset(request):
    """Create minimal data needed for testing
    """
    from trytond.transaction import Transaction
    from trytond.tests.test_tryton import USER, CONTEXT, DB_NAME, POOL

    Party = POOL.get('party.party')
    Company = POOL.get('company.company')
    Country = POOL.get('country.country')
    Subdivision = POOL.get('country.subdivision')
    Employee = POOL.get('company.employee')
    Currency = POOL.get('currency.currency')
    SequenceStrict = POOL.get('ir.sequence.strict')
    User = POOL.get('res.user')
    FiscalYear = POOL.get('account.fiscalyear')
    Sequence = POOL.get('ir.sequence')
    AccountTemplate = POOL.get('account.account.template')
    Account = POOL.get('account.account')
    ProductTemplate = POOL.get('product.template')
    Product = POOL.get('product.product')
    Uom = POOL.get('product.uom')
    Carrier = POOL.get('carrier')
    PaymentTerm = POOL.get('account.invoice.payment_term')
    FedExShipmentMethod = POOL.get('fedex.shipment.method')
    StockLocation = POOL.get('stock.location')
    SaleConfiguration = POOL.get('sale.configuration')
    AccountCreateChart = POOL.get('account.create_chart', type="wizard")

    with Transaction().start(DB_NAME, USER, context=CONTEXT) as transaction:
        # Create company, employee and set it user's current company
        usd, = Currency.create([{
            'name': 'US Dollar',
            'code': 'USD',
            'symbol': '$',
        }])

        country_us, = Country.create([{
            'name': 'United States',
            'code': 'US',
        }])
        subdivision_florida, = Subdivision.create([{
            'name': 'Florida',
            'code': 'US-FL',
            'country': country_us.id,
            'type': 'state'
        }])
        subdivision_california, = Subdivision.create([{
            'name': 'California',
            'code': 'US-CA',
            'country': country_us.id,
            'type': 'state'
        }])

        company_party, = Party.create([{
            'name':
            'ABC Corp.',
            'addresses': [('create', [{
                'name': 'ABC Corp.',
                'street': '247 High Street',
                'zip': '94301-1041',
                'city': 'Palo Alto',
                'country': country_us.id,
                'subdivision': subdivision_california.id,
            }])],
            'contact_mechanisms': [('create', [{
                'type': 'phone',
                'value': '123456789'
            }])]
        }])

        employee_party, = Party.create([{
            'name': 'Prakash Pandey',
        }])
        company, = Company.create([{
            'party': company_party.id,
            'currency': usd.id,
        }])
        employee, = Employee.create([{
            'party': employee_party.id,
            'company': company.id,
        }])
        User.write([User(USER)], {
            'main_company': company.id,
            'company': company.id,
        })
        CONTEXT.update(User.get_preferences(context_only=True))

        # Set warehouse address as company address
        StockLocation.write(StockLocation.search([('type', '=', 'warehouse')]),
                            {
                                'address': company_party.addresses[0].id,
                            })

        # Create fiscal year
        date = datetime.date.today()

        post_move_sequence, = Sequence.create([{
            'name': '%s' % date.year,
            'code': 'account.move',
            'company': company.id,
        }])
        invoice_sequence, = SequenceStrict.create([{
            'name': '%s' % date.year,
            'code': 'account.invoice',
            'company': company.id,
        }])

        fiscal_year, = FiscalYear.create([{
            'name':
            '%s' % date.year,
            'start_date':
            date + relativedelta(month=1, day=1),
            'end_date':
            date + relativedelta(month=12, day=31),
            'company':
            company.id,
            'post_move_sequence':
            post_move_sequence.id,
            'out_invoice_sequence':
            invoice_sequence.id,
            'in_invoice_sequence':
            invoice_sequence.id,
            'out_credit_note_sequence':
            invoice_sequence.id,
            'in_credit_note_sequence':
            invoice_sequence.id,
        }])
        FiscalYear.create_period([fiscal_year])

        # Create minimal chart of account
        account_template, = AccountTemplate.search([('parent', '=', None)])

        session_id, _, _ = AccountCreateChart.create()
        create_chart = AccountCreateChart(session_id)
        create_chart.account.account_template = account_template
        create_chart.account.company = company
        create_chart.transition_create_account()

        receivable, = Account.search([
            ('kind', '=', 'receivable'),
            ('company', '=', company.id),
        ])
        payable, = Account.search([
            ('kind', '=', 'payable'),
            ('company', '=', company.id),
        ])
        create_chart.properties.company = company
        create_chart.properties.account_receivable = receivable
        create_chart.properties.account_payable = payable
        create_chart.transition_create_properties()

        account_revenue, = Account.search([('kind', '=', 'revenue')])

        # Create payment term
        payment_term, = PaymentTerm.create([{
            'name':
            'Direct',
            'lines': [('create', [{
                'type': 'remainder'
            }])]
        }])

        # Create Products
        uom_pound, = Uom.search([('symbol', '=', 'lb')])
        uom_unit, = Uom.search([('symbol', '=', 'u')])
        uom_day, = Uom.search([('symbol', '=', 'd')])

        product_template, = ProductTemplate.create([{
            'name':
            'KindleFire',
            'type':
            'goods',
            'salable':
            True,
            'sale_uom':
            uom_unit.id,
            'list_price':
            Decimal('119'),
            'cost_price':
            Decimal('100'),
            'default_uom':
            uom_unit.id,
            'account_revenue':
            account_revenue.id,
            'weight':
            .7,
            'weight_uom':
            uom_pound.id,
            'products': [],
        }])

        product1, product2 = Product.create([{
            'code': 'ABC',
            'template': product_template.id,
        }, {
            'code': 'MAD',
            'template': product_template.id,
        }])

        # Create carrier
        carrier_party, = Party.create([{
            'name': 'FedEx',
        }])
        fedex_carrier_product_template, = ProductTemplate.create([{
            'name':
            'FedEx Carrier Product',
            'type':
            'service',
            'salable':
            True,
            'sale_uom':
            uom_day,
            'list_price':
            Decimal('0'),
            'cost_price':
            Decimal('0'),
            'default_uom':
            uom_day,
            'cost_price_method':
            'fixed',
            'account_revenue':
            account_revenue.id,
            'products': [('create', [{
                'code': '001',
            }])]
        }])
        fedex_carrier_product, = fedex_carrier_product_template.products

        fedex_carrier, = Carrier.create([{
            'party':
            carrier_party.id,
            'carrier_product':
            fedex_carrier_product.id,
            'currency':
            usd.id,
            'carrier_cost_method':
            'fedex',
            'fedex_key':
            'w8B7YBVgtfnDgn0k',
            'fedex_account_number':
            '510088000',
            'fedex_password':
            '******',
            'fedex_meter_number':
            '118518591',
            'fedex_integrator_id':
            '123',
            'fedex_product_id':
            'TEST',
            'fedex_product_version':
            '9999',
        }])

        # Create customer
        customer, = Party.create([{
            'name':
            'John Doe',
            'addresses': [('create', [{
                'name': 'John Doe',
                'street': '250 NE 25th St',
                'zip': '33137',
                'city': 'Miami, Miami-Dade',
                'country': country_us.id,
                'subdivision': subdivision_florida.id,
            }])],
            'contact_mechanisms': [('create', [{
                'type': 'phone',
                'value': '123456789'
            }])]
        }])

        def get_fedex_drop_off_type(value):
            res, = FedExShipmentMethod.search([
                ('method_type', '=', 'dropoff'),
                ('value', '=', value),
            ])
            return res.id

        def get_fedex_packaging_type(value):
            res, = FedExShipmentMethod.search([
                ('method_type', '=', 'packaging'),
                ('value', '=', value),
            ])
            return res.id

        def get_fedex_service_type(value):
            res, = FedExShipmentMethod.search([
                ('method_type', '=', 'service'),
                ('value', '=', value),
            ])
            return res.id

        sale_config = SaleConfiguration(1)
        sale_config.fedex_drop_off_type = \
            get_fedex_drop_off_type('REGULAR_PICKUP')
        sale_config.fedex_packaging_type = \
            get_fedex_packaging_type('FEDEX_BOX')
        sale_config.fedex_service_type = get_fedex_service_type('FEDEX_2_DAY')
        sale_config.save()

        result = {
            'customer': customer,
            'company': company,
            'product1': product1,
            'product2': product2,
            'fedex_carrier': fedex_carrier,
            'currency_usd': usd,
            'payment_term': payment_term,
            'uom_unit': uom_unit,
            'get_fedex_drop_off_type': get_fedex_drop_off_type,
            'get_fedex_packaging_type': get_fedex_packaging_type,
            'get_fedex_service_type': get_fedex_service_type,
        }

        transaction.cursor.commit()

    def get():
        from trytond.model import Model

        for key, value in result.iteritems():
            if isinstance(value, Model):
                result[key] = value.__class__(value.id)
        return namedtuple('Dataset', result.keys())(**result)

    return get
コード例 #42
0
    def setup_defaults(self):
        """
        Setup defaults
        """
        usd, = self.Currency.create([{"name": "US Dollar", "code": "USD", "symbol": "$"}])

        with Transaction().set_context(company=None):
            company_party, = self.Party.create(
                [{"name": "Openlabs", "addresses": [("create", [{"name": "Openlabs"}])]}]
            )

        self.company, = self.Company.create([{"party": company_party.id, "currency": usd}])

        self.User.write([self.User(USER)], {"company": self.company, "main_company": self.company})

        CONTEXT.update(self.User.get_preferences(context_only=True))

        # Create Fiscal Year
        self._create_fiscal_year(company=self.company.id)
        # Create Chart of Accounts
        self._create_coa_minimal(company=self.company.id)
        # Create a payment term
        payment_term, = self._create_payment_term()

        channel_price_list, user_price_list = self._create_pricelists()
        party1, = self.Party.create([{"name": "Guest User"}])

        party2, = self.Party.create([{"name": "Registered User", "sale_price_list": user_price_list}])

        self.party2 = party2

        party3, = self.Party.create([{"name": "Registered User 2"}])

        # Create users and assign the pricelists to them
        self.guest_user, = self.NereidUser.create(
            [
                {
                    "party": party1.id,
                    "display_name": "Guest User",
                    "email": "*****@*****.**",
                    "password": "******",
                    "company": self.company.id,
                }
            ]
        )
        self.registered_user, = self.NereidUser.create(
            [
                {
                    "party": party2.id,
                    "display_name": "Registered User",
                    "email": "*****@*****.**",
                    "password": "******",
                    "company": self.company.id,
                }
            ]
        )
        self.registered_user2, = self.NereidUser.create(
            [
                {
                    "party": party3.id,
                    "display_name": "Registered User 2",
                    "email": "*****@*****.**",
                    "password": "******",
                    "company": self.company.id,
                }
            ]
        )

        warehouse, = self.Location.search([("type", "=", "warehouse")], limit=1)
        location, = self.Location.search([("type", "=", "storage")], limit=1)
        en_us, = self.Language.search([("code", "=", "en_US")])

        self.locale_en_us, = self.Locale.create([{"code": "en_US", "language": en_us.id, "currency": usd.id}])

        with Transaction().set_context({"company": self.company.id}):
            self.channel, = self.SaleChannel.create(
                [
                    {
                        "name": "Default Channel",
                        "price_list": channel_price_list,
                        "warehouse": warehouse,
                        "payment_term": payment_term,
                        "create_users": [("add", [USER])],
                        "invoice_method": "order",
                        "shipment_method": "order",
                        "source": "webshop",
                    }
                ]
            )
        self.User.set_preferences({"current_channel": self.channel})

        self.User.write(
            [self.User(USER)],
            {"main_company": self.company.id, "company": self.company.id, "current_channel": self.channel},
        )
        self.default_node, = self.Node.create([{"name": "root", "slug": "root"}])
        self.country, = self.Country.create([{"name": "United States", "code": "US"}])
        self.subdivision1, = self.Subdivision.create(
            [{"country": self.country.id, "name": "California", "code": "US-CA", "type": "state"}]
        )
        self.NereidWebsite.create(
            [
                {
                    "name": "localhost",
                    "channel": self.channel,
                    "company": self.company.id,
                    "application_user": USER,
                    "default_locale": self.locale_en_us.id,
                    "guest_user": self.guest_user,
                    "countries": [("add", [self.country.id])],
                    "currencies": [("add", [usd.id])],
                }
            ]
        )
コード例 #43
0
    def setup_defaults(self):
        """Creates default data for testing
        """
        self.country, = self.Country.create([{
            'name': 'United States of America',
            'code': 'US',
        }])
        self.subdivision, = self.Subdivision.create([{
            'country': self.country.id,
            'name': 'California',
            'code': 'CA',
            'type': 'state',
        }])

        self.currency, = self.Currency.create([{
            'name': 'US Dollar',
            'code': 'USD',
            'symbol': '$',
        }])

        with Transaction().set_context(company=None):
            company_party, = self.Party.create([{'name': 'openlabs'}])

        self.company, = self.Company.create([{
            'party': company_party,
            'currency': self.currency,
        }])

        self.User.write([self.User(USER)], {
            'company': self.company,
            'main_company': self.company,
        })
        CONTEXT.update(self.User.get_preferences(context_only=True))

        # Create Fiscal Year
        self._create_fiscal_year(company=self.company.id)
        # Create Chart of Accounts
        self._create_coa_minimal(company=self.company.id)
        # Create a payment term
        self.payment_term, = self._create_payment_term()

        self.cash_journal, = self.Journal.search([('type', '=', 'cash')],
                                                 limit=1)
        self.Journal.write(
            [self.cash_journal],
            {'debit_account': self._get_account_by_kind('other').id})

        # Create party
        self.party, = self.Party.create([{
            'name':
            'Bruce Wayne',
            'addresses': [('create', [{
                'name': 'Bruce Wayne',
                'party': Eval('id'),
                'city': 'Gotham',
                'invoice': True,
                'country': self.country.id,
                'subdivision': self.subdivision.id,
            }])],
            'customer_payment_term':
            self.payment_term.id,
            'account_receivable':
            self._get_account_by_kind('receivable').id,
            'contact_mechanisms': [('create', [
                {
                    'type': 'email',
                    'value': '*****@*****.**'
                },
            ])],
        }])

        # Add address to company's party record
        self.Party.write(
            [self.company.party], {
                'addresses': [('create', [{
                    'name': 'Openlabs',
                    'city': 'LA',
                    'country': self.country.id,
                    'subdivision': self.subdivision.id,
                }])],
            })

        self.uom, = self.Uom.search([('name', '=', 'Unit')])
        self.product_category, = self.ProductCategory.create([{
            'name':
            'Automobile',
            'account_revenue':
            self._get_account_by_kind('revenue', company=self.company.id).id,
            'account_expense':
            self._get_account_by_kind('expense', company=self.company.id).id,
        }])

        self.product_template, = self.ProductTemplate.create([{
            'name':
            'Bat Mobile',
            'type':
            'goods',
            'salable':
            True,
            'category':
            self.product_category.id,
            'default_uom':
            self.uom.id,
            'sale_uom':
            self.uom.id,
            'list_price':
            Decimal('20000'),
            'cost_price':
            Decimal('15000'),
            'account_category':
            True,
        }])

        self.product, = self.Product.create([{
            'template':
            self.product_template.id,
            'code':
            '123',
        }])

        warehouse = self.StockLocation.search([('type', '=', 'warehouse')])[0]
        warehouse.address = self.company.party.addresses[0].id
        warehouse.save()

        Inventory = POOL.get('stock.inventory')

        # Create and confirm inventory
        inventory, = Inventory.create([{
            'location':
            warehouse.storage_location,
            'company':
            self.company.id,
            'lines': [('create', [{
                'product': self.product,
                'quantity': 100,
            }])]
        }])
        Inventory.confirm([inventory])
コード例 #44
0
def dataset(request):
    """Create minimal data needed for testing
    """
    from trytond.transaction import Transaction
    from trytond.tests.test_tryton import USER, CONTEXT, DB_NAME, POOL

    Party = POOL.get("party.party")
    Company = POOL.get("company.company")
    Country = POOL.get("country.country")
    Subdivision = POOL.get("country.subdivision")
    Employee = POOL.get("company.employee")
    Currency = POOL.get("currency.currency")
    SequenceStrict = POOL.get("ir.sequence.strict")
    User = POOL.get("res.user")
    FiscalYear = POOL.get("account.fiscalyear")
    Sequence = POOL.get("ir.sequence")
    AccountTemplate = POOL.get("account.account.template")
    Account = POOL.get("account.account")
    ProductTemplate = POOL.get("product.template")
    Product = POOL.get("product.product")
    Uom = POOL.get("product.uom")
    Carrier = POOL.get("carrier")
    PaymentTerm = POOL.get("account.invoice.payment_term")
    FedExShipmentMethod = POOL.get("fedex.shipment.method")
    StockLocation = POOL.get("stock.location")
    SaleConfiguration = POOL.get("sale.configuration")
    AccountCreateChart = POOL.get("account.create_chart", type="wizard")

    with Transaction().start(DB_NAME, USER, context=CONTEXT) as transaction:
        # Create company, employee and set it user's current company
        usd, = Currency.create([{"name": "US Dollar", "code": "USD", "symbol": "$"}])

        country_us, = Country.create([{"name": "United States", "code": "US"}])
        subdivision_florida, = Subdivision.create(
            [{"name": "Florida", "code": "US-FL", "country": country_us.id, "type": "state"}]
        )
        subdivision_california, = Subdivision.create(
            [{"name": "California", "code": "US-CA", "country": country_us.id, "type": "state"}]
        )

        company_party, = Party.create(
            [
                {
                    "name": "ABC Corp.",
                    "addresses": [
                        (
                            "create",
                            [
                                {
                                    "name": "ABC Corp.",
                                    "street": "247 High Street",
                                    "zip": "94301-1041",
                                    "city": "Palo Alto",
                                    "country": country_us.id,
                                    "subdivision": subdivision_california.id,
                                }
                            ],
                        )
                    ],
                    "contact_mechanisms": [("create", [{"type": "phone", "value": "123456789"}])],
                }
            ]
        )

        employee_party, = Party.create([{"name": "Prakash Pandey"}])
        company, = Company.create([{"party": company_party.id, "currency": usd.id}])
        employee, = Employee.create([{"party": employee_party.id, "company": company.id}])
        User.write([User(USER)], {"main_company": company.id, "company": company.id})
        CONTEXT.update(User.get_preferences(context_only=True))

        # Set warehouse address as company address
        StockLocation.write(
            StockLocation.search([("type", "=", "warehouse")]), {"address": company_party.addresses[0].id}
        )

        # Create fiscal year
        date = datetime.date.today()

        post_move_sequence, = Sequence.create(
            [{"name": "%s" % date.year, "code": "account.move", "company": company.id}]
        )
        invoice_sequence, = SequenceStrict.create(
            [{"name": "%s" % date.year, "code": "account.invoice", "company": company.id}]
        )

        fiscal_year, = FiscalYear.create(
            [
                {
                    "name": "%s" % date.year,
                    "start_date": date + relativedelta(month=1, day=1),
                    "end_date": date + relativedelta(month=12, day=31),
                    "company": company.id,
                    "post_move_sequence": post_move_sequence.id,
                    "out_invoice_sequence": invoice_sequence.id,
                    "in_invoice_sequence": invoice_sequence.id,
                    "out_credit_note_sequence": invoice_sequence.id,
                    "in_credit_note_sequence": invoice_sequence.id,
                }
            ]
        )
        FiscalYear.create_period([fiscal_year])

        # Create minimal chart of account
        account_template, = AccountTemplate.search([("parent", "=", None)])

        session_id, _, _ = AccountCreateChart.create()
        create_chart = AccountCreateChart(session_id)
        create_chart.account.account_template = account_template
        create_chart.account.company = company
        create_chart.transition_create_account()

        receivable, = Account.search([("kind", "=", "receivable"), ("company", "=", company.id)])
        payable, = Account.search([("kind", "=", "payable"), ("company", "=", company.id)])
        create_chart.properties.company = company
        create_chart.properties.account_receivable = receivable
        create_chart.properties.account_payable = payable
        create_chart.transition_create_properties()

        account_revenue, = Account.search([("kind", "=", "revenue")])

        # Create payment term
        payment_term, = PaymentTerm.create([{"name": "Direct", "lines": [("create", [{"type": "remainder"}])]}])

        # Create Products
        uom_pound, = Uom.search([("symbol", "=", "lb")])
        uom_unit, = Uom.search([("symbol", "=", "u")])
        uom_day, = Uom.search([("symbol", "=", "d")])

        product_template, = ProductTemplate.create(
            [
                {
                    "name": "KindleFire",
                    "type": "goods",
                    "salable": True,
                    "sale_uom": uom_unit.id,
                    "list_price": Decimal("119"),
                    "cost_price": Decimal("100"),
                    "default_uom": uom_unit.id,
                    "account_revenue": account_revenue.id,
                    "weight": 0.7,
                    "weight_uom": uom_pound.id,
                    "products": [],
                }
            ]
        )

        product1, product2 = Product.create(
            [{"code": "ABC", "template": product_template.id}, {"code": "MAD", "template": product_template.id}]
        )

        # Create carrier
        carrier_party, = Party.create([{"name": "FedEx"}])
        fedex_carrier_product_template, = ProductTemplate.create(
            [
                {
                    "name": "FedEx Carrier Product",
                    "type": "service",
                    "salable": True,
                    "sale_uom": uom_day,
                    "list_price": Decimal("0"),
                    "cost_price": Decimal("0"),
                    "default_uom": uom_day,
                    "cost_price_method": "fixed",
                    "account_revenue": account_revenue.id,
                    "products": [("create", [{"code": "001"}])],
                }
            ]
        )
        fedex_carrier_product, = fedex_carrier_product_template.products

        fedex_carrier, = Carrier.create(
            [
                {
                    "party": carrier_party.id,
                    "carrier_product": fedex_carrier_product.id,
                    "currency": usd.id,
                    "carrier_cost_method": "fedex",
                    "fedex_key": "w8B7YBVgtfnDgn0k",
                    "fedex_account_number": "510088000",
                    "fedex_password": "******",
                    "fedex_meter_number": "118518591",
                    "fedex_is_test": True,
                }
            ]
        )

        # Create customer
        customer, = Party.create(
            [
                {
                    "name": "John Doe",
                    "addresses": [
                        (
                            "create",
                            [
                                {
                                    "name": "John Doe",
                                    "street": "250 NE 25th St",
                                    "zip": "33137",
                                    "city": "Miami, Miami-Dade",
                                    "country": country_us.id,
                                    "subdivision": subdivision_florida.id,
                                }
                            ],
                        )
                    ],
                    "contact_mechanisms": [("create", [{"type": "phone", "value": "123456789"}])],
                }
            ]
        )

        def get_fedex_drop_off_type(value):
            res, = FedExShipmentMethod.search([("method_type", "=", "dropoff"), ("value", "=", value)])
            return res.id

        def get_fedex_packaging_type(value):
            res, = FedExShipmentMethod.search([("method_type", "=", "packaging"), ("value", "=", value)])
            return res.id

        def get_fedex_service_type(value):
            res, = FedExShipmentMethod.search([("method_type", "=", "service"), ("value", "=", value)])
            return res.id

        sale_config = SaleConfiguration(1)
        sale_config.fedex_drop_off_type = get_fedex_drop_off_type("REGULAR_PICKUP")
        sale_config.fedex_packaging_type = get_fedex_packaging_type("FEDEX_BOX")
        sale_config.fedex_service_type = get_fedex_service_type("FEDEX_2_DAY")
        sale_config.save()

        result = {
            "customer": customer,
            "company": company,
            "product1": product1,
            "product2": product2,
            "fedex_carrier": fedex_carrier,
            "currency_usd": usd,
            "payment_term": payment_term,
            "uom_unit": uom_unit,
            "get_fedex_drop_off_type": get_fedex_drop_off_type,
            "get_fedex_packaging_type": get_fedex_packaging_type,
            "get_fedex_service_type": get_fedex_service_type,
        }

        transaction.cursor.commit()

    def get():
        from trytond.model import Model

        for key, value in result.iteritems():
            if isinstance(value, Model):
                result[key] = value.__class__(value.id)
        return namedtuple("Dataset", result.keys())(**result)

    return get
コード例 #45
0
    def setup_defaults(self):
        """
        Creates default data for testing
        """
        currency, = self.Currency.create([{
            'name': 'US Dollar',
            'code': 'USD',
            'symbol': '$',
        }])

        with Transaction().set_context(company=None):
            company_party, = self.Party.create([{
                'name': 'Openlabs'
            }])

        self.company, = self.Company.create([{
            'party': company_party,
            'currency': currency,
        }])

        self.User.write([self.User(USER)], {
            'company': self.company,
            'main_company': self.company,
        })

        CONTEXT.update(self.User.get_preferences(context_only=True))

        # Create Fiscal Year
        self._create_fiscal_year(company=self.company.id)
        # Create Chart of Accounts
        self._create_coa_minimal(company=self.company.id)
        # Create Cash journal
        self.cash_journal, = self.Journal.search(
            [('type', '=', 'cash')], limit=1
        )
        self.Journal.write([self.cash_journal], {
            'debit_account': self._get_account_by_kind('expense').id
        })

        self.auth_net_gateway = self.PaymentGateway(
            name='Authorize.net',
            journal=self.cash_journal,
            provider='authorize_net',
            method='credit_card',
            authorize_net_login='******',
            authorize_net_transaction_key='32jF65cTxja88ZA2',
            test=True
        )
        self.auth_net_gateway.save()

        # Create parties
        self.party1, = self.Party.create([{
            'name': 'Test party - 1',
            'addresses': [('create', [{
                'name': 'Test Party %s' % random.randint(1, 999),
                'street': 'Test Street %s' % random.randint(1, 999),
                'city': 'Test City %s' % random.randint(1, 999),
            }])],
            'account_receivable': self._get_account_by_kind(
                'receivable').id,
        }])
        self.party2, = self.Party.create([{
            'name': 'Test party - 2',
            'addresses': [('create', [{
                'name': 'Test Party',
                'street': 'Test Street',
                'city': 'Test City',
            }])],
            'account_receivable': self._get_account_by_kind(
                'receivable').id,
        }])
        self.party3, = self.Party.create([{
            'name': 'Test party - 3',
            'addresses': [('create', [{
                'name': 'Test Party',
                'street': 'Test Street',
                'city': 'Test City',
            }])],
            'account_receivable': self._get_account_by_kind(
                'receivable').id,
        }])

        self.card_data1 = self.UseCardView(
            number='4111111111111111',
            expiry_month='04',
            expiry_year=str(random.randint(2016, 2020)),
            csc=str(random.randint(100, 555)),
            owner='Test User -1',
        )
        self.card_data2 = self.UseCardView(
            number='4111111111111111',
            expiry_month='08',
            expiry_year=str(random.randint(2016, 2020)),
            csc=str(random.randint(556, 999)),
            owner='Test User -2',
        )
        self.invalid_card_data = self.UseCardView(
            number='4111111111111111',
            expiry_month='08',
            expiry_year='2022',
            csc=str(911),
            owner='Test User -2',
        )

        self.payment_profile = self.PaymentProfile(
            party=self.party1,
            address=self.party1.addresses[0].id,
            gateway=self.auth_net_gateway.id,
            last_4_digits='1111',
            expiry_month='01',
            expiry_year='2018',
            provider_reference='27527167',
            authorize_profile_id='28545177',
        )
        self.payment_profile.save()
コード例 #46
0
    def setup_defaults(self):
        """
        Creates default data for testing
        """
        self.country, = self.Country.create([{
            'name': 'United States',
            'code': 'US',
        }])

        self.subdivision, = self.CountrySubdivision.create([{
            'name': 'Florida',
            'code': 'US-FL',
            'country': self.country.id,
            'type': 'state'
        }])
        currency, = self.Currency.create([{
            'name': 'Unites Stated',
            'code': 'USD',
            'symbol': '$',
        }])

        with Transaction().set_context(company=None):
            company_party, = self.Party.create([{
                'name': 'Openlabs'
            }])

        self.company, = self.Company.create([{
            'party': company_party,
            'currency': currency,
        }])

        self.User.write([self.User(USER)], {
            'company': self.company,
            'main_company': self.company,
        })

        CONTEXT.update(self.User.get_preferences(context_only=True))

        # Create Fiscal Year
        self._create_fiscal_year(company=self.company.id)
        # Create Chart of Accounts
        self._create_coa_minimal(company=self.company.id)
        # Create Cash journal
        self.cash_journal, = self.Journal.search(
            [('type', '=', 'cash')], limit=1
        )
        self.Journal.write([self.cash_journal], {
            'debit_account': self._get_account_by_kind('expense').id,
            'credit_account': self._get_account_by_kind('expense').id,
        })

        self.beanstream_passcode_gateway = self.PaymentGateway(
            name='beanstream',
            journal=self.cash_journal,
            provider='beanstream',
            method='credit_card',
            beanstream_auth_mechanism='passcode',
            beanstream_merchant_id='300200425',
            beanstream_pass_code='B042485853bb4ee9b8269ADEAF6A60dd',
            beanstream_currency=currency,
            test=True
        )
        self.beanstream_passcode_gateway.save()

        self.beanstream_hash_gateway = self.PaymentGateway(
            name='beanstream',
            journal=self.cash_journal,
            provider='beanstream',
            method='credit_card',
            beanstream_auth_mechanism='hash',
            beanstream_merchant_id='300200425',
            beanstream_hash_key='de59b16d310ace6983af0b0a791c1d318f79ec9d',
            beanstream_currency=currency,
            test=True,
        )
        self.beanstream_hash_gateway.save()

        # Create parties
        self.party1, = self.Party.create([{
            'name': 'Test party - 1',
            'addresses': [
                ('create', [{
                    'name': 'Amine Khechfe',
                    'street': '247 High Street',
                    'zip': '94301-1041',
                    'city': 'Palo Alto',
                    'country': self.country.id,
                    'subdivision': self.subdivision.id,
                }])
            ],
            'account_receivable': self._get_account_by_kind(
                'receivable'
            ).id,
        }])
        self.party2, = self.Party.create([{
            'name': 'Test party - 2',
            'addresses': [
                ('create', [{
                    'name': 'Amine Khechfe',
                    'street': '247 High Street',
                    'zip': '94301-1041',
                    'city': 'Palo Alto',
                    'country': self.country.id,
                    'subdivision': self.subdivision.id,
                }])
            ],
            'account_receivable': self._get_account_by_kind(
                'receivable'
            ).id,
        }])
        self.party3, = self.Party.create([{
            'name': 'Test party - 3',
            'addresses': [
                ('create', [{
                    'name': 'Amine Khechfe',
                    'street': '247 High Street',
                    'zip': '94301-1041',
                    'city': 'Palo Alto',
                    'country': self.country.id,
                    'subdivision': self.subdivision.id,
                }])
            ],
            'account_receivable': self._get_account_by_kind(
                'receivable'
            ).id,
        }])

        self.card_data1 = self.UseCardView(
            number='4030000010001234',
            expiry_month='04',
            expiry_year=str(random.randint(2016, 2020)),
            csc='123',
            owner='Test User -1',
        )
        self.card_data2 = self.UseCardView(
            number='4111111111111111',
            expiry_month='08',
            expiry_year=str(random.randint(2016, 2020)),
            csc=str(random.randint(556, 999)),
            owner='Test User -2',
        )
        self.invalid_card_data = self.UseCardView(
            number='4111111111111111',
            expiry_month='08',
            expiry_year='2022',
            csc=str(911),
            owner='Test User -2',
        )

        self.payment_profile = self.PaymentProfile(
            party=self.party1,
            address=self.party1.addresses[0].id,
            gateway=self.beanstream_passcode_gateway.id,
            last_4_digits='1111',
            expiry_month='01',
            expiry_year='2018',
            provider_reference='26037832',
        )
        self.payment_profile.save()
コード例 #47
0
    def setup_defaults(self):
        """
        Setup the defaults
        """
        with Transaction().set_context(company=None):
            self.usd, = self.Currency.create([{
                'name': 'US Dollar',
                'code': 'USD',
                'symbol': '$',
            }])
            self.party, = self.Party.create([{
                'name': 'Openlabs',
            }])
            self.company, = self.Company.create([{
                'party': self.party.id,
                'currency': self.usd
            }])
        self.User.write(
            [self.User(USER)], {
                'main_company': self.company.id,
                'company': self.company.id,
            }
        )

        CONTEXT.update(self.User.get_preferences(context_only=True))

        # Create Fiscal Year
        self._create_fiscal_year(company=self.company.id)
        # Create Chart of Accounts
        self._create_coa_minimal(company=self.company.id)
        # Create a payment term
        payment_term, = self._create_payment_term()

        channel_price_list, user_price_list = self._create_pricelists()

        party1, = self.Party.create([{
            'name': 'Guest User',
        }])

        party2, = self.Party.create([{
            'name': 'Registered User',
            'sale_price_list': user_price_list,
            'addresses': [('create', [{
                'name': 'An Address',
            }])],
        }])

        party3, = self.Party.create([{
            'name': 'Registered User 2',
        }])

        # Create users and assign the pricelists to them
        self.guest_user, = self.NereidUser.create([{
            'party': party1.id,
            'display_name': 'Guest User',
            'email': '*****@*****.**',
            'password': '******',
            'company': self.company.id,
        }])
        self.registered_user, = self.NereidUser.create([{
            'party': party2.id,
            'display_name': 'Registered User',
            'email': '*****@*****.**',
            'password': '******',
            'company': self.company.id,
        }])
        self.registered_user2, = self.NereidUser.create([{
            'party': party3.id,
            'display_name': 'Registered User 2',
            'email': '*****@*****.**',
            'password': '******',
            'company': self.company.id,
        }])

        self._create_countries()
        self.available_countries = self.Country.search([], limit=5)

        warehouse, = self.Location.search([
            ('type', '=', 'warehouse')
        ], limit=1)
        location, = self.Location.search([
            ('type', '=', 'storage')
        ], limit=1)
        en_us, = self.Language.search([('code', '=', 'en_US')])

        self.locale_en_us, = self.Locale.create([{
            'code': 'en_US',
            'language': en_us.id,
            'currency': self.usd.id,
        }])

        self.sale_tax, = self.Tax.create([{
            'name': 'Sales Tax',
            'description': 'Sales Tax',
            'type': 'percentage',
            'rate': Decimal('0.05'),  # Rate 5%
            'company': self.company.id,
            'invoice_account': self._get_account_by_kind('other').id,
            'credit_note_account': self._get_account_by_kind('other').id,
        }])

        with Transaction().set_context(company=self.company.id):
            self.channel, = self.SaleChannel.create([{
                'name': 'Default Channel',
                'price_list': channel_price_list,
                'invoice_method': 'order',
                'shipment_method': 'order',
                'source': 'webshop',
                'create_users': [('add', [USER])],
                'warehouse': warehouse,
                'payment_term': payment_term,
                'company': self.company.id,
            }])

        self.User.set_preferences({'current_channel': self.channel})

        self.User.write(
            [self.User(USER)], {
                'main_company': self.company.id,
                'company': self.company.id,
                'current_channel': self.channel,
            }
        )

        self.create_website()

        # Create product templates with products
        self.template1, = self._create_product_template(
            'product-1',
            [{
                'type': 'goods',
                'salable': True,
                'list_price': Decimal('10'),
                'cost_price': Decimal('5'),
                'account_expense': self._get_account_by_kind('expense').id,
                'account_revenue': self._get_account_by_kind('revenue').id,
            }],
            uri='product-1',
        )
        self.template2, = self._create_product_template(
            'product-2',
            [{
                'type': 'goods',
                'salable': True,
                'list_price': Decimal('15'),
                'cost_price': Decimal('5'),
                'account_expense': self._get_account_by_kind('expense').id,
                'account_revenue': self._get_account_by_kind('revenue').id,
            }],
            uri='product-2',
        )
        self.product1 = self.template1.products[0]
        self.product2 = self.template2.products[0]
コード例 #48
0
    def setup_defaults(self):
        """Method to setup defaults
        """
        # Create currency
        self.currency, = self.Currency.create([{"name": "United Stated Dollar", "code": "USD", "symbol": "USD"}])
        self.Currency.create([{"name": "Indian Rupee", "code": "INR", "symbol": "INR"}])

        country_us, = self.Country.create([{"name": "United States", "code": "US"}])

        subdivision_florida, = self.CountrySubdivision.create(
            [{"name": "Florida", "code": "US-FL", "country": country_us.id, "type": "state"}]
        )

        subdivision_california, = self.CountrySubdivision.create(
            [{"name": "California", "code": "US-CA", "country": country_us.id, "type": "state"}]
        )

        with Transaction().set_context(company=None):
            company_party, = self.Party.create(
                [
                    {
                        "name": "Test Party",
                        "vat_number": "123456",
                        "addresses": [
                            (
                                "create",
                                [
                                    {
                                        "name": "Amine Khechfe",
                                        "street": "247 High Street",
                                        "zip": "94301-1041",
                                        "city": "Palo Alto",
                                        "country": country_us.id,
                                        "subdivision": subdivision_california.id,
                                    }
                                ],
                            )
                        ],
                    }
                ]
            )

        self.ups_service, = self.UPSService.create([{"name": "Next Day Air", "code": "01"}])

        self.ups_service2, = self.UPSService.create([{"name": "Second Next Day Air", "code": "02"}])

        self.SaleConfig.create([{"ups_service_type": self.ups_service.id}])
        self.company, = self.Company.create([{"party": company_party.id, "currency": self.currency.id}])
        self.PartyContact.create([{"type": "phone", "value": "8005551212", "party": self.company.party.id}])

        self.User.write([self.User(USER)], {"main_company": self.company.id, "company": self.company.id})

        CONTEXT.update(self.User.get_preferences(context_only=True))

        self._create_fiscal_year(company=self.company)
        self._create_coa_minimal(company=self.company)
        self.payment_term, = self._create_payment_term()

        account_revenue, = self.Account.search([("kind", "=", "revenue")])

        # Create product category
        category, = self.Category.create([{"name": "Test Category"}])

        uom_kg, = self.Uom.search([("symbol", "=", "kg")])
        uom_cm, = self.Uom.search([("symbol", "=", "cm")])
        uom_pound, = self.Uom.search([("symbol", "=", "lb")])

        # Carrier Carrier Product
        carrier_product_template, = self.Template.create(
            [
                {
                    "name": "Test Carrier Product",
                    "category": category.id,
                    "type": "service",
                    "salable": True,
                    "sale_uom": uom_kg,
                    "list_price": Decimal("10"),
                    "cost_price": Decimal("5"),
                    "default_uom": uom_kg,
                    "cost_price_method": "fixed",
                    "account_revenue": account_revenue.id,
                    "products": [("create", self.Template.default_products())],
                }
            ]
        )

        carrier_product = carrier_product_template.products[0]

        # Create product
        template, = self.Template.create(
            [
                {
                    "name": "Test Product",
                    "category": category.id,
                    "type": "goods",
                    "salable": True,
                    "sale_uom": uom_kg,
                    "list_price": Decimal("10"),
                    "cost_price": Decimal("5"),
                    "default_uom": uom_kg,
                    "account_revenue": account_revenue.id,
                    "weight": 0.5,
                    "weight_uom": uom_pound.id,
                    "products": [("create", self.Template.default_products())],
                }
            ]
        )

        self.product = template.products[0]
        self.product.code = "TEST_PRODUCT"
        self.product.save()

        # Create party
        carrier_party, = self.Party.create([{"name": "Test Party"}])

        self.carrier, = self.Carrier.create(
            [
                {
                    "party": carrier_party.id,
                    "carrier_product": carrier_product.id,
                    "carrier_cost_method": "ups",
                    "ups_license_key": os.environ["UPS_LICENSE_NO"],
                    "ups_user_id": os.environ["UPS_USER_ID"],
                    "ups_password": os.environ["UPS_PASSWORD"],
                    "ups_shipper_no": os.environ["UPS_SHIPPER_NO"],
                    "ups_is_test": True,
                    "ups_uom_system": "01",
                    "currency": self.currency.id,
                }
            ]
        )
        self.ups_worldship_carrier, = self.Carrier.create(
            [
                {
                    "party": carrier_party.id,
                    "carrier_product": carrier_product.id,
                    "carrier_cost_method": "ups_worldship",
                    "currency": self.currency.id,
                }
            ]
        )

        self.PartyConfig.create([{"default_validation_carrier": self.carrier.id}])

        self.sale_party, = self.Party.create(
            [
                {
                    "name": "Test Sale Party",
                    "vat_number": "123456",
                    "addresses": [
                        (
                            "create",
                            [
                                {
                                    "name": "John Doe",
                                    "street": "250 NE 25th St",
                                    "zip": "33137",
                                    "city": "Miami, Miami-Dade",
                                    "country": country_us.id,
                                    "subdivision": subdivision_florida.id,
                                }
                            ],
                        )
                    ],
                }
            ]
        )
        self.PartyContact.create([{"type": "phone", "value": "8005763279", "party": self.sale_party.id}])

        self.warehouse = self.StockLocation.search([("type", "=", "warehouse")])[0]
        self.StockLocation.write([self.warehouse], {"address": self.company.party.addresses[0].id})
コード例 #49
0
    def setup_defaults(self):
        """Creates default data for testing
        """
        currency, = self.Currency.create([{
            'name': 'US Dollar',
            'code': 'USD',
            'symbol': '$',
        }])

        with Transaction().set_context(company=None):
            company_party, = self.Party.create([{
                'name': 'Openlabs'
            }])
            employee_party, = self.Party.create([{
                'name': 'Jim'
            }])

        self.company, = self.Company.create([{
            'party': company_party,
            'currency': currency,
        }])

        self.employee, = self.Employee.create([{
            'party': employee_party.id,
            'company': self.company.id,
        }])

        self.User.write([self.User(USER)], {
            'company': self.company,
            'main_company': self.company,
        })

        CONTEXT.update(self.User.get_preferences(context_only=True))

        # Create Fiscal Year
        self.fiscal_year = self._create_fiscal_year(company=self.company.id)
        # Create Chart of Accounts
        self._create_coa_minimal(company=self.company.id)

        self.cash_journal, = self.Journal.search(
            [('type', '=', 'cash')], limit=1
        )
        self.Journal.write([self.cash_journal], {
            'debit_account': self._get_account_by_kind('other').id
        })

        self.country, = self.Country.create([{
            'name': 'United States of America',
            'code': 'US',
        }])

        self.subdivision, = self.Subdivision.create([{
            'country': self.country.id,
            'name': 'California',
            'code': 'CA',
            'type': 'state',
        }])

        # Add address to company's party record
        self.Party.write([self.company.party], {
            'addresses': [('create', [{
                'name': 'Openlabs',
                'party': Eval('id'),
                'city': 'Los Angeles',
                'country': self.country.id,
                'subdivision': self.subdivision.id,
            }])],
        })

        # Create party
        self.party, = self.Party.create([{
            'name': 'Bruce Wayne',
            'addresses': [('create', [{
                'name': 'Bruce Wayne',
                'party': Eval('id'),
                'city': 'Gotham',
                'country': self.country.id,
                'subdivision': self.subdivision.id,
            }])],
            'account_receivable': self._get_account_by_kind(
                'receivable').id,
            'contact_mechanisms': [('create', [
                {'type': 'mobile', 'value': '8888888888'},
            ])],
        }])

        self.payment_term, = self._create_payment_term()
コード例 #50
0
    def setup_defaults(self):
        """Method to setup defaults
        """
        # Create currency
        self.currency, = self.Currency.create([{
            'name': 'United Stated Dollar',
            'code': 'USD',
            'symbol': 'USD',
        }])
        self.Currency.create([{
            'name': 'Indian Rupee',
            'code': 'INR',
            'symbol': 'INR',
        }])

        country_us, = self.Country.create([{
            'name': 'United States',
            'code': 'US',
        }])

        subdivision_florida, = self.CountrySubdivision.create([{
            'name': 'Florida',
            'code': 'US-FL',
            'country': country_us.id,
            'type': 'state'
        }])

        subdivision_california, = self.CountrySubdivision.create([{
            'name': 'California',
            'code': 'US-CA',
            'country': country_us.id,
            'type': 'state'
        }])

        with Transaction().set_context(company=None):
            company_party, = self.Party.create([{
                'name': 'Test Party',
                'vat_number': '123456',
                'addresses': [('create', [{
                    'name': 'Amine Khechfe',
                    'street': '247 High Street',
                    'zip': '94301-1041',
                    'city': 'Palo Alto',
                    'country': country_us.id,
                    'subdivision': subdivision_california.id,
                }])]
            }])

        self.ups_service, = self.UPSService.create([{
            'name': 'Next Day Air',
            'code': '01',
        }])

        self.ups_service2, = self.UPSService.create([{
            'name': 'Second Next Day Air',
            'code': '02',
        }])

        # UPS Configuration
        self.UPSConfiguration.create([{
            'license_key': os.environ['UPS_LICENSE_NO'],
            'user_id': os.environ['UPS_USER_ID'],
            'password': os.environ['UPS_PASSWORD'],
            'shipper_no': os.environ['UPS_SHIPPER_NO'],
            'is_test': True,
            'uom_system': '01',
        }])
        self.CarrierConfig.create([{
            'default_validation_provider': 'ups',
        }])
        self.SaleConfig.create([{
            'ups_service_type': self.ups_service.id,
        }])
        self.company, = self.Company.create([{
            'party': company_party.id,
            'currency': self.currency.id,
        }])
        self.PartyContact.create([{
            'type': 'phone',
            'value': '8005551212',
            'party': self.company.party.id
        }])

        self.User.write(
            [self.User(USER)], {
                'main_company': self.company.id,
                'company': self.company.id,
            }
        )

        CONTEXT.update(self.User.get_preferences(context_only=True))

        self._create_fiscal_year(company=self.company)
        self._create_coa_minimal(company=self.company)
        self.payment_term, = self._create_payment_term()

        account_revenue, = self.Account.search([
            ('kind', '=', 'revenue')
        ])

        # Create product category
        category, = self.Category.create([{
            'name': 'Test Category',
        }])

        uom_kg, = self.Uom.search([('symbol', '=', 'kg')])
        uom_cm, = self.Uom.search([('symbol', '=', 'cm')])
        uom_pound, = self.Uom.search([('symbol', '=', 'lb')])

        # Carrier Carrier Product
        carrier_product_template, = self.Template.create([{
            'name': 'Test Carrier Product',
            'category': category.id,
            'type': 'service',
            'salable': True,
            'sale_uom': uom_kg,
            'list_price': Decimal('10'),
            'cost_price': Decimal('5'),
            'default_uom': uom_kg,
            'cost_price_method': 'fixed',
            'account_revenue': account_revenue.id,
            'products': [('create', self.Template.default_products())]
        }])

        carrier_product = carrier_product_template.products[0]

        # Create product
        template, = self.Template.create([{
            'name': 'Test Product',
            'category': category.id,
            'type': 'goods',
            'salable': True,
            'sale_uom': uom_kg,
            'list_price': Decimal('10'),
            'cost_price': Decimal('5'),
            'default_uom': uom_kg,
            'account_revenue': account_revenue.id,
            'weight': .5,
            'weight_uom': uom_pound.id,
            'products': [('create', self.Template.default_products())]
        }])

        self.product = template.products[0]

        # Create party
        carrier_party, = self.Party.create([{
            'name': 'Test Party',
        }])

        # Create party
        carrier_party, = self.Party.create([{
            'name': 'Test Party',
        }])

        self.carrier, = self.Carrier.create([{
            'party': carrier_party.id,
            'carrier_product': carrier_product.id,
            'carrier_cost_method': 'ups',
        }])

        self.sale_party, = self.Party.create([{
            'name': 'Test Sale Party',
            'vat_number': '123456',
            'addresses': [('create', [{
                'name': 'John Doe',
                'street': '250 NE 25th St',
                'zip': '33137',
                'city': 'Miami, Miami-Dade',
                'country': country_us.id,
                'subdivision': subdivision_florida.id,
            }])]
        }])
        self.PartyContact.create([{
            'type': 'phone',
            'value': '8005763279',
            'party': self.sale_party.id
        }])
コード例 #51
0
    def setup_defaults(self):
        """Creates default data for testing
        """
        self.country, = self.Country.create([{
            'name': 'United States of America',
            'code': 'US',
        }])
        self.subdivision, = self.Subdivision.create([{
            'country': self.country.id,
            'name': 'California',
            'code': 'CA',
            'type': 'state',
        }])

        self.currency, = self.Currency.create([{
            'name': 'US Dollar',
            'code': 'USD',
            'symbol': '$',
        }])

        with Transaction().set_context(company=None):
            company_party, = self.Party.create([{'name': 'openlabs'}])

        self.company, = self.Company.create([{
            'party': company_party,
            'currency': self.currency,
        }])

        self.User.write([self.User(USER)], {
            'company': self.company,
            'main_company': self.company,
        })
        CONTEXT.update(self.User.get_preferences(context_only=True))

        # Create Fiscal Year
        self._create_fiscal_year(company=self.company.id)
        # Create Chart of Accounts
        self._create_coa_minimal(company=self.company.id)
        # Create a payment term
        self.payment_term, = self._create_payment_term()

        self.cash_journal, = self.Journal.search([('type', '=', 'cash')],
                                                 limit=1)
        self.Journal.write(
            [self.cash_journal],
            {'debit_account': self._get_account_by_kind('other').id})

        # Create party
        self.party, = self.Party.create([{
            'name':
            'Bruce Wayne',
            'addresses': [('create', [{
                'name': 'Bruce Wayne',
                'party': Eval('id'),
                'city': 'Gotham',
                'invoice': True,
                'country': self.country.id,
                'subdivision': self.subdivision.id,
            }])],
            'customer_payment_term':
            self.payment_term.id,
            'account_receivable':
            self._get_account_by_kind('receivable').id,
            'contact_mechanisms': [('create', [
                {
                    'type': 'email',
                    'value': '*****@*****.**'
                },
            ])],
        }])

        self.uom, = self.Uom.search([('name', '=', 'Unit')])
        self.product_category, = self.ProductCategory.create([{
            'name':
            'Automobile',
            'account_revenue':
            self._get_account_by_kind('revenue', company=self.company.id).id,
            'account_expense':
            self._get_account_by_kind('expense', company=self.company.id).id,
        }])

        self.product_template, = self.ProductTemplate.create([{
            'name':
            'Bat Mobile',
            'type':
            'goods',
            'salable':
            True,
            'category':
            self.product_category.id,
            'default_uom':
            self.uom.id,
            'sale_uom':
            self.uom.id,
            'list_price':
            Decimal('20000'),
            'cost_price':
            Decimal('15000'),
            'account_category':
            True,
        }])

        self.product, = self.Product.create([{
            'template':
            self.product_template.id,
            'code':
            '123',
        }])

        # Create return policies
        self.reason_1, self.reason_2, self.reason_3, self.reason_4 = \
            self.ReturnReason.create([{
                'name': 'Reason 1',
                'description': 'Reason 1 description',
            }, {
                'name': 'Reason 2',
                'description': 'Reason 2 description',
            }, {
                'name': 'Reason 3',
                'description': 'Reason 3 description',
            }, {
                'name': 'Reason 4',
                'description': 'Reason 4 description',
            }])

        self.policy_1, self.policy_2 = self.ReturnPolicy.create([{
            'name':
            'Some Policy',
            'description':
            'Some Policy description',
            'terms': [('create', [{
                'reason': self.reason_1,
                'days': 7,
                'since': 'sale',
            }, {
                'reason': self.reason_2,
                'days': 30,
                'since': 'shipping',
            }])]
        }, {
            'name':
            'Some other Policy',
            'description':
            'Some other Policy description',
            'terms': [('create', [{
                'reason': self.reason_3,
                'days': 7,
                'since': 'sale',
            }, {
                'reason': self.reason_4,
                'days': 30,
                'since': 'sale',
            }])]
        }])

        # Fill inventory with our product
        Inventory = POOL.get('stock.inventory')
        StockLocation = POOL.get('stock.location')

        warehouse, = StockLocation.search([
            ('type', '=', 'warehouse'),
        ])
        inventory, = Inventory.create([{
            'location':
            warehouse.storage_location,
            'company':
            self.company.id,
            'lines': [('create', [{
                'product': self.product.id,
                'quantity': 100,
            }])]
        }])
        Inventory.confirm([inventory])

        # Update Sale Configuration
        self.sale_configuration = self.SaleConfiguration(1)
        self.sale_configuration.default_return_policy = self.policy_1.id
        self.sale_configuration.save()