def test_incoterm(self): 'Incoterm' pool = Pool() Party = pool.get('party.party') Incoterm = pool.get('incoterm') company = create_company(name='Company 1') with set_company(company): incoterm, = Incoterm.search([('code', '=', 'EXW')], limit=1) party1, = Party.create([{ 'name': 'Party 1', 'incoterm': incoterm, 'incoterm_place': 'Test1', }]) self.assertEqual(party1.incoterm, incoterm) party1_id = party1.id company = create_company(name='Company 2') with set_company(company): incoterm2, = Incoterm.search([('code', '=', 'FCA')], limit=1) party1 = Party(party1_id) party1.incoterm = incoterm2 party1.save() self.assertEqual(party1.incoterm, incoterm2) self.assertEqual(party1.incoterm_place, None)
def test_account_chart_many_companies(self): "Test creation of chart of accounts for many companies" company1 = create_company() with set_company(company1): create_chart(company1, tax=True) company2 = create_company() with set_company(company2): create_chart(company2, tax=True)
def test_payment_sepa_bank_account_number(self): 'Test Payment.sepa_bank_account_number' pool = Pool() Payment = pool.get('account.payment') Mandate = pool.get('account.payment.sepa.mandate') AccountNumber = pool.get('bank.account.number') Party = pool.get('party.party') BankAccount = pool.get('bank.account') company = create_company() with set_company(company): create_chart(company) account_number = AccountNumber() mandate = Mandate(account_number=account_number) payment = Payment(kind='receivable', sepa_mandate=mandate) self.assertEqual(id(payment.sepa_bank_account_number), id(account_number)) other_account_number = AccountNumber(type='other') iban_account_number = AccountNumber(type='iban') bank_account = BankAccount( numbers=[other_account_number, iban_account_number]) party = Party( bank_accounts=[bank_account]) payment = Payment(kind='payable', party=party) self.assertEqual(id(payment.sepa_bank_account_number), id(iban_account_number))
def test_identification_unique(self): 'Test unique identification constraint' pool = Pool() Party = pool.get('party.party') Mandate = pool.get('account.payment.sepa.mandate') same_id = '1' party = Party(name='Test') party.save() company = create_company() with set_company(company): mandate = Mandate(party=party, identification=same_id) mandate.save() for i in range(2): mandate = Mandate(party=party) mandate.save() mandate = Mandate(party=party, identification='') mandate.save() self.assertEqual(mandate.identification, None) Mandate.write([mandate], { 'identification': '', }) self.assertEqual(mandate.identification, None) self.assertRaises(UserError, Mandate.create, [{ 'party': party.id, 'identification': same_id, }])
def test_sepa_mandate_sequence(self): 'Test SEPA mandate sequence' pool = Pool() Configuration = pool.get('account.configuration') Sequence = pool.get('ir.sequence') Party = pool.get('party.party') Mandate = pool.get('account.payment.sepa.mandate') party = Party(name='Test') party.save() company = create_company() with set_company(company): mandate = Mandate(party=party) mandate.save() self.assertFalse(mandate.identification) sequence = Sequence(name='Test', code='account.payment.sepa.mandate') sequence.save() config = Configuration(1) config.sepa_mandate_sequence = sequence config.save() mandate = Mandate(party=party) mandate.save() self.assertTrue(mandate.identification)
def test_configuration_accounts_on_party(self): 'Test configuration accounts are used as fallback on party' pool = Pool() Party = pool.get('party.party') Account = pool.get('account.account') party = Party(name='Party') party.save() self.assertIsNone(party.account_payable) self.assertIsNone(party.account_receivable) company = create_company() with set_company(company): create_chart(company) receivable, = Account.search([ ('kind', '=', 'receivable'), ]) payable, = Account.search([ ('kind', '=', 'payable'), ]) party = Party(party.id) self.assertEqual(party.account_payable_used, payable) self.assertEqual(party.account_receivable_used, receivable)
def test_plan_no_product(self): "Test plan with no product" pool = Pool() Category = pool.get('product.category') PlanLine = pool.get('commission.plan.line') category = Category(name="Category") category.save() company = create_company() with set_company(company): product = create_product("Other", Decimal(10)) plan = create_plan([{ 'category': category.id, 'formula': 'amount * 0.8', }, { 'product': product.id, 'formula': 'amount * 0.7', }, { 'formula': 'amount', }]) self.assertEqual(plan.compute(Decimal(1), None), Decimal(1)) PlanLine.delete(plan.lines[1:]) self.assertEqual(plan.compute(Decimal(1), None), None)
def create_product(self, web_shop, quantity=0, code="CODE"): pool = Pool() Template = pool.get('product.template') Product = pool.get('product.product') Category = pool.get('product.category') Uom = pool.get('product.uom') Location = pool.get('stock.location') Move = pool.get('stock.move') unit, = Uom.search([('name', '=', "Unit")], limit=1) template = Template(name="Product") template.type = 'goods' template.list_price = Decimal(100) template.default_uom = unit template.salable = True template.sale_uom = unit template.products = [Product(suffix_code=code, web_shops=[web_shop])] template.account_category = Category(name="Category", accounting=True) template.save() product, = template.products if quantity: supplier, = Location.search([('code', '=', 'SUP')]) storage, = Location.search([('code', '=', 'STO')]) with set_company(web_shop.company): move = Move(product=product) move.uom = unit move.quantity = quantity move.from_location = supplier move.to_location = storage move.unit_price = Decimal(50) move.save() Move.do([move]) Product.set_vsf_identifier([product]) return product
def test_delete_access(self): 'Test delete_access' pool = Pool() User = pool.get('res.user') Group = pool.get('res.group') ModelData = pool.get('ir.model.data') ProjectWork = pool.get('project.work') TimesheetWork = pool.get('timesheet.work') company = create_company() with set_company(company): project_user = User() project_user.login = '******' project_user.companies = [company] project_user.company = company project_group = Group(ModelData.get_id( 'project', 'group_project_admin')) project_user.groups = [project_group] project_user.save() with Transaction().set_user(project_user.id): p_work = ProjectWork() p_work.name = 'Project Work' p_work.timesheet_available = True p_work.save() self.assertEqual(len(p_work.timesheet_works), 1) ProjectWork.delete([p_work]) self.assertEqual(TimesheetWork.search([]), [])
def test_tax_rule(self): "Test tax rule" country1, country2 = self._create_countries()[:2] subdivision1 = country1.subdivisions[0] subdivision2 = country2.subdivisions[0] company = create_company() with set_company(company): create_chart(company, tax=True) tax, target_tax = self._get_taxes()[:2] tax_rule = self._create_rule([{ 'from_country': country1.id, 'from_subdivision': subdivision1.id, 'to_country': country2.id, 'to_subdivision': subdivision2.id, 'origin_tax': tax.id, 'tax': target_tax.id, }]) pattern = { 'from_country': country1.id, 'from_subdivision': subdivision1.id, 'to_country': country2.id, 'to_subdivision': subdivision2.id, } self.assertListEqual(tax_rule.apply(tax, pattern), [target_tax.id])
def test_compute_cost_price(self): 'Test compute_cost_price' pool = Pool() Party = pool.get('party.party') EmployeeCostPrice = pool.get('company.employee_cost_price') cost_prices = [ (datetime.date(2011, 1, 1), Decimal(10)), (datetime.date(2012, 1, 1), Decimal(15)), (datetime.date(2013, 1, 1), Decimal(20)), ] test_prices = [ (datetime.date(2010, 1, 1), 0), (datetime.date(2011, 1, 1), Decimal(10)), (datetime.date(2011, 6, 1), Decimal(10)), (datetime.date(2012, 1, 1), Decimal(15)), (datetime.date(2012, 6, 1), Decimal(15)), (datetime.date(2013, 1, 1), Decimal(20)), (datetime.date(2013, 6, 1), Decimal(20)), ] party = Party(name='Pam Beesly') party.save() company = create_company() with set_company(company): employee = create_employee(company) for date, cost_price in cost_prices: EmployeeCostPrice(employee=employee, date=date, cost_price=cost_price).save() for date, cost_price in test_prices: self.assertEqual(employee.compute_cost_price(date), cost_price)
def test_payment_sepa_bank_account_number(self): 'Test Payment.sepa_bank_account_number' pool = Pool() Payment = pool.get('account.payment') Mandate = pool.get('account.payment.sepa.mandate') AccountNumber = pool.get('bank.account.number') Party = pool.get('party.party') BankAccount = pool.get('bank.account') company = create_company() with set_company(company): create_chart(company) account_number = AccountNumber() mandate = Mandate(account_number=account_number) payment = Payment(kind='receivable', sepa_mandate=mandate) self.assertEqual(id(payment.sepa_bank_account_number), id(account_number)) other_account_number = AccountNumber(type='other') iban_account_number = AccountNumber(type='iban') bank_account = BankAccount( numbers=[other_account_number, iban_account_number]) party = Party(bank_accounts=[bank_account]) payment = Payment(kind='payable', party=party) self.assertEqual(id(payment.sepa_bank_account_number), id(iban_account_number))
def test_plan_category(self): "Test plan with category" pool = Pool() Category = pool.get('product.category') category = Category(name="Category") category.save() child_category = Category(name="Child Category", parent=category) child_category.save() company = create_company() with set_company(company): product = create_product("Other", Decimal(10), [category]) plan = create_plan([{ 'category': category.id, 'formula': 'amount * 0.8', }, { 'formula': 'amount', }]) self.assertEqual(plan.compute(Decimal(1), product), Decimal('0.8')) template = product.template template.categories = [] template.save() self.assertEqual(plan.compute(Decimal(1), product), Decimal(1)) template.categories = [child_category] template.save() self.assertEqual(plan.compute(Decimal(1), product), Decimal('0.8'))
def test_price_list_list_price(self): "Test price list with list_price formula" pool = Pool() Template = pool.get('product.template') Product = pool.get('product.product') Uom = pool.get('product.uom') PriceList = pool.get('product.price_list') unit, = Uom.search([('name', '=', 'Unit')]) company = create_company() with set_company(company): template = Template( name="Template", list_price=Decimal(10), default_uom=unit, products=None, ) template.save() product = Product(template=template) product.save() price_list, = PriceList.create([{ 'name': "Price List", 'lines': [('create', [{ 'formula': 'list_price * 0.8', }])], }]) self.assertEqual( price_list.compute(None, product, Decimal(0), 1, unit), Decimal(8))
def test_tax_rule_children(self): "Test tax rule with children subdivision" country = self._create_countries()[0] parent_subdivision = [s for s in country.subdivisions if not s.parent][0] subdivision = [ s for s in country.subdivisions if s.parent == parent_subdivision ][0] company = create_company() with set_company(company): create_chart(company, tax=True) tax, target_tax = self._get_taxes()[:2] tax_rule = self._create_rule([{ 'to_country': country.id, 'to_subdivision': parent_subdivision.id, 'origin_tax': tax.id, 'tax': target_tax.id, }]) pattern = { 'to_country': country.id, 'to_subdivision': subdivision.id, } self.assertListEqual(tax_rule.apply(tax, pattern), [target_tax.id])
def test_tax_rule_keep_origin(self): "Test tax rule keeps origin" pool = Pool() TaxRule = pool.get('account.tax.rule') Tax = pool.get('account.tax') company = create_company() with set_company(company): create_chart(company, tax=True) tax, = Tax.search([]) target_tax, = Tax.copy([tax]) tax_rule, = TaxRule.create([{ 'name': 'Test', 'kind': 'both', 'lines': [('create', [{ 'origin_tax': tax.id, 'tax': target_tax.id, 'keep_origin': True, }])], }]) self.assertListEqual(tax_rule.apply(tax, {}), [target_tax.id, tax.id])
def test_compute_cost_price(self): 'Test compute_cost_price' pool = Pool() Party = pool.get('party.party') Employee = pool.get('company.employee') EmployeeCostPrice = pool.get('company.employee_cost_price') cost_prices = [ (datetime.date(2011, 1, 1), Decimal(10)), (datetime.date(2012, 1, 1), Decimal(15)), (datetime.date(2013, 1, 1), Decimal(20)), ] test_prices = [ (datetime.date(2010, 1, 1), 0), (datetime.date(2011, 1, 1), Decimal(10)), (datetime.date(2011, 6, 1), Decimal(10)), (datetime.date(2012, 1, 1), Decimal(15)), (datetime.date(2012, 6, 1), Decimal(15)), (datetime.date(2013, 1, 1), Decimal(20)), (datetime.date(2013, 6, 1), Decimal(20)), ] party = Party(name='Pam Beesly') party.save() company = create_company() with set_company(company): employee = Employee(party=party.id, company=company) employee.save() for date, cost_price in cost_prices: EmployeeCostPrice( employee=employee, date=date, cost_price=cost_price).save() for date, cost_price in test_prices: self.assertEqual(employee.compute_cost_price(date), cost_price)
def create_product_supplier(self, lead_time): ''' Create a Product with a Product Supplier :param lead_time: timedelta needed to supply :return: the id of the Product Supplier ''' pool = Pool() Uom = pool.get('product.uom') UomCategory = pool.get('product.uom.category') Category = pool.get('product.category') Template = pool.get('product.template') Product = pool.get('product.product') Party = pool.get('party.party') Account = pool.get('account.account') ProductSupplier = pool.get('purchase.product_supplier') uom_category, = UomCategory.create([{'name': 'Test'}]) uom, = Uom.create([{ 'name': 'Test', 'symbol': 'T', 'category': uom_category.id, 'rate': 1.0, 'factor': 1.0, }]) category, = Category.create([{'name': 'ProdCategoryTest'}]) template, = Template.create([{ 'name': 'ProductTest', 'default_uom': uom.id, 'category': category.id, 'account_category': True, 'list_price': Decimal(0), 'cost_price': Decimal(0), }]) product, = Product.create([{ 'template': template.id, }]) company = create_company() with set_company(company): create_chart(company) receivable, = Account.search([ ('kind', '=', 'receivable'), ('company', '=', company.id), ]) payable, = Account.search([ ('kind', '=', 'payable'), ('company', '=', company.id), ]) supplier, = Party.create([{ 'name': 'supplier', 'account_receivable': receivable.id, 'account_payable': payable.id, }]) product_supplier, = ProductSupplier.create([{ 'product': template.id, 'company': company.id, 'party': supplier.id, 'lead_time': lead_time, }]) return product_supplier
def test_move_internal_quantity(self): 'Test Move.internal_quantity' pool = Pool() Category = pool.get('product.category') Uom = pool.get('product.uom') Template = pool.get('product.template') Product = pool.get('product.product') Location = pool.get('stock.location') Move = pool.get('stock.move') category, = Category.create([{ 'name': 'Test Move.internal_quantity', }]) kg, = Uom.search([('name', '=', 'Kilogram')]) g, = Uom.search([('name', '=', 'Gram')]) template, = Template.create([{ 'name': 'Test Move.internal_quantity', 'type': 'goods', 'list_price': Decimal(1), 'cost_price': Decimal(0), 'category': category.id, 'cost_price_method': 'fixed', 'default_uom': kg.id, }]) product, = Product.create([{ 'template': template.id, }]) supplier, = Location.search([('code', '=', 'SUP')]) storage, = Location.search([('code', '=', 'STO')]) company = create_company() currency = company.currency with set_company(company): tests = [ (kg, 10, 10, 0), (g, 100, 0.1, 1), (g, 1, 0, 0), # rounded (kg, 35.23, 35.23, 2), # check infinite loop ] for uom, quantity, internal_quantity, ndigits in tests: move, = Move.create([{ 'product': product.id, 'uom': uom.id, 'quantity': quantity, 'from_location': supplier.id, 'to_location': storage.id, 'company': company.id, 'unit_price': Decimal('1'), 'currency': currency.id, }]) self.assertEqual(round(move.internal_quantity, ndigits), internal_quantity) for uom, quantity, internal_quantity, ndigits in tests: Move.write([move], { 'uom': uom.id, 'quantity': quantity, }) self.assertEqual(round(move.internal_quantity, ndigits), internal_quantity)
def test_sum_tree(self): 'Test sum_tree' pool = Pool() ProjectWork = pool.get('project.work') company = create_company() with set_company(company): p_work_1, = ProjectWork.create([{ 'name': 'Work 1', 'company': company.id, 'effort_duration': datetime.timedelta(hours=1), }]) p_work_1_1, = ProjectWork.create([{ 'name': 'Work 1 1', 'company': company.id, 'parent': p_work_1.id, 'effort_duration': datetime.timedelta(hours=1), }]) p_work_1_2, = ProjectWork.create([{ 'name': 'Work 1 2', 'company': company.id, 'parent': p_work_1.id, 'effort_duration': datetime.timedelta(hours=1), }]) p_work_1_1_1, = ProjectWork.create([{ 'name': 'Work 1 1 1', 'company': company.id, 'parent': p_work_1_1.id, 'effort_duration': datetime.timedelta(hours=1), }]) p_work_1_1_2, = ProjectWork.create([{ 'name': 'Work 1 1 2', 'company': company.id, 'parent': p_work_1_1.id, 'effort_duration': datetime.timedelta(hours=1), }]) p_work_1_1_3, = ProjectWork.create([{ 'name': 'Work 1 1 3', 'company': company.id, 'parent': p_work_1_1.id, 'effort_duration': datetime.timedelta(hours=1), }]) for work, total_effort in ( (p_work_1, 6), (p_work_1_1, 4), (p_work_1_2, 1), (p_work_1_1_1, 1), (p_work_1_1_2, 1), (p_work_1_1_3, 1), ): self.assertEqual(work.total_effort, datetime.timedelta(hours=total_effort))
def test_move_lines(self): 'Test move lines' pool = Pool() Account = pool.get('account.account') FiscalYear = pool.get('account.fiscalyear') Journal = pool.get('account.journal') Move = pool.get('account.move') MoveLine = pool.get('account.move.line') PaymentType = pool.get('account.payment.type') company = create_company() with set_company(company): create_chart(company) fiscalyear = get_fiscalyear(company) set_invoice_sequences(fiscalyear) fiscalyear.save() FiscalYear.create_period([fiscalyear]) period = fiscalyear.periods[0] journal_revenue, = Journal.search([ ('code', '=', 'REV'), ]) revenue, = Account.search([ ('type.revenue', '=', True), ]) receivable, = Account.search([ ('type.receivable', '=', True), ]) payable, = Account.search([ ('type.payable', '=', True), ]) payment_payable, = PaymentType.create([{ 'name': 'Payment Payable', 'kind': 'payable', 'company': company.id, }]) payment_receivable, = PaymentType.create([{ 'name': 'Payment Receivable', 'kind': 'receivable', 'company': company.id, }]) move, = Move.create([{ 'period': period.id, 'journal': journal_revenue.id, 'date': period.start_date, }]) MoveLine.create([{ 'move': move.id, 'account': revenue.id, 'debit': Decimal(30), }]) self.assertRaises(Exception, MoveLine.create, [{ 'move': move.id, 'account': revenue.id, 'debit': Decimal(30), 'payment_type': payment_receivable, }])
def test_price_list_category(self): "Test price list with category" pool = Pool() Category = pool.get('product.category') Template = pool.get('product.template') Product = pool.get('product.product') Uom = pool.get('product.uom') PriceList = pool.get('product.price_list') category = Category(name="Category") category.save() child_category = Category(name="Child Category", parent=category) child_category.save() unit, = Uom.search([('name', '=', 'Unit')]) company = create_company() with set_company(company): template = Template( name="Template", list_price=Decimal(10), default_uom=unit, products=None, categories=[category], ) template.save() product = Product(template=template) product.save() price_list, = PriceList.create([{ 'name': "Price List", 'lines': [('create', [{ 'category': category.id, 'formula': 'unit_price * 0.8', }, { 'formula': 'unit_price', }])], }]) self.assertEqual( price_list.compute(None, product, product.list_price, 1, unit), Decimal(8)) template.categories = [] template.save() self.assertEqual( price_list.compute(None, product, product.list_price, 1, unit), Decimal(10)) template.categories = [child_category] template.save() self.assertEqual( price_list.compute(None, product, product.list_price, 1, unit), Decimal(8))
def create_product_supplier(self, lead_time): ''' Create a Product with a Product Supplier :param lead_time: timedelta needed to supply :return: the id of the Product Supplier ''' pool = Pool() Uom = pool.get('product.uom') UomCategory = pool.get('product.uom.category') Template = pool.get('product.template') Product = pool.get('product.product') Party = pool.get('party.party') Account = pool.get('account.account') ProductSupplier = pool.get('purchase.product_supplier') uom_category, = UomCategory.create([{'name': 'Test'}]) uom, = Uom.create([{ 'name': 'Test', 'symbol': 'T', 'category': uom_category.id, 'rate': 1.0, 'factor': 1.0, }]) template, = Template.create([{ 'name': 'ProductTest', 'default_uom': uom.id, 'list_price': Decimal(0), 'cost_price': Decimal(0), }]) product, = Product.create([{ 'template': template.id, }]) company = create_company() with set_company(company): create_chart(company) receivable, = Account.search([ ('kind', '=', 'receivable'), ('company', '=', company.id), ]) payable, = Account.search([ ('kind', '=', 'payable'), ('company', '=', company.id), ]) supplier, = Party.create([{ 'name': 'supplier', 'account_receivable': receivable.id, 'account_payable': payable.id, }]) product_supplier, = ProductSupplier.create([{ 'product': template.id, 'company': company.id, 'party': supplier.id, 'lead_time': lead_time, }]) return product_supplier
def test_assign_try_chained(self): "Test Move assign_try chained" pool = Pool() Template = pool.get('product.template') Product = pool.get('product.product') Uom = pool.get('product.uom') Location = pool.get('stock.location') Move = pool.get('stock.move') uom, = Uom.search([('name', '=', 'Meter')]) template = Template( name='Test Move.assign_try', type='goods', list_price=Decimal(1), cost_price=Decimal(0), cost_price_method='fixed', default_uom=uom, ) template.save() product = Product(template=template.id) product.save() supplier, = Location.search([('code', '=', 'SUP')]) storage, = Location.search([('code', '=', 'STO')]) storage2, = Location.copy([storage]) storage3, = Location.copy([storage]) company = create_company() with set_company(company): move, = Move.create([{ 'product': product.id, 'uom': uom.id, 'quantity': 1, 'from_location': supplier.id, 'to_location': storage.id, 'company': company.id, 'unit_price': Decimal(1), 'currency': company.currency.id, }]) Move.do([move]) moves = Move.create([{ 'product': product.id, 'uom': uom.id, 'quantity': 1, 'from_location': from_.id, 'to_location': to.id, 'company': company.id, 'unit_price': Decimal(1), 'currency': company.currency.id, } for from_, to in [ (storage, storage2), (storage2, storage3)]]) self.assertFalse(Move.assign_try(moves)) self.assertEqual([m.state for m in moves], ['assigned', 'draft'])
def test_fiscalyear(self): 'Test fiscalyear' pool = Pool() FiscalYear = pool.get('account.fiscalyear') company = create_company() with set_company(company): fiscalyear = get_fiscalyear(company) fiscalyear.save() FiscalYear.create_period([fiscalyear]) self.assertEqual(len(fiscalyear.periods), 12)
def test_move_internal_quantity(self): 'Test Move.internal_quantity' pool = Pool() Uom = pool.get('product.uom') Template = pool.get('product.template') Product = pool.get('product.product') Location = pool.get('stock.location') Move = pool.get('stock.move') kg, = Uom.search([('name', '=', 'Kilogram')]) g, = Uom.search([('name', '=', 'Gram')]) template, = Template.create([{ 'name': 'Test Move.internal_quantity', 'type': 'goods', 'list_price': Decimal(1), 'cost_price': Decimal(0), 'cost_price_method': 'fixed', 'default_uom': kg.id, }]) product, = Product.create([{ 'template': template.id, }]) supplier, = Location.search([('code', '=', 'SUP')]) storage, = Location.search([('code', '=', 'STO')]) company = create_company() currency = company.currency with set_company(company): tests = [ (kg, 10, 10, 0), (g, 100, 0.1, 1), (g, 1, 0, 0), # rounded (kg, 35.23, 35.23, 2), # check infinite loop ] for uom, quantity, internal_quantity, ndigits in tests: move, = Move.create([{ 'product': product.id, 'uom': uom.id, 'quantity': quantity, 'from_location': supplier.id, 'to_location': storage.id, 'company': company.id, 'unit_price': Decimal('1'), 'currency': currency.id, }]) self.assertEqual(round(move.internal_quantity, ndigits), internal_quantity) for uom, quantity, internal_quantity, ndigits in tests: Move.write([move], { 'uom': uom.id, 'quantity': quantity, }) self.assertEqual(round(move.internal_quantity, ndigits), internal_quantity)
def test_domum(self): pool = Pool() Configuration = pool.get('domum.configuration') Extension = pool.get('domum.unit.extension') UnitOwner = pool.get('domun.unit-party.owner') UnitResident = pool.get('domun.unit-party.resident') UnitAgent = pool.get('domun.unit-party.agent') company = create_company() with set_company(company): building, units = create_group_units(company)
def test_create_sale(self): pool = Pool() User = pool.get('res.user') Sequence = pool.get('ir.sequence') Currency = pool.get('currency.currency') Location = pool.get('stock.location') PaymentTerm = pool.get('account.invoice.payment_term') PriceList = pool.get('product.price_list') Shop = pool.get('sale.shop') Sale = pool.get('sale.sale') company = create_company() with set_company(company): create_chart(company) # update sale configuration sale_configuration() payment_term, = PaymentTerm.search([], limit=1) product_price_list, = PriceList.search([], limit=1) warehouse, = Location.search([('type', '=', 'warehouse')], limit=1) currency, = Currency.search([], limit=1) sequence, = Sequence.search([('code', '=', 'sale.sale')], limit=1) shop = Shop() shop.name = 'Shop test' shop.warehouse = warehouse shop.currency = currency shop.sale_sequence = sequence shop.price_list = product_price_list shop.payment_term = payment_term shop.sale_invoice_method = 'shipment' shop.sale_shipment_method = 'order' shop.esale_ext_reference = True shop.save() # set user shop user = User(Transaction().user) user.shops = [shop] user.shop = shop user.save() Sale.create_external_order( shop, sale_values=sale_values(number='S0001'), lines_values=[lines_values(code='P0001')], party_values=party_values(), invoice_values=invoice_values(), shipment_values=shipment_values()) sale, = Sale.search([('number', '=', 'S0001')], limit=1) self.assertEqual(sale.number, 'S0001') self.assertEqual(sale.comment, u'Example Sale Order') self.assertEqual(sale.total_amount, Decimal('10.00'))
def test_create_moves_after(self): "Test create not moves after end date" pool = Pool() Uom = pool.get('product.uom') Template = pool.get('product.template') Product = pool.get('product.product') Location = pool.get('stock.location') Forecast = pool.get('stock.forecast') unit, = Uom.search([('name', '=', 'Unit')]) template, = Template.create([{ 'name': 'Test create_moves', 'type': 'goods', 'default_uom': unit.id, }]) product, = Product.create([{ 'template': template.id, }]) customer, = Location.search([('code', '=', 'CUS')]) warehouse, = Location.search([('code', '=', 'WH')]) storage, = Location.search([('code', '=', 'STO')]) company = create_company() with set_company(company): today = datetime.date.today() forecast, = Forecast.create([{ 'warehouse': warehouse.id, 'destination': customer.id, 'from_date': today - relativedelta(days=20), 'to_date': today - relativedelta(days=10), 'company': company.id, 'lines': [ ( 'create', [{ 'product': product.id, 'quantity': 20, 'uom': unit.id, 'minimal_quantity': 2, }], ), ], }]) Forecast.confirm([forecast]) Forecast.create_moves([forecast]) line, = forecast.lines self.assertEqual(len(line.moves), 0)
def test_tracebility_report(self): 'Test Tracebility report' pool = Pool() Uom = pool.get('product.uom') Template = pool.get('product.template') Product = pool.get('product.product') Location = pool.get('stock.location') Move = pool.get('stock.move') PrintStockTraceabilityReport = pool.get('stock.traceability.report', type='report') PrintStockTraceability = pool.get('stock.print_traceability', type='wizard') unit, = Uom.search([('name', '=', 'Unit')]) template, = Template.create([{ 'name': 'Test Move', 'type': 'goods', 'list_price': Decimal(1), 'default_uom': unit.id, }]) product, = Product.create([{ 'template': template.id, }]) supplier, = Location.search([('code', '=', 'SUP')]) storage, = Location.search([('code', '=', 'STO')]) company = create_company() currency = company.currency with set_company(company): for quantity in [10, 100, 1, 35]: move, = Move.create([{ 'product': product.id, 'uom': unit.id, 'quantity': quantity, 'from_location': supplier.id, 'to_location': storage.id, 'company': company.id, 'unit_price': Decimal('1'), 'currency': currency.id, }]) Move.do([move]) session_id, _, _ = PrintStockTraceability.create() print_traceability = PrintStockTraceability(session_id) print_traceability.start.warehouse = storage.warehouse print_traceability.start.from_date = None print_traceability.start.to_date = None with Transaction().set_context(active_ids=[product.id], active_model='product.product'): _, data = print_traceability.do_print_(None) records, parameters = PrintStockTraceabilityReport.prepare(data) record, = records self.assertEqual(type(record['product']), DualRecord) self.assertEqual(record['supplier_incommings_total'], 146) self.assertEqual(len(record['supplier_incommings']), 4)
def test_rrhh(self): pool = Pool() Configuration = pool.get('rrhh.pa.208.configuration') Hora = pool.get('rrhh.pa.208.hora') Deduccion = pool.get('rrhh.pa.208.deduccion') # Horas hora_normal = Hora(name='NORMAL', tipo='normal') hora_normal.save() self.assertTrue(hora_normal.id) hora_domingo = Hora(name='DOMINGO', tipo='sobretiempo', recargo=50) hora_domingo.save() self.assertTrue(hora_domingo.id) falta_justificada = Hora(name='Falta Justificada', tipo='descuento') falta_justificada.save() self.assertTrue(falta_justificada.id) retraso = Hora(name='Retraso', tipo='descuento') retraso.save() self.assertTrue(retraso.id) # Deducciones seguro_social = Deduccion(name='Seguro Social', tipo='porcentaje', valor=Decimal('9.75'), ley=True) seguro_social.save() self.assertTrue(seguro_social.id) vale_20 = Deduccion(name='Vale 20', tipo='fijo', valor=Decimal('20.0')) vale_20.save() self.assertTrue(vale_20.id) company = create_company() with set_company(company): employee = create_employee('Employee 1') employee.salario = Decimal('2080.0') employee.save() self.assertEqual(employee.horas_base, Decimal(208.00)) self.assertEqual(employee.rata, Decimal('10.00'))
def test_timesheet_default_work_empty(self): "Test timesheet default work with no context" pool = Pool() ProjectWork = pool.get('project.work') TimesheetLine = pool.get('timesheet.line') company = create_company() with set_company(company): p_work = ProjectWork() p_work.name = "Work" p_work.timesheet_available = True p_work.save() self.assertFalse(TimesheetLine.default_work())
def test_rrhh(self): pool = Pool() Dependent = pool.get('rrhh.dependent') DependentRelation = pool.get('rrhh.dependent.relation') DocumentType = pool.get('rrhh.document.type') Document = pool.get('rrhh.document') Qualification = pool.get('rrhh.qualification') QualificationDegree = pool.get('rrhh.qualification.degree') company = create_company() with set_company(company): employee = create_employee('Employee 1') employee.save() self.assertTrue(employee.id)
def test_account_chart(self): 'Test creation and update of minimal chart of accounts' pool = Pool() Account = pool.get('account.account') UpdateChart = pool.get('account.update_chart', type='wizard') company = create_company() with set_company(company): create_chart(company, tax=True) root, = Account.search([('parent', '=', None)]) session_id, _, _ = UpdateChart.create() update_chart = UpdateChart(session_id) update_chart.start.account = root update_chart.transition_update()
def validate_file(flavor, kind, xsd=None): 'Test generated files are valid' pool = Pool() Payment = pool.get('account.payment') PaymentGroup = pool.get('account.payment.group') Date = pool.get('ir.date') ProcessPayment = pool.get('account.payment.process', type='wizard') if xsd is None: xsd = flavor environment = setup_environment() company = environment['company'] bank = environment['bank'] customer = environment['customer'] with set_company(company): company_account, customer_account = setup_accounts( bank, company, customer) setup_mandate(company, customer, customer_account) journal = setup_journal(flavor, kind, company, company_account) payment, = Payment.create([{ 'company': company, 'party': customer, 'journal': journal, 'kind': kind, 'amount': Decimal('1000.0'), 'state': 'approved', 'description': 'PAYMENT', 'date': Date.today(), }]) session_id, _, _ = ProcessPayment.create() process_payment = ProcessPayment(session_id) with Transaction().set_context(active_ids=[payment.id]): _, data = process_payment.do_process(None) group, = PaymentGroup.browse(data['res_id']) message, = group.sepa_messages assert message.type == 'out', message.type assert message.state == 'waiting', message.state sepa_string = message.message.encode('utf-8') sepa_xml = etree.fromstring(sepa_string) schema_file = os.path.join(os.path.dirname(__file__), '%s.xsd' % xsd) schema = etree.XMLSchema(etree.parse(schema_file)) schema.assertValid(sepa_xml)
def test_sepa_mandate_report(self): 'Test sepa mandate report' pool = Pool() Report = pool.get('account.payment.sepa.mandate', type='report') environment = setup_environment() company = environment['company'] bank = environment['bank'] customer = environment['customer'] with set_company(company): company_account, customer_account = setup_accounts( bank, company, customer) mandate = setup_mandate(company, customer, customer_account) oext, content, _, _ = Report.execute([mandate.id], {}) self.assertEqual(oext, 'odt') self.assertTrue(content)
def test_tax_rule(self): "Test tax rule" pool = Pool() TaxRule = pool.get('account.tax.rule') Tax = pool.get('account.tax') company = create_company() with set_company(company): create_chart(company, tax=True) tax, = Tax.search([]) target_tax, = Tax.copy([tax]) tax_rule, = TaxRule.create([{ 'name': 'Test', 'kind': 'both', 'lines': [('create', [{ 'origin_tax': tax.id, 'tax': target_tax.id, }])], }]) self.assertListEqual(tax_rule.apply(tax, {}), [target_tax.id])
def test_check_origin(self): 'Test Move check_origin' pool = Pool() Uom = pool.get('product.uom') Template = pool.get('product.template') Product = pool.get('product.product') Location = pool.get('stock.location') Move = pool.get('stock.move') uom, = Uom.search([('name', '=', 'Unit')]) template, = Template.create([{ 'name': 'Test Move.check_origin', 'type': 'goods', 'list_price': Decimal(1), 'cost_price': Decimal(0), 'cost_price_method': 'fixed', 'default_uom': uom.id, }]) product, = Product.create([{ 'template': template.id, }]) storage, = Location.search([('code', '=', 'STO')]) customer, = Location.search([('code', '=', 'CUS')]) company = create_company() with set_company(company): moves = Move.create([{ 'product': product.id, 'uom': uom.id, 'quantity': 1, 'from_location': storage.id, 'to_location': customer.id, 'company': company.id, 'unit_price': Decimal(1), 'currency': company.currency.id, }]) Move.check_origin(moves, set()) Move.check_origin(moves, {'supplier'}) self.assertRaises(UserWarning, Move.check_origin, moves, {'customer'})
def test_account_chart(self): 'Test creation and update of minimal chart of accounts' pool = Pool() Account = pool.get('account.account') Tax = pool.get('account.tax') UpdateChart = pool.get('account.update_chart', type='wizard') company = create_company() with set_company(company): create_chart(company, tax=True) root, = Account.search([('parent', '=', None)]) # Create an account and tax without template cash, = Account.search([('name', '=', 'Main Cash')]) Account.copy([cash.id]) tax, = Tax.search([]) Tax.copy([tax.id]) session_id, _, _ = UpdateChart.create() update_chart = UpdateChart(session_id) update_chart.start.account = root update_chart.transition_update()
def test_period(self): 'Test period' pool = Pool() Category = pool.get('product.category') Uom = pool.get('product.uom') Template = pool.get('product.template') Product = pool.get('product.product') Location = pool.get('stock.location') Move = pool.get('stock.move') Period = pool.get('stock.period') transaction = Transaction() category, = Category.create([{ 'name': 'Test period', }]) unit, = Uom.search([('name', '=', 'Unit')]) template, = Template.create([{ 'name': 'Test period', 'type': 'goods', 'category': category.id, 'cost_price_method': 'fixed', 'default_uom': unit.id, 'list_price': Decimal(0), 'cost_price': Decimal(0), }]) product, = Product.create([{ 'template': template.id, }]) supplier, = Location.search([('code', '=', 'SUP')]) customer, = Location.search([('code', '=', 'CUS')]) storage, = Location.search([('code', '=', 'STO')]) company = create_company() currency = company.currency with set_company(company): today = datetime.date.today() moves = Move.create([{ 'product': product.id, 'uom': unit.id, 'quantity': 10, 'from_location': supplier.id, 'to_location': storage.id, 'planned_date': today + relativedelta(days=-5), 'effective_date': today + relativedelta(days=-5), 'company': company.id, 'unit_price': Decimal('1'), 'currency': currency.id, }, { 'product': product.id, 'uom': unit.id, 'quantity': 15, 'from_location': supplier.id, 'to_location': storage.id, 'planned_date': today + relativedelta(days=-4), 'effective_date': today + relativedelta(days=-4), 'company': company.id, 'unit_price': Decimal('1'), 'currency': currency.id, }, { 'product': product.id, 'uom': unit.id, 'quantity': 5, 'from_location': storage.id, 'to_location': customer.id, 'planned_date': today + relativedelta(days=-3), 'effective_date': today + relativedelta(days=-3), 'company': company.id, 'unit_price': Decimal('1'), 'currency': currency.id, }]) Move.do(moves) Move.create([{ 'product': product.id, 'uom': unit.id, 'quantity': 3, 'from_location': supplier.id, 'to_location': storage.id, 'planned_date': None, 'effective_date': None, 'company': company.id, 'unit_price': Decimal('1'), 'currency': currency.id, }]) tests = [ (-5, { supplier.id: -10, storage.id: 10, }), (-3, { supplier.id: -25, storage.id: 20, customer.id: 5, }) ] products_by_location = partial(Product.products_by_location, [storage.id], [product.id]) tests_pbl = [ ({'stock_date_end': today + relativedelta(days=-6)}, 0), ({'stock_date_end': today + relativedelta(days=-5)}, 10), ({'stock_date_end': today + relativedelta(days=-4)}, 25), ({'stock_date_end': today + relativedelta(days=-3)}, 20), ({'stock_date_end': today + relativedelta(days=-2)}, 20), ({'stock_date_end': today}, 20), ({'stock_date_end': datetime.date.max}, 23), ] def test_products_by_location(): for context, quantity in tests_pbl: with transaction.set_context(context): if not quantity: self.assertEqual(products_by_location(), {}) else: self.assertEqual(products_by_location(), {(storage.id, product.id): quantity}) test_products_by_location() for days, quantities in tests: period, = Period.create([{ 'date': today + relativedelta(days=days), 'company': company.id, }]) Period.close([period]) self.assertEqual(period.state, 'closed') caches = period.caches for cache in caches: self.assertEqual(cache.product, product) self.assertEqual(cache.internal_quantity, quantities[cache.location.id]) test_products_by_location() # Test check_period_closed moves = Move.create([{ 'product': product.id, 'uom': unit.id, 'quantity': 10, 'from_location': supplier.id, 'to_location': storage.id, 'planned_date': today, 'effective_date': today, 'company': company.id, 'unit_price': Decimal('1'), 'currency': currency.id, }]) Move.do(moves) self.assertRaises(Exception, Move.create, [{ 'product': product.id, 'uom': unit.id, 'quantity': 10, 'from_location': supplier.id, 'to_location': storage.id, 'planned_date': today + relativedelta(days=-5), 'effective_date': today + relativedelta(days=-5), 'company': company.id, 'unit_price': Decimal('1'), 'currency': currency.id, }]) # Test close period check period, = Period.create([{ 'date': today, 'company': company.id, }]) self.assertRaises(Exception, Period.close, [period]) period, = Period.create([{ 'date': today + relativedelta(days=1), 'company': company.id, }]) self.assertRaises(Exception, Period.close, [period])
def test_products_by_location_with_childs(self): 'Test products_by_location with_childs and stock_skip_warehouse' pool = Pool() Uom = pool.get('product.uom') Template = pool.get('product.template') Product = pool.get('product.product') Location = pool.get('stock.location') Move = pool.get('stock.move') unit, = Uom.search([('name', '=', 'Unit')]) template, = Template.create([{ 'name': 'Test products_by_location', 'type': 'goods', 'list_price': Decimal(0), 'cost_price': Decimal(0), 'cost_price_method': 'fixed', 'default_uom': unit.id, }]) product, = Product.create([{ 'template': template.id, }]) lost_found, = Location.search([('type', '=', 'lost_found')]) warehouse, = Location.search([('type', '=', 'warehouse')]) storage, = Location.search([('code', '=', 'STO')]) input_, = Location.search([('code', '=', 'IN')]) storage1, = Location.create([{ 'name': 'Storage 1', 'type': 'view', 'parent': storage.id, }]) storage2, = Location.create([{ 'name': 'Storage 1.1', 'type': 'view', 'parent': storage1.id, }]) storage3, = Location.create([{ 'name': 'Storage 2', 'type': 'view', 'parent': storage.id, }]) company = create_company() with set_company(company): today = datetime.date.today() moves = Move.create([{ 'product': product.id, 'uom': unit.id, 'quantity': 1, 'from_location': lost_found.id, 'to_location': storage.id, 'planned_date': today, 'effective_date': today, 'company': company.id, }, { 'product': product.id, 'uom': unit.id, 'quantity': 1, 'from_location': input_.id, 'to_location': storage.id, 'planned_date': today, 'effective_date': today, 'company': company.id, }]) Move.do(moves) products_by_location = Product.products_by_location( [warehouse.id], [product.id], with_childs=True) self.assertEqual(products_by_location[(warehouse.id, product.id)], 1) with Transaction().set_context(stock_skip_warehouse=True): products_by_location = Product.products_by_location( [warehouse.id], [product.id], with_childs=True) products_by_location_all = Product.products_by_location( [warehouse.id], None, with_childs=True) self.assertEqual( products_by_location[(warehouse.id, product.id)], 2) self.assertEqual( products_by_location_all[(warehouse.id, product.id)], 2)
def test_check_credit_limit(self): 'Test check_credit_limit' pool = Pool() Account = pool.get('account.account') Move = pool.get('account.move') Journal = pool.get('account.journal') Party = pool.get('party.party') company = create_company() with set_company(company): create_chart(company) fiscalyear = get_fiscalyear(company) fiscalyear.save() fiscalyear.create_period([fiscalyear]) period = fiscalyear.periods[0] receivable, = Account.search([ ('kind', '=', 'receivable'), ]) revenue, = Account.search([ ('kind', '=', 'revenue'), ]) journal, = Journal.search([], limit=1) party, = Party.create([{ 'name': 'Party', }]) Move.create([{ 'journal': journal.id, 'period': period.id, 'date': period.start_date, 'lines': [ ('create', [{ 'debit': Decimal(100), 'account': receivable.id, 'party': party.id, }, { 'credit': Decimal(100), 'account': revenue.id, }]), ], }]) self.assertEqual(party.credit_amount, Decimal(100)) self.assertEqual(party.credit_limit_amount, None) party.check_credit_limit(Decimal(0)) party.check_credit_limit(Decimal(0), 'test') party.check_credit_limit(Decimal(100)) party.check_credit_limit(Decimal(100), 'test') party.credit_limit_amount = Decimal(0) party.save() self.assertRaises(UserError, party.check_credit_limit, Decimal(0)) self.assertRaises(UserWarning, party.check_credit_limit, Decimal(0), 'test') party.credit_limit_amount = Decimal(200) party.save() party.check_credit_limit(Decimal(0)) party.check_credit_limit(Decimal(0), 'test') self.assertRaises(UserError, party.check_credit_limit, Decimal(150)) self.assertRaises(UserWarning, party.check_credit_limit, Decimal(150), 'test')
def test_products_by_location(self): 'Test products_by_location' pool = Pool() Uom = pool.get('product.uom') Template = pool.get('product.template') Product = pool.get('product.product') Location = pool.get('stock.location') Move = pool.get('stock.move') Lot = pool.get('stock.lot') kg, = Uom.search([('name', '=', 'Kilogram')]) g, = Uom.search([('name', '=', 'Gram')]) template, = Template.create([{ 'name': 'Test products_by_location', 'type': 'goods', 'list_price': Decimal(0), 'cost_price': Decimal(0), 'cost_price_method': 'fixed', 'default_uom': kg.id, }]) product, = Product.create([{ 'template': template.id, }]) supplier, = Location.search([('code', '=', 'SUP')]) customer, = Location.search([('code', '=', 'CUS')]) storage, = Location.search([('code', '=', 'STO')]) company = create_company() currency = company.currency with set_company(company): lot1, lot2 = Lot.create([{ 'number': '1', 'product': product.id, }, { 'number': '2', 'product': product.id, }]) moves = Move.create([{ 'product': product.id, 'lot': lot1.id, 'uom': kg.id, 'quantity': 5, 'from_location': supplier.id, 'to_location': storage.id, 'company': company.id, 'unit_price': Decimal('1'), 'currency': currency.id, }, { 'product': product.id, 'lot': lot2.id, 'uom': kg.id, 'quantity': 10, 'from_location': supplier.id, 'to_location': storage.id, 'company': company.id, 'unit_price': Decimal('1'), 'currency': currency.id, }, { 'product': product.id, 'lot': lot2.id, 'uom': kg.id, 'quantity': 2, 'from_location': storage.id, 'to_location': customer.id, 'company': company.id, 'unit_price': Decimal('1'), 'currency': currency.id, }, { 'product': product.id, 'lot': None, 'uom': kg.id, 'quantity': 3, 'from_location': supplier.id, 'to_location': storage.id, 'company': company.id, 'unit_price': Decimal('1'), 'currency': currency.id, }]) Move.do(moves) self.assertEqual(Product.products_by_location([storage.id], [product.id]), { (storage.id, product.id): 16, }) self.assertEqual(Product.products_by_location([storage.id], [product.id], grouping=('product', 'lot')), { (storage.id, product.id, lot1.id): 5, (storage.id, product.id, lot2.id): 8, (storage.id, product.id, None): 3, }) with Transaction().set_context(locations=[storage.id]): self.assertEqual(lot1.quantity, 5) self.assertEqual(lot2.quantity, 8)
def test_products_by_location(self): 'Test products_by_location' pool = Pool() Category = pool.get('product.category') Uom = pool.get('product.uom') Template = pool.get('product.template') Product = pool.get('product.product') Location = pool.get('stock.location') Move = pool.get('stock.move') Period = pool.get('stock.period') transaction = Transaction() category, = Category.create([{ 'name': 'Test products_by_location', }]) kg, = Uom.search([('name', '=', 'Kilogram')]) g, = Uom.search([('name', '=', 'Gram')]) template, = Template.create([{ 'name': 'Test products_by_location', 'type': 'goods', 'list_price': Decimal(0), 'cost_price': Decimal(0), 'category': category.id, 'cost_price_method': 'fixed', 'default_uom': kg.id, }]) product, = Product.create([{ 'template': template.id, }]) supplier, = Location.search([('code', '=', 'SUP')]) customer, = Location.search([('code', '=', 'CUS')]) storage, = Location.search([('code', '=', 'STO')]) company = create_company() currency = company.currency with set_company(company): today = datetime.date.today() moves = Move.create([{ 'product': product.id, 'uom': kg.id, 'quantity': 5, 'from_location': supplier.id, 'to_location': storage.id, 'planned_date': today + relativedelta(days=-5), 'effective_date': today + relativedelta(days=-5), 'company': company.id, 'unit_price': Decimal('1'), 'currency': currency.id, }, { 'product': product.id, 'uom': kg.id, 'quantity': 1, 'from_location': supplier.id, 'to_location': storage.id, 'planned_date': today + relativedelta(days=-4), 'company': company.id, 'unit_price': Decimal('1'), 'currency': currency.id, }, { 'product': product.id, 'uom': kg.id, 'quantity': 1, 'from_location': storage.id, 'to_location': customer.id, 'planned_date': today, 'effective_date': today, 'company': company.id, 'unit_price': Decimal('1'), 'currency': currency.id, }, { 'product': product.id, 'uom': kg.id, 'quantity': 1, 'from_location': storage.id, 'to_location': customer.id, 'planned_date': today, 'company': company.id, 'unit_price': Decimal('1'), 'currency': currency.id, }, { 'product': product.id, 'uom': kg.id, 'quantity': 2, 'from_location': storage.id, 'to_location': customer.id, 'planned_date': today + relativedelta(days=5), 'company': company.id, 'unit_price': Decimal('1'), 'currency': currency.id, }, { 'product': product.id, 'uom': kg.id, 'quantity': 5, 'from_location': supplier.id, 'to_location': storage.id, 'planned_date': today + relativedelta(days=7), 'company': company.id, 'unit_price': Decimal('1'), 'currency': currency.id, }]) Move.do([moves[0], moves[2]]) products_by_location = partial(Product.products_by_location, [storage.id], [product.id]) tests = [ ({'stock_date_end': today + relativedelta(days=-6), }, 0), ({'stock_date_end': today + relativedelta(days=-5), }, 5), ({'stock_date_end': today + relativedelta(days=-4), }, 5), ({'stock_date_end': today + relativedelta(days=-3), }, 5), ({'stock_date_end': today, }, 4), ({'stock_date_end': today + relativedelta(days=1), }, 3), ({'stock_date_end': today + relativedelta(days=5), }, 1), ({'stock_date_end': today + relativedelta(days=6), }, 1), ({'stock_date_end': today + relativedelta(days=7), }, 6), ({'stock_date_end': today + relativedelta(days=8), }, 6), ({'stock_date_end': False, }, 6), ({'stock_date_end': today + relativedelta(days=-6), 'forecast': True, }, 0), ({'stock_date_end': today + relativedelta(days=-5), 'forecast': True, }, 5), ({'stock_date_end': today + relativedelta(days=-4), 'forecast': True, }, 5), ({'stock_date_end': today + relativedelta(days=-3), 'forecast': True, }, 5), ({'stock_date_end': today, 'forecast': True, }, 3), ({'stock_date_end': today + relativedelta(days=1), 'forecast': True, }, 3), ({'stock_date_end': today + relativedelta(days=5), 'forecast': True, }, 1), ({'stock_date_end': today + relativedelta(days=6), 'forecast': True, }, 1), ({'stock_date_end': today + relativedelta(days=7), 'forecast': True, }, 6), ({'stock_date_end': False, 'forecast': True, }, 6), ] def tests_product_quantity(context, quantity): with transaction.set_context(locations=[storage.id]): product_reloaded = Product(product.id) if (not context.get('stock_date_end') or context['stock_date_end'] > today or context.get('forecast')): self.assertEqual(product_reloaded.forecast_quantity, quantity) else: self.assertEqual(product_reloaded.quantity, quantity) def tests_product_search_quantity(context, quantity): with transaction.set_context(locations=[storage.id]): if (not context.get('stock_date_end') or context['stock_date_end'] > today or context.get('forecast')): fname = 'forecast_quantity' else: fname = 'quantity' found_products = Product.search([ (fname, '=', quantity), ]) self.assertIn(product, found_products) found_products = Product.search([ (fname, '!=', quantity), ]) self.assertNotIn(product, found_products) found_products = Product.search([ (fname, 'in', (quantity, quantity + 1)), ]) self.assertIn(product, found_products) found_products = Product.search([ (fname, 'not in', (quantity, quantity + 1)), ]) self.assertNotIn(product, found_products) found_products = Product.search([ (fname, '<', quantity), ]) self.assertNotIn(product, found_products) found_products = Product.search([ (fname, '<', quantity + 1), ]) self.assertIn(product, found_products) found_products = Product.search([ (fname, '>', quantity), ]) self.assertNotIn(product, found_products) found_products = Product.search([ (fname, '>', quantity - 1), ]) self.assertIn(product, found_products) found_products = Product.search([ (fname, '>=', quantity), ]) self.assertIn(product, found_products) found_products = Product.search([ (fname, '<=', quantity), ]) self.assertIn(product, found_products) def test_products_by_location(): for context, quantity in tests: with transaction.set_context(context): if not quantity: self.assertEqual(products_by_location(), {}) else: self.assertEqual(products_by_location(), {(storage.id, product.id): quantity}) tests_product_quantity(context, quantity) tests_product_search_quantity(context, quantity) test_products_by_location() periods = [ today + relativedelta(days=-6), today + relativedelta(days=-5), today + relativedelta(days=-4), today + relativedelta(days=-3), today + relativedelta(days=-2), ] moves = Move.create([{ 'product': product.id, 'uom': g.id, 'quantity': 1, 'from_location': supplier.id, 'to_location': storage.id, 'planned_date': today + relativedelta(days=-5), 'effective_date': (today + relativedelta(days=-5)), 'company': company.id, 'unit_price': Decimal('1'), 'currency': currency.id, }]) Move.do(moves) # Nothing should change when adding a small quantity test_products_by_location() for period_date in periods: period, = Period.create([{ 'date': period_date, 'company': company.id, }]) Period.close([period]) test_products_by_location()
def test_account_debit_credit(self): 'Test account debit/credit' pool = Pool() Party = pool.get('party.party') AnalyticAccount = pool.get('analytic_account.account') Journal = pool.get('account.journal') Account = pool.get('account.account') Move = pool.get('account.move') transaction = Transaction() party = Party(name='Party') party.save() company = create_company() with set_company(company): root, = AnalyticAccount.create([{ 'type': 'root', 'name': 'Root', }]) analytic_account, = AnalyticAccount.create([{ 'type': 'normal', 'name': 'Analytic Account', 'parent': root.id, 'root': root.id, }]) create_chart(company) fiscalyear = get_fiscalyear(company) fiscalyear.save() fiscalyear.create_period([fiscalyear]) period = fiscalyear.periods[0] journal_revenue, = Journal.search([ ('code', '=', 'REV'), ]) journal_expense, = Journal.search([ ('code', '=', 'EXP'), ]) revenue, = Account.search([ ('kind', '=', 'revenue'), ]) receivable, = Account.search([ ('kind', '=', 'receivable'), ]) expense, = Account.search([ ('kind', '=', 'expense'), ]) payable, = Account.search([ ('kind', '=', 'payable'), ]) first_account_line = { 'account': revenue.id, 'credit': Decimal(100), 'analytic_lines': [ ('create', [{ 'account': analytic_account.id, 'name': 'Analytic Line', 'credit': Decimal(100), 'debit': Decimal(0), 'journal': journal_revenue.id, 'date': period.start_date, }]) ]} second_account_line = { 'account': expense.id, 'debit': Decimal(30), 'analytic_lines': [ ('create', [{ 'account': analytic_account.id, 'name': 'Analytic Line', 'debit': Decimal(30), 'credit': Decimal(0), 'journal': journal_expense.id, 'date': period.start_date, }]) ]} # Create some moves vlist = [{ 'period': period.id, 'journal': journal_revenue.id, 'date': period.start_date, 'lines': [ ('create', [first_account_line, { 'account': receivable.id, 'debit': Decimal(100), 'party': party.id, }]), ], }, { 'period': period.id, 'journal': journal_expense.id, 'date': period.start_date, 'lines': [ ('create', [second_account_line, { 'account': payable.id, 'credit': Decimal(30), 'party': party.id, }]), ], }, ] Move.create(vlist) self.assertEqual((analytic_account.debit, analytic_account.credit), (Decimal(30), Decimal(100))) self.assertEqual(analytic_account.balance, Decimal(70)) with transaction.set_context(start_date=period.end_date): analytic_account = AnalyticAccount(analytic_account.id) self.assertEqual((analytic_account.debit, analytic_account.credit), (Decimal(0), Decimal(0))) self.assertEqual(analytic_account.balance, Decimal(0)) with transaction.set_context(end_date=period.end_date): analytic_account = AnalyticAccount(analytic_account.id) self.assertEqual((analytic_account.debit, analytic_account.credit), (Decimal(30), Decimal(100))) self.assertEqual(analytic_account.balance, Decimal(70))
def test_account_chart(self): 'Test creation of minimal chart of accounts' company = create_company() with set_company(company): create_chart(company, tax=True)
def test_account_debit_credit(self): 'Test account debit/credit' pool = Pool() Party = pool.get('party.party') FiscalYear = pool.get('account.fiscalyear') Period = pool.get('account.period') Journal = pool.get('account.journal') Account = pool.get('account.account') AccountType = pool.get('account.account.type') Move = pool.get('account.move') Sequence = pool.get('ir.sequence') BalanceNonDeferral = pool.get( 'account.fiscalyear.balance_non_deferral', type='wizard') party = Party(name='Party') party.save() company = create_company() with set_company(company): fiscalyear = get_fiscalyear(company) fiscalyear.save() FiscalYear.create_period([fiscalyear]) period = fiscalyear.periods[0] create_chart(company) journal_revenue, = Journal.search([ ('code', '=', 'REV'), ]) journal_expense, = Journal.search([ ('code', '=', 'EXP'), ]) revenue, = Account.search([ ('kind', '=', 'revenue'), ]) receivable, = Account.search([ ('kind', '=', 'receivable'), ]) expense, = Account.search([ ('kind', '=', 'expense'), ]) payable, = Account.search([ ('kind', '=', 'payable'), ]) # Create some moves vlist = [ { 'period': period.id, 'journal': journal_revenue.id, 'date': period.start_date, 'lines': [ ('create', [{ 'account': revenue.id, 'credit': Decimal(100), }, { 'account': receivable.id, 'debit': Decimal(100), 'party': party.id, }]), ], }, { 'period': period.id, 'journal': journal_expense.id, 'date': period.start_date, 'lines': [ ('create', [{ 'account': expense.id, 'debit': Decimal(30), }, { 'account': payable.id, 'credit': Decimal(30), 'party': party.id, }]), ], }, ] Move.create(vlist) # Test debit/credit self.assertEqual((revenue.debit, revenue.credit), (Decimal(0), Decimal(100))) self.assertEqual(revenue.balance, Decimal(-100)) # Use next fiscalyear today = datetime.date.today() next_fiscalyear = get_fiscalyear(company, today=today.replace(year=today.year + 1)) next_fiscalyear.save() FiscalYear.create_period([next_fiscalyear]) # Test debit/credit for next year with Transaction().set_context(fiscalyear=next_fiscalyear.id): revenue = Account(revenue.id) self.assertEqual((revenue.debit, revenue.credit), (Decimal(0), Decimal(0))) self.assertEqual(revenue.balance, Decimal(-100)) # Test debit/credit cumulate for next year with Transaction().set_context(fiscalyear=next_fiscalyear.id, cumulate=True): revenue = Account(revenue.id) self.assertEqual((revenue.debit, revenue.credit), (Decimal(0), Decimal(100))) self.assertEqual(revenue.balance, Decimal(-100)) # Balance non-deferral journal_sequence, = Sequence.search([ ('code', '=', 'account.journal'), ]) journal_closing, = Journal.create([{ 'name': 'Closing', 'code': 'CLO', 'type': 'situation', 'sequence': journal_sequence.id, }]) period_closing, = Period.create([{ 'name': 'Closing', 'start_date': fiscalyear.end_date, 'end_date': fiscalyear.end_date, 'fiscalyear': fiscalyear.id, 'type': 'adjustment', }]) type_equity, = AccountType.search([ ('name', '=', 'Equity'), ]) account_pl, = Account.create([{ 'name': 'P&L', 'type': type_equity.id, 'deferral': True, 'parent': revenue.parent.id, 'kind': 'other', }]) session_id = BalanceNonDeferral.create()[0] balance_non_deferral = BalanceNonDeferral(session_id) balance_non_deferral.start.fiscalyear = fiscalyear balance_non_deferral.start.journal = journal_closing balance_non_deferral.start.period = period_closing balance_non_deferral.start.credit_account = account_pl balance_non_deferral.start.debit_account = account_pl balance_non_deferral._execute('balance') moves = Move.search([ ('state', '=', 'draft'), ('period.fiscalyear', '=', fiscalyear.id), ]) Move.post(moves) # Close fiscalyear FiscalYear.close([fiscalyear]) # Check deferral self.assertEqual(revenue.deferrals, ()) deferral_receivable, = receivable.deferrals self.assertEqual( (deferral_receivable.debit, deferral_receivable.credit), (Decimal(100), Decimal(0))) self.assertEqual(deferral_receivable.fiscalyear, fiscalyear) # Test debit/credit with Transaction().set_context(fiscalyear=fiscalyear.id): revenue = Account(revenue.id) self.assertEqual((revenue.debit, revenue.credit), (Decimal(100), Decimal(100))) self.assertEqual(revenue.balance, Decimal(0)) receivable = Account(receivable.id) self.assertEqual((receivable.debit, receivable.credit), (Decimal(100), Decimal(0))) self.assertEqual(receivable.balance, Decimal(100)) # Test debit/credit for next year with Transaction().set_context(fiscalyear=next_fiscalyear.id): revenue = Account(revenue.id) self.assertEqual((revenue.debit, revenue.credit), (Decimal(0), Decimal(0))) self.assertEqual(revenue.balance, Decimal(0)) receivable = Account(receivable.id) self.assertEqual((receivable.debit, receivable.credit), (Decimal(0), Decimal(0))) self.assertEqual(receivable.balance, Decimal(100)) # Test debit/credit cumulate for next year with Transaction().set_context(fiscalyear=next_fiscalyear.id, cumulate=True): revenue = Account(revenue.id) self.assertEqual((revenue.debit, revenue.credit), (Decimal(0), Decimal(0))) self.assertEqual(revenue.balance, Decimal(0)) receivable = Account(receivable.id) self.assertEqual((receivable.debit, receivable.credit), (Decimal(100), Decimal(0))) self.assertEqual(receivable.balance, Decimal(100))
def test_tax_compute(self): 'Test tax compute/reverse_compute' pool = Pool() Account = pool.get('account.account') Tax = pool.get('account.tax') today = datetime.date.today() company = create_company() with set_company(company): create_chart(company) tax_account, = Account.search([ ('name', '=', 'Main Tax'), ]) tax = Tax() tax.name = tax.description = 'Test' tax.type = 'none' tax.invoice_account = tax_account tax.credit_note_account = tax_account child1 = Tax() child1.name = child1.description = 'Child 1' child1.type = 'percentage' child1.rate = Decimal('0.2') child1.invoice_account = tax_account child1.credit_note_account = tax_account child1.save() child2 = Tax() child2.name = child2.description = 'Child 1' child2.type = 'fixed' child2.amount = Decimal('10') child2.invoice_account = tax_account child2.credit_note_account = tax_account child2.save() tax.childs = [child1, child2] tax.save() self.assertEqual(Tax.compute([tax], Decimal('100'), 2), [{ 'base': Decimal('200'), 'amount': Decimal('40.0'), 'tax': child1, }, { 'base': Decimal('200'), 'amount': Decimal('20'), 'tax': child2, }]) self.assertEqual( Tax.reverse_compute(Decimal('130'), [tax]), Decimal('100')) child1.end_date = today + relativedelta(days=5) child1.save() self.assertEqual(Tax.compute([tax], Decimal('100'), 2, today), [{ 'base': Decimal('200'), 'amount': Decimal('40.0'), 'tax': child1, }, { 'base': Decimal('200'), 'amount': Decimal('20'), 'tax': child2, }]) self.assertEqual( Tax.reverse_compute(Decimal('130'), [tax], today), Decimal('100')) child1.start_date = today + relativedelta(days=1) child1.save() self.assertEqual(Tax.compute([tax], Decimal('100'), 2, today), [{ 'base': Decimal('200'), 'amount': Decimal('20'), 'tax': child2, }]) self.assertEqual( Tax.reverse_compute(Decimal('110'), [tax], today), Decimal('100')) self.assertEqual(Tax.compute([tax], Decimal('100'), 2, today + relativedelta(days=1)), [{ 'base': Decimal('200'), 'amount': Decimal('40.0'), 'tax': child1, }, { 'base': Decimal('200'), 'amount': Decimal('20'), 'tax': child2, }]) self.assertEqual( Tax.reverse_compute( Decimal('130'), [tax], today + relativedelta(days=1)), Decimal('100')) self.assertEqual(Tax.compute([tax], Decimal('100'), 2, today + relativedelta(days=5)), [{ 'base': Decimal('200'), 'amount': Decimal('40.0'), 'tax': child1, }, { 'base': Decimal('200'), 'amount': Decimal('20'), 'tax': child2, }]) self.assertEqual( Tax.reverse_compute(Decimal('130'), [tax], today + relativedelta(days=5)), Decimal('100')) self.assertEqual(Tax.compute([tax], Decimal('100'), 2, today + relativedelta(days=6)), [{ 'base': Decimal('200'), 'amount': Decimal('20'), 'tax': child2, }]) self.assertEqual( Tax.reverse_compute(Decimal('110'), [tax], today + relativedelta(days=6)), Decimal('100')) child1.end_date = None child1.save() self.assertEqual(Tax.compute([tax], Decimal('100'), 2, today + relativedelta(days=6)), [{ 'base': Decimal('200'), 'amount': Decimal('40.0'), 'tax': child1, }, { 'base': Decimal('200'), 'amount': Decimal('20'), 'tax': child2, }]) self.assertEqual( Tax.reverse_compute(Decimal('130'), [tax], today + relativedelta(days=6)), Decimal('100')) ecotax1 = Tax() ecotax1.name = ecotax1.description = 'EcoTax 1' ecotax1.type = 'fixed' ecotax1.amount = Decimal(5) ecotax1.invoice_account = tax_account ecotax1.credit_note_account = tax_account ecotax1.sequence = 10 ecotax1.save() vat0 = Tax() vat0.name = vat0.description = 'VAT0' vat0.type = 'percentage' vat0.rate = Decimal('0.1') vat0.invoice_account = tax_account vat0.credit_note_account = tax_account vat0.sequence = 5 vat0.save() vat1 = Tax() vat1.name = vat1.description = 'VAT1' vat1.type = 'percentage' vat1.rate = Decimal('0.2') vat1.invoice_account = tax_account vat1.credit_note_account = tax_account vat1.sequence = 20 vat1.save() self.assertEqual( Tax.compute([vat0, ecotax1, vat1], Decimal(100), 1), [{ 'base': Decimal(100), 'amount': Decimal(10), 'tax': vat0, }, { 'base': Decimal(100), 'amount': Decimal(5), 'tax': ecotax1, }, { 'base': Decimal(100), 'amount': Decimal(20), 'tax': vat1, }]) self.assertEqual( Tax.reverse_compute(Decimal(135), [vat0, ecotax1, vat1]), Decimal(100))
def test_tax_compute_with_update_unit_price(self): 'Test tax compute with unit_price modifying tax' pool = Pool() Account = pool.get('account.account') Tax = pool.get('account.tax') company = create_company() with set_company(company): create_chart(company) tax_account, = Account.search([ ('name', '=', 'Main Tax'), ]) ecotax1 = Tax() ecotax1.name = ecotax1.description = 'EcoTax 1' ecotax1.type = 'fixed' ecotax1.amount = Decimal(5) ecotax1.invoice_account = tax_account ecotax1.credit_note_account = tax_account ecotax1.update_unit_price = True ecotax1.sequence = 10 ecotax1.save() vat1 = Tax() vat1.name = vat1.description = 'VAT1' vat1.type = 'percentage' vat1.rate = Decimal('0.2') vat1.invoice_account = tax_account vat1.credit_note_account = tax_account vat1.sequence = 20 vat1.save() self.assertEqual( Tax.compute([ecotax1, vat1], Decimal(100), 5), [{ 'base': Decimal(500), 'amount': Decimal(25), 'tax': ecotax1, }, { 'base': Decimal(525), 'amount': Decimal(105), 'tax': vat1, }]) self.assertEqual( Tax.reverse_compute(Decimal(126), [ecotax1, vat1]), Decimal(100)) ecotax2 = Tax() ecotax2.name = ecotax2.description = 'EcoTax 2' ecotax2.type = 'percentage' ecotax2.rate = Decimal('0.5') ecotax2.invoice_account = tax_account ecotax2.credit_note_account = tax_account ecotax2.update_unit_price = True ecotax2.sequence = 10 ecotax2.save() self.assertEqual( Tax.compute([ecotax1, ecotax2, vat1], Decimal(100), 1), [{ 'base': Decimal(100), 'amount': Decimal(5), 'tax': ecotax1, }, { 'base': Decimal(100), 'amount': Decimal(50), 'tax': ecotax2, }, { 'base': Decimal(155), 'amount': Decimal(31), 'tax': vat1, }]) self.assertEqual( Tax.reverse_compute(Decimal(186), [ecotax1, ecotax2, vat1]), Decimal(100)) vat0 = Tax() vat0.name = vat0.description = 'VAT0' vat0.type = 'percentage' vat0.rate = Decimal('0.1') vat0.invoice_account = tax_account vat0.credit_note_account = tax_account vat0.sequence = 5 vat0.save() self.assertEqual( Tax.compute([vat0, ecotax1, vat1], Decimal(100), 1), [{ 'base': Decimal(100), 'amount': Decimal(10), 'tax': vat0, }, { 'base': Decimal(100), 'amount': Decimal(5), 'tax': ecotax1, }, { 'base': Decimal(105), 'amount': Decimal(21), 'tax': vat1, }]) self.assertEqual( Tax.reverse_compute(Decimal(136), [vat0, ecotax1, vat1]), Decimal(100)) self.assertEqual( Tax.compute([vat0, ecotax1, ecotax2, vat1], Decimal(100), 1), [{ 'base': Decimal(100), 'amount': Decimal(10), 'tax': vat0, }, { 'base': Decimal(100), 'amount': Decimal(5), 'tax': ecotax1, }, { 'base': Decimal(100), 'amount': Decimal(50), 'tax': ecotax2, }, { 'base': Decimal(155), 'amount': Decimal(31), 'tax': vat1, }]) self.assertEqual( Tax.reverse_compute(Decimal(196), [vat0, ecotax1, ecotax2, vat1]), Decimal(100)) vat2 = Tax() vat2.name = vat2.description = 'VAT2' vat2.type = 'percentage' vat2.rate = Decimal('0.3') vat2.invoice_account = tax_account vat2.credit_note_account = tax_account vat2.sequence = 30 vat2.save() self.assertEqual( Tax.compute([vat0, ecotax1, vat1, vat2], Decimal(100), 1), [{ 'base': Decimal(100), 'amount': Decimal(10), 'tax': vat0, }, { 'base': Decimal(100), 'amount': Decimal(5), 'tax': ecotax1, }, { 'base': Decimal(105), 'amount': Decimal(21), 'tax': vat1, }, { 'base': Decimal(105), 'amount': Decimal('31.5'), 'tax': vat2, }]) self.assertEqual( Tax.reverse_compute(Decimal('167.5'), [vat0, ecotax1, vat1, vat2]), Decimal(100)) ecotax3 = Tax() ecotax3.name = ecotax3.description = 'ECOTAX3' ecotax3.type = 'percentage' ecotax3.rate = Decimal('0.4') ecotax3.invoice_account = tax_account ecotax3.credit_note_account = tax_account ecotax3.update_unit_price = True ecotax3.sequence = 25 ecotax3.save() self.assertEqual( Tax.compute([vat0, ecotax1, vat1, ecotax3, vat2], Decimal(100), 1), [{ 'base': Decimal(100), 'amount': Decimal(10), 'tax': vat0, }, { 'base': Decimal(100), 'amount': Decimal(5), 'tax': ecotax1, }, { 'base': Decimal(105), 'amount': Decimal(21), 'tax': vat1, }, { 'base': Decimal(105), 'amount': Decimal('42'), 'tax': ecotax3, }, { 'base': Decimal(147), 'amount': Decimal('44.1'), 'tax': vat2 }]) self.assertEqual( Tax.reverse_compute(Decimal('222.1'), [vat0, ecotax1, vat1, ecotax3, vat2]), Decimal(100))
def test_receivable_payable(self): 'Test party receivable payable' pool = Pool() Party = pool.get('party.party') FiscalYear = pool.get('account.fiscalyear') Journal = pool.get('account.journal') Account = pool.get('account.account') Move = pool.get('account.move') company = create_company() with set_company(company): create_chart(company) fiscalyear = get_fiscalyear(company) fiscalyear.save() FiscalYear.create_period([fiscalyear]) period = fiscalyear.periods[0] journal_revenue, = Journal.search([ ('code', '=', 'REV'), ]) journal_expense, = Journal.search([ ('code', '=', 'EXP'), ]) revenue, = Account.search([ ('kind', '=', 'revenue'), ]) receivable, = Account.search([ ('kind', '=', 'receivable'), ]) expense, = Account.search([ ('kind', '=', 'expense'), ]) payable, = Account.search([ ('kind', '=', 'payable'), ]) party, = Party.create([{ 'name': 'Receivable/Payable party', }]) tomorrow = datetime.date.today() + datetime.timedelta(days=1) def get_move(journal, amount, credit_account, debit_account, party, maturity_date=None): return { 'period': period.id, 'journal': journal.id, 'date': period.start_date, 'lines': [ ('create', [{ 'account': credit_account.id, 'credit': amount, }, { 'account': debit_account.id, 'debit': amount, 'party': party.id, 'maturity_date': maturity_date, }]), ], } vlist = [ get_move(journal_revenue, Decimal(100), revenue, receivable, party), get_move(journal_expense, Decimal(30), expense, payable, party), get_move(journal_revenue, Decimal(200), revenue, receivable, party, tomorrow), get_move(journal_revenue, Decimal(60), expense, payable, party, tomorrow), ] moves = Move.create(vlist) Move.post(moves) party = Party(party.id) self.assertEqual(party.receivable, Decimal('300')) self.assertEqual(party.receivable_today, Decimal('100')) self.assertEqual(party.payable, Decimal('90')) self.assertEqual(party.payable_today, Decimal('30'))
def _test_assign_try(self, quantity, quantities, success, result): pool = Pool() Template = pool.get('product.template') Product = pool.get('product.product') Uom = pool.get('product.uom') Location = pool.get('stock.location') Move = pool.get('stock.move') uom, = Uom.search([('name', '=', 'Meter')]) template = Template( name='Test Move.assign_try', type='goods', list_price=Decimal(1), cost_price=Decimal(0), cost_price_method='fixed', default_uom=uom, ) template.save() product = Product(template=template.id) product.save() supplier, = Location.search([('code', '=', 'SUP')]) storage, = Location.search([('code', '=', 'STO')]) customer, = Location.search([('code', '=', 'CUS')]) company = create_company() with set_company(company): move, = Move.create([{ 'product': product.id, 'uom': uom.id, 'quantity': quantity, 'from_location': supplier.id, 'to_location': storage.id, 'company': company.id, 'unit_price': Decimal(1), 'currency': company.currency.id, }]) Move.do([move]) moves = Move.create([{ 'product': product.id, 'uom': uom.id, 'quantity': qty, 'from_location': storage.id, 'to_location': customer.id, 'company': company.id, 'unit_price': Decimal(1), 'currency': company.currency.id, } for qty in quantities]) msg = 'quantity: %s, quantities: %s' % (quantity, quantities) self.assertEqual(Move.assign_try(moves), success, msg=msg) moves = Move.search([ ('product', '=', product.id), ('from_location', '=', storage.id), ('to_location', '=', customer.id), ('company', '=', company.id), ]) states = defaultdict(list) for move in moves: states[move.state].append(move.quantity) for state in states: states[state].sort() self.assertEqual(states, result, msg=msg)
def test_sum_tree(self): 'Test sum_tree' pool = Pool() TimesheetWork = pool.get('timesheet.work') ProjectWork = pool.get('project.work') company = create_company() with set_company(company): t_work_1, = TimesheetWork.create([{ 'name': 'Work 1', 'company': company.id, }]) p_work_1, = ProjectWork.create([{ 'name': 'Work 1', 'company': company.id, 'work': t_work_1.id, 'effort_duration': datetime.timedelta(hours=1), }]) t_work_1_1, = TimesheetWork.create([{ 'name': 'Work 1 1', 'company': company.id, 'parent': t_work_1.id, }]) p_work_1_1, = ProjectWork.create([{ 'name': 'Work 1 1', 'company': company.id, 'parent': p_work_1.id, 'work': t_work_1_1.id, 'effort_duration': datetime.timedelta(hours=1), }]) t_work_1_2, = TimesheetWork.create([{ 'name': 'Work 1 1', 'company': company.id, 'parent': t_work_1.id, }]) p_work_1_2, = ProjectWork.create([{ 'name': 'Work 1 2', 'company': company.id, 'parent': p_work_1.id, 'work': t_work_1_2.id, 'effort_duration': datetime.timedelta(hours=1), }]) t_work_1_1_1, = TimesheetWork.create([{ 'name': 'Work 1 1 1', 'company': company.id, 'parent': t_work_1_1.id, }]) p_work_1_1_1, = ProjectWork.create([{ 'name': 'Work 1 1 1', 'company': company.id, 'parent': p_work_1_1.id, 'work': t_work_1_1_1.id, 'effort_duration': datetime.timedelta(hours=1), }]) t_work_1_1_2, = TimesheetWork.create([{ 'name': 'Work 1 1 2', 'company': company.id, 'parent': t_work_1_1.id, }]) p_work_1_1_2, = ProjectWork.create([{ 'name': 'Work 1 1 2', 'company': company.id, 'parent': p_work_1_1.id, 'work': t_work_1_1_2.id, 'effort_duration': datetime.timedelta(hours=1), }]) t_work_1_1_3, = TimesheetWork.create([{ 'name': 'Work 1 1 3', 'company': company.id, 'parent': t_work_1_1.id, }]) p_work_1_1_3, = ProjectWork.create([{ 'name': 'Work 1 1 3', 'company': company.id, 'parent': p_work_1_1.id, 'work': t_work_1_1_3.id, 'effort_duration': datetime.timedelta(hours=1), }]) for work, total_effort in ( (p_work_1, 6), (p_work_1_1, 4), (p_work_1_2, 1), (p_work_1_1_1, 1), (p_work_1_1_2, 1), (p_work_1_1_3, 1), ): self.assertEqual(work.total_effort, datetime.timedelta(hours=total_effort))
def test_account_used(self): 'Test account used' pool = Pool() ProductTemplate = pool.get('product.template') ProductCategory = pool.get('product.category') Uom = pool.get('product.uom') Account = pool.get('account.account') company = create_company() with set_company(company): create_chart(company) unit, = Uom.search([ ('name', '=', 'Unit'), ]) account_expense, = Account.search([ ('kind', '=', 'expense'), ]) # raise when empty template = ProductTemplate( name='test account used', list_price=Decimal(10), cost_price=Decimal(3), default_uom=unit.id, ) template.save() self.assertIsNone(template.account_expense) with self.assertRaises(UserError): template.account_expense_used # with account template = ProductTemplate( name='test account used', list_price=Decimal(10), cost_price=Decimal(3), default_uom=unit.id, account_expense=account_expense.id, ) template.save() self.assertEqual(template.account_expense, account_expense) self.assertEqual(template.account_expense_used, account_expense) # with account on category category = ProductCategory(name='test account used', account_expense=account_expense) category.save() template.account_expense = None template.account_category = True template.category = category template.save() self.assertIsNone(template.account_expense) self.assertEqual(template.account_expense_used, account_expense) # with account on grant category parent_category = ProductCategory(name='parent account used', account_expense=account_expense) parent_category.save() category.account_expense = None category.account_parent = True category.parent = parent_category category.save() self.assertIsNone(category.account_expense) self.assertEqual(template.account_expense_used, account_expense) self.assertEqual(category.account_expense_used, account_expense) # raise only at direct usage templates = ProductTemplate.create([{ 'name': 'test with account', 'list_price': Decimal(10), 'cost_price': Decimal(3), 'default_uom': unit.id, 'account_expense': account_expense.id, }, { 'name': 'test without account', 'list_price': Decimal(10), 'cost_price': Decimal(3), 'default_uom': unit.id, 'account_expense': None, }]) self.assertEqual(templates[0].account_expense_used.id, account_expense.id) with self.assertRaises(UserError): templates[1].account_expense_used
def test_period(self): 'Test period' pool = Pool() Uom = pool.get('product.uom') Template = pool.get('product.template') Product = pool.get('product.product') Location = pool.get('stock.location') Move = pool.get('stock.move') Lot = pool.get('stock.lot') Period = pool.get('stock.period') unit, = Uom.search([('name', '=', 'Unit')]) template, = Template.create([{ 'name': 'Test period', 'type': 'goods', 'cost_price_method': 'fixed', 'default_uom': unit.id, 'list_price': Decimal(0), 'cost_price': Decimal(0), }]) product, = Product.create([{ 'template': template.id, }]) supplier, = Location.search([('code', '=', 'SUP')]) storage, = Location.search([('code', '=', 'STO')]) company = create_company() currency = company.currency with set_company(company): lot1, lot2 = Lot.create([{ 'number': '1', 'product': product.id, }, { 'number': '2', 'product': product.id, }]) today = datetime.date.today() moves = Move.create([{ 'product': product.id, 'lot': lot1.id, 'uom': unit.id, 'quantity': 5, 'from_location': supplier.id, 'to_location': storage.id, 'planned_date': today - relativedelta(days=1), 'effective_date': today - relativedelta(days=1), 'company': company.id, 'unit_price': Decimal('1'), 'currency': currency.id, }, { 'product': product.id, 'lot': lot2.id, 'uom': unit.id, 'quantity': 10, 'from_location': supplier.id, 'to_location': storage.id, 'planned_date': today - relativedelta(days=1), 'effective_date': today - relativedelta(days=1), 'company': company.id, 'unit_price': Decimal('1'), 'currency': currency.id, }, { 'product': product.id, 'lot': None, 'uom': unit.id, 'quantity': 3, 'from_location': supplier.id, 'to_location': storage.id, 'planned_date': today - relativedelta(days=1), 'effective_date': today - relativedelta(days=1), 'company': company.id, 'unit_price': Decimal('1'), 'currency': currency.id, }]) Move.do(moves) period, = Period.create([{ 'date': today - relativedelta(days=1), 'company': company.id, }]) Period.close([period]) self.assertEqual(period.state, 'closed') quantities = { supplier: -18, storage: 18, } for cache in period.caches: self.assertEqual(cache.product, product) self.assertEqual(cache.internal_quantity, quantities[cache.location]) quantities = { (supplier, lot1): -5, (storage, lot1): 5, (supplier, lot2): -10, (storage, lot2): 10, (supplier, None): -3, (storage, None): 3, } for lot_cache in period.lot_caches: self.assertEqual(lot_cache.product, product) self.assertEqual(lot_cache.internal_quantity, quantities[(lot_cache.location, lot_cache.lot)])