OLD | NEW |
(Empty) | |
| 1 =========================== |
| 2 Sale Shipment Cost Scenario |
| 3 =========================== |
| 4 |
| 5 ============= |
| 6 General Setup |
| 7 ============= |
| 8 |
| 9 Imports:: |
| 10 |
| 11 >>> import datetime |
| 12 >>> from dateutil.relativedelta import relativedelta |
| 13 >>> from decimal import Decimal |
| 14 >>> from proteus import config, Model, Wizard |
| 15 >>> today = datetime.date.today() |
| 16 |
| 17 Create database:: |
| 18 |
| 19 >>> config = config.set_trytond(':memory:') |
| 20 |
| 21 Install sale_shipment_cost, sale and account_invoice:: |
| 22 |
| 23 >>> Module = Model.get('ir.module.module') |
| 24 >>> modules = Module.find([ |
| 25 ... ('name', 'in', ('sale_shipment_cost', |
| 26 ... 'sale', 'account_invoice')), |
| 27 ... ]) |
| 28 >>> Module.button_install([x.id for x in modules], config.context) |
| 29 >>> Wizard('ir.module.module.install_upgrade').execute('start') |
| 30 |
| 31 Create company:: |
| 32 |
| 33 >>> Currency = Model.get('currency.currency') |
| 34 >>> CurrencyRate = Model.get('currency.currency.rate') |
| 35 >>> Company = Model.get('company.company') |
| 36 >>> company_config = Wizard('company.company.config') |
| 37 >>> company_config.execute('company') |
| 38 >>> company = company_config.form |
| 39 >>> company.name = 'B2CK' |
| 40 >>> currencies = Currency.find([('code', '=', 'EUR')]) |
| 41 >>> if not currencies: |
| 42 ... currency = Currency(name='Euro', symbol=u'€', code='EUR', |
| 43 ... rounding=Decimal('0.01'), mon_grouping='[3, 3, 0]', |
| 44 ... mon_decimal_point=',') |
| 45 ... currency.save() |
| 46 ... CurrencyRate(date=today + relativedelta(month=1, day=1), |
| 47 ... rate=Decimal('1.0'), currency=currency).save() |
| 48 ... else: |
| 49 ... currency, = currencies |
| 50 >>> company.currency = currency |
| 51 >>> company_config.execute('add') |
| 52 >>> company, = Company.find() |
| 53 |
| 54 Reload the context:: |
| 55 |
| 56 >>> User = Model.get('res.user') |
| 57 >>> config._context = User.get_preferences(True, config.context) |
| 58 |
| 59 Create fiscal year:: |
| 60 |
| 61 >>> FiscalYear = Model.get('account.fiscalyear') |
| 62 >>> Sequence = Model.get('ir.sequence') |
| 63 >>> SequenceStrict = Model.get('ir.sequence.strict') |
| 64 >>> fiscalyear = FiscalYear(name='%s' % today.year) |
| 65 >>> fiscalyear.start_date = today + relativedelta(month=1, day=1) |
| 66 >>> fiscalyear.end_date = today + relativedelta(month=12, day=31) |
| 67 >>> fiscalyear.company = company |
| 68 >>> post_move_sequence = Sequence(name='%s' % today.year, |
| 69 ... code='account.move', |
| 70 ... company=company) |
| 71 >>> post_move_sequence.save() |
| 72 >>> fiscalyear.post_move_sequence = post_move_sequence |
| 73 >>> invoice_sequence = SequenceStrict(name='%s' % today.year, |
| 74 ... code='account.invoice', |
| 75 ... company=company) |
| 76 >>> invoice_sequence.save() |
| 77 >>> fiscalyear.out_invoice_sequence = invoice_sequence |
| 78 >>> fiscalyear.in_invoice_sequence = invoice_sequence |
| 79 >>> fiscalyear.out_credit_note_sequence = invoice_sequence |
| 80 >>> fiscalyear.in_credit_note_sequence = invoice_sequence |
| 81 >>> fiscalyear.save() |
| 82 >>> FiscalYear.create_period([fiscalyear.id], config.context) |
| 83 True |
| 84 |
| 85 Create chart of accounts:: |
| 86 |
| 87 >>> AccountTemplate = Model.get('account.account.template') |
| 88 >>> Account = Model.get('account.account') |
| 89 >>> AccountJournal = Model.get('account.journal') |
| 90 >>> account_template, = AccountTemplate.find([('parent', '=', False)]) |
| 91 >>> create_chart_account = Wizard('account.account.create_chart_account') |
| 92 >>> create_chart_account.execute('account') |
| 93 >>> create_chart_account.form.account_template = account_template |
| 94 >>> create_chart_account.form.company = company |
| 95 >>> create_chart_account.execute('create_account') |
| 96 >>> receivable, = Account.find([ |
| 97 ... ('kind', '=', 'receivable'), |
| 98 ... ('company', '=', company.id), |
| 99 ... ]) |
| 100 >>> payable, = Account.find([ |
| 101 ... ('kind', '=', 'payable'), |
| 102 ... ('company', '=', company.id), |
| 103 ... ]) |
| 104 >>> revenue, = Account.find([ |
| 105 ... ('kind', '=', 'revenue'), |
| 106 ... ('company', '=', company.id), |
| 107 ... ]) |
| 108 >>> expense, = Account.find([ |
| 109 ... ('kind', '=', 'expense'), |
| 110 ... ('company', '=', company.id), |
| 111 ... ]) |
| 112 >>> create_chart_account.form.account_receivable = receivable |
| 113 >>> create_chart_account.form.account_payable = payable |
| 114 >>> create_chart_account.execute('create_properties') |
| 115 |
| 116 Create customer:: |
| 117 |
| 118 >>> Party = Model.get('party.party') |
| 119 >>> customer = Party(name='Customer') |
| 120 >>> customer.save() |
| 121 |
| 122 Create category:: |
| 123 |
| 124 >>> ProductCategory = Model.get('product.category') |
| 125 >>> category = ProductCategory(name='Category') |
| 126 >>> category.save() |
| 127 |
| 128 Create product:: |
| 129 |
| 130 >>> ProductUom = Model.get('product.uom') |
| 131 >>> Product = Model.get('product.product') |
| 132 >>> unit, = ProductUom.find([('name', '=', 'Unit')]) |
| 133 >>> product = Product() |
| 134 >>> product.name = 'Product' |
| 135 >>> product.category = category |
| 136 >>> product.default_uom = unit |
| 137 >>> product.type = 'stockable' |
| 138 >>> product.salable = True |
| 139 >>> product.list_price = Decimal('20') |
| 140 >>> product.cost_price = Decimal('8') |
| 141 >>> product.account_revenue = revenue |
| 142 >>> product.save() |
| 143 >>> carrier_product = Product() |
| 144 >>> carrier_product.name = 'Carrier Product' |
| 145 >>> carrier_product.category = category |
| 146 >>> carrier_product.default_uom = unit |
| 147 >>> carrier_product.type = 'service' |
| 148 >>> carrier_product.salable = True |
| 149 >>> carrier_product.list_price = Decimal('3') |
| 150 >>> carrier_product.account_revenue = revenue |
| 151 >>> carrier_product.save() |
| 152 |
| 153 Create carrier:: |
| 154 |
| 155 >>> Carrier = Model.get('carrier') |
| 156 >>> carrier = Carrier() |
| 157 >>> carrier.name = 'Carrier' |
| 158 >>> carrier.carrier_product = carrier_product |
| 159 >>> carrier.save() |
| 160 |
| 161 Create payment term:: |
| 162 |
| 163 >>> PaymentTerm = Model.get('account.invoice.payment_term') |
| 164 >>> PaymentTermLine = Model.get('account.invoice.payment_term.line') |
| 165 >>> payment_term = PaymentTerm(name='Direct') |
| 166 >>> payment_term_line = PaymentTermLine(type='remainder') |
| 167 >>> payment_term.lines.append(payment_term_line) |
| 168 >>> payment_term.save() |
| 169 |
| 170 Sale products with cost on shipment:: |
| 171 |
| 172 >>> Sale = Model.get('sale.sale') |
| 173 >>> SaleLine = Model.get('sale.line') |
| 174 >>> sale = Sale() |
| 175 >>> sale.party = customer |
| 176 >>> sale.carrier = carrier |
| 177 >>> sale.payment_term = payment_term |
| 178 >>> sale.invoice_method = 'shipment' |
| 179 >>> sale.shipment_cost_method = 'shipment' |
| 180 >>> sale_line = SaleLine() |
| 181 >>> sale.lines.append(sale_line) |
| 182 >>> sale_line.product = product |
| 183 >>> sale_line.quantity = 5.0 |
| 184 >>> cost_line = sale.lines[-1] |
| 185 >>> cost_line.product == carrier_product |
| 186 True |
| 187 >>> cost_line.quantity |
| 188 1.0 |
| 189 >>> cost_line.amount == Decimal('3') |
| 190 True |
| 191 >>> sale.save() |
| 192 >>> Sale.workflow_trigger_validate(sale.id, 'quotation', config.context) |
| 193 >>> Sale.workflow_trigger_validate(sale.id, 'confirm', config.context) |
| 194 >>> sale.state |
| 195 u'confirmed' |
| 196 >>> sale.untaxed_amount == Decimal('103') |
| 197 True |
| 198 |
| 199 Send products:: |
| 200 |
| 201 >>> ShipmentOut = Model.get('stock.shipment.out') |
| 202 >>> shipment, = sale.shipments |
| 203 >>> shipment.carrier == carrier |
| 204 True |
| 205 >>> shipment.cost == Decimal('3') |
| 206 True |
| 207 >>> shipment.cost_currency == currency |
| 208 True |
| 209 >>> move, = shipment.inventory_moves |
| 210 >>> move.quantity = 4 |
| 211 >>> shipment.cost == Decimal('3') |
| 212 True |
| 213 >>> shipment.cost_currency == currency |
| 214 True |
| 215 >>> shipment.state |
| 216 u'waiting' |
| 217 >>> shipment.save() |
| 218 >>> shipment.reload() |
| 219 >>> ShipmentOut.workflow_trigger_validate(shipment.id, 'force_assign', |
| 220 ... config.context) |
| 221 >>> shipment.state |
| 222 u'assigned' |
| 223 >>> shipment.reload() |
| 224 >>> ShipmentOut.workflow_trigger_validate(shipment.id, 'packed', |
| 225 ... config.context) |
| 226 >>> shipment.state |
| 227 u'packed' |
| 228 >>> shipment.reload() |
| 229 >>> ShipmentOut.workflow_trigger_validate(shipment.id, 'done', |
| 230 ... config.context) |
| 231 >>> shipment.state |
| 232 u'done' |
| 233 |
| 234 Check customer invoice:: |
| 235 |
| 236 >>> sale.reload() |
| 237 >>> invoice, = sale.invoices |
| 238 >>> invoice.untaxed_amount == Decimal('83') |
| 239 True |
| 240 |
| 241 Sale products with cost on order:: |
| 242 |
| 243 >>> sale = Sale() |
| 244 >>> sale.party = customer |
| 245 >>> sale.carrier = carrier |
| 246 >>> sale.payment_term = payment_term |
| 247 >>> sale.invoice_method = 'order' |
| 248 >>> sale.shipment_cost_method = 'order' |
| 249 >>> sale_line = SaleLine() |
| 250 >>> sale.lines.append(sale_line) |
| 251 >>> sale_line.product = product |
| 252 >>> sale_line.quantity = 3.0 |
| 253 >>> cost_line = sale.lines[-1] |
| 254 >>> cost_line.product == carrier_product |
| 255 True |
| 256 >>> cost_line.quantity |
| 257 1.0 |
| 258 >>> cost_line.amount == Decimal('3') |
| 259 True |
| 260 >>> sale.save() |
| 261 >>> Sale.workflow_trigger_validate(sale.id, 'quotation', config.context) |
| 262 >>> Sale.workflow_trigger_validate(sale.id, 'confirm', config.context) |
| 263 >>> sale.state |
| 264 u'confirmed' |
| 265 >>> sale.untaxed_amount == Decimal('63') |
| 266 True |
| 267 |
| 268 Check customer shipment:: |
| 269 |
| 270 >>> shipment, = sale.shipments |
| 271 >>> shipment.carrier == carrier |
| 272 True |
| 273 |
| 274 Check customer invoice:: |
| 275 |
| 276 >>> sale.reload() |
| 277 >>> invoice, = sale.invoices |
| 278 >>> invoice.untaxed_amount == Decimal('63') |
| 279 True |
OLD | NEW |